]> _ Git - fluidbook-toolbox.git/commitdiff
wip #7634 @1:00
authorsoufiane <soufiane@cubedesigners.com>
Mon, 28 Jul 2025 13:17:57 +0000 (15:17 +0200)
committersoufiane <soufiane@cubedesigners.com>
Mon, 28 Jul 2025 13:17:57 +0000 (15:17 +0200)
resources/markdowneditor/js/markdowneditor.js
resources/markdowneditor/js/markdowneditor.toolbar.js

index 9df2c913435b9beb13822fee772fd3ccb0c6ad37..0cf870de9ca15c2961f6cc90ec8b48a182cea75a 100644 (file)
@@ -5,7 +5,26 @@ import MarkdowneditorSave from "./markdowneditor.save";
 import MarkdowneditorVersions from "./markdowneditor.versions";
 import tippy from "tippy.js";
 import 'tippy.js/dist/tippy.css';
+
 window.$ = window.jQuery = require('jquery');
+window.key = require('keymaster-reloaded');
+
+window.key.filter = function (event) {
+    return keyfilter(event);
+};
+
+function keyfilter(event, disable = false) {
+    if (disable) {
+        return false
+    }
+    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;
+}
 
 $.ajaxSetup({
     headers: {
@@ -282,7 +301,17 @@ MarkdownEditor.prototype = {
             this.open = false
             $("#linkeditor-icon-versions").removeClass("active")
         }
-    }
+    },
+
+    isfocusOnFormItem: function () {
+        return $(document.activeElement).is('input[type="text"],input[type="email"],input[type="number"],input[type="tel"],input[type="search"],textarea,select');
+    },
+
+    focusPageField: function () {
+        let i = $("#markdowneditor-page-field input").get(0);
+        i.focus();
+        i.select();
+    },
 
     /*isSpecialPage: function (page) {
         if (page === undefined) {
index c36ffb107f7fdfadc0654dd1757b5aa20b71d598..8c2eb1a06176d5b1148b3ff02d7c6aa8d4723ec9 100644 (file)
@@ -17,6 +17,45 @@ MarkdowneditorToolbar.prototype = {
             $this.markdowneditor.runAction($(this).data('action'), $(this).is('[data-action-args]') ? $(this).data('action-args') : []);
             return false;
         });
-    }
+
+        $("[data-key]").each(function () {
+            let e = $(this);
+            key($(this).data('key'), function () {
+                if ($(e).is('[data-key-skipintextfields]') && $this.markdowneditor.isfocusOnFormItem()) {
+                    return true;
+                }
+                $(e).addClass('hover');
+                $this.markdowneditor.runAction($(e).data('action'));
+                setTimeout(function () {
+                    $(e).removeClass('hover')
+                }, 150);
+                return false;
+            });
+        });
+
+        this.key('enter', function () {
+            if ($(document.activeElement).is('input[type="number"]')) {
+                $this.markdowneditor.changePage($(document.activeElement).val());
+                return false;
+            }
+        });
+    },
+
+    key: function (shortcut, scope) {
+        var $this = this;
+        key(shortcut, function (event, handler) {
+            if ($this.allowsKeyboardShortcut(shortcut)) {
+                var res = scope(event, handler);
+                return res;
+            }
+        });
+    },
+
+    allowsKeyboardShortcut: function (shortcut) {
+        if (shortcut === 'pageup' || shortcut === 'pagedown' || shortcut === 'enter') {
+            return true;
+        }
+        return !this.markdowneditor.isfocusOnFormItem();
+    },
 };
 export default MarkdowneditorToolbar;