From: soufiane Date: Mon, 28 Jul 2025 13:17:57 +0000 (+0200) Subject: wip #7634 @1:00 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=9366e99cab4e06d02fd3957d03118325b19a0690;p=fluidbook-toolbox.git wip #7634 @1:00 --- diff --git a/resources/markdowneditor/js/markdowneditor.js b/resources/markdowneditor/js/markdowneditor.js index 9df2c9134..0cf870de9 100644 --- a/resources/markdowneditor/js/markdowneditor.js +++ b/resources/markdowneditor/js/markdowneditor.js @@ -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) { diff --git a/resources/markdowneditor/js/markdowneditor.toolbar.js b/resources/markdowneditor/js/markdowneditor.toolbar.js index c36ffb107..8c2eb1a06 100644 --- a/resources/markdowneditor/js/markdowneditor.toolbar.js +++ b/resources/markdowneditor/js/markdowneditor.toolbar.js @@ -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;