]> _ Git - fluidbook-toolbox.git/commitdiff
wait #5619 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 30 Nov 2022 13:31:26 +0000 (14:31 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 30 Nov 2022 13:31:26 +0000 (14:31 +0100)
resources/linkeditor/js/linkeditor.form.js
resources/linkeditor/js/linkeditor.js
resources/linkeditor/js/linkeditor.links.js

index c37bd8eee9de10a9e162c68d026e563361b543d0..6672fcbcfbf17f0227b9b42c7a1eeb36d807d6f6 100644 (file)
@@ -55,6 +55,15 @@ LinkeditorForm.prototype = {
         this.unmaskChangeEvent();
     },
 
+    focusAndSelectDestinationField: function () {
+        var f = $('#linkeditor-panel-form [name="to"]').get(0);
+        f.focus();
+        f.select();
+        setTimeout(function () {
+            f.select();
+        }, 1);
+    },
+
     emptyForm: function () {
         $('#linkeditor-panel-form .select2_from_array').each(function () {
             $(this).select2('close');
@@ -81,7 +90,6 @@ LinkeditorForm.prototype = {
         this.updateFormData(form);
         container.append(form);
 
-
         this.initSelect2();
     },
 
index ef6918d0c7ed661e36e9de64018c0b90c4cf8a7c..229b8f78e02153ef79d4b141e5ab798b54e4f099 100644 (file)
@@ -18,10 +18,19 @@ import LinkeditorPanels from './linkeditor.panels';
 import LinkeditorForm from './linkeditor.form';
 
 window.$ = window.jQuery = require('jquery');
-window.key = require('keymaster');
+window.key = require('keymaster-reloaded');
 window.tippy = tippy;
 window.Noty = Noty;
 
+window.key.filter = function (event) {
+    let tagName = (event.target || event.srcElement).tagName;
+    //let field=tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA';
+    if (tagName === 'TEXTAREA' && event.keyCode === 13) {
+        return false;
+    }
+    return true;
+};
+
 require('jquery.scrollto');
 require('jquery-contextmenu');
 
index f5f41992e642b1f3007f0f8a5e30fd06e86344c5..6bdcb47804b04925c0d42f0e13728cddea9b7650 100644 (file)
@@ -1,7 +1,6 @@
 var LinkeditorLinks = function (linkeditor) {
     this.linkeditor = linkeditor;
 
-    this.currentSelection = [];
     this.dragLinkPos = null;
     this.resizeLinkPos = null;
 
@@ -69,15 +68,71 @@ LinkeditorLinks.prototype = {
         key('ctrl+down', function () {
             $this.offsetSelectedLinks('top', 10);
         });
+        key('pageup', function () {
+            $this.selectPreviousLink();
+        });
+        key('pagedown', function () {
+            $this.selectNextLink();
+        });
+        key('enter', function () {
+            if ($(document.activeElement).is('input[name="to"]')) {
+                $this.selectNextLink();
+                return false;
+            }
+        });
 
         setInterval(function () {
             $this.checkLastSelectedLink();
         }, 250);
     },
 
+    selectLinkAndSelectToField(link) {
+        if ($(link).length === 0) {
+            return;
+        }
+        this.deselectAllLinks();
+        this.selectLink($(link));
+        this.linkeditor.form.focusAndSelectDestinationField();
+    },
+
+    selectFirstLink: function () {
+        this.selectLinkAndSelectToField($('#linkeditor-links .link:eq(0)'));
+    },
+
+    selectLastLink: function () {
+        this.selectLinkAndSelectToField($('#linkeditor-links .link:last'));
+    },
+
+    selectPreviousLink: function () {
+        if (this.getCurrentSelection().length === 0) {
+            return this.selectLastLink();
+        }
+        return this.selectLinkAndSelectToField(this._getLinkByIndexOffset(-1));
+    },
+
+    selectNextLink: function () {
+        if (this.getCurrentSelection().length === 0) {
+            return this.selectFirstLink();
+        }
+        return this.selectLinkAndSelectToField(this._getLinkByIndexOffset(1));
+    },
+
+    _getLinkByIndexOffset(way) {
+        let allLinks = this.getCurrentLinksOnPage();
+        let index = this.getFirstLinkInSelection().index();
+        let nb = allLinks.length;
+        let n = (nb + index + way) % nb;
+        return allLinks.eq(n);
+    },
+
     mouseUp: function () {
         this.stopDragLink();
         this.stopResizeLink();
+        this.cleanPendingCreateLink();
+    },
+
+    cleanPendingCreateLink() {
+        $('.pendingCreate').remove();
     },
 
     createLinkDrag: function () {
@@ -290,7 +345,7 @@ LinkeditorLinks.prototype = {
             $(l).append('<div class="corners"><div class="nw"></div><div class="n"></div><div class="ne"></div><div class="e"></div><div class="se"></div><div class="s"></div><div class="sw"></div><div class="w"></div></div>')
         }
         $(l).addClass('selected');
-        this.currentSelection.push(l);
+
         this.linkeditor.form.updateLinkForm();
         this.lastSelectedLink = l;
     },
@@ -316,9 +371,9 @@ LinkeditorLinks.prototype = {
     },
 
     deselectAllLinks: function () {
-        this.currentSelection = [];
-        $(".link.selected").removeClass('selected');
+        this.linkeditor.form.saveFormDataInLink();
         this.linkeditor.form.updateLinkForm();
+        $(".link.selected").removeClass('selected');
     },
 
     offsetSelectedLinks: function (dim, value) {
@@ -369,7 +424,6 @@ LinkeditorLinks.prototype = {
     },
 
     addLink: function (link) {
-        let $this = this;
         let change = false;
         if (link.uid === undefined) {
             link.uid = this.linkeditor.utils.generateUID();
@@ -434,6 +488,18 @@ LinkeditorLinks.prototype = {
         this.linkeditor.hasChanged();
     },
 
+    getCurrentSelection: function () {
+        return $('.link.selected:not(.pendingCreate)');
+    },
+
+    getFirstLinkInSelection: function () {
+        return this.getCurrentSelection().eq(0);
+    },
+
+    getCurrentLinksOnPage() {
+        return $('.link:not(.pendingCreate)');
+    },
+
     deleteLink: function (link, triggerChange) {
         if (triggerChange === undefined) {
             triggerChange = true;