From fac67579baf0f7ddea22ce69376d286bd28084cd Mon Sep 17 00:00:00 2001 From: salexdv Date: Wed, 2 Jun 2021 12:28:43 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BB=20onKeyDown=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D0=B1?= =?UTF-8?q?=D1=8B=D1=87=D0=BD=D0=BE=D0=B3=D0=BE=20=D1=80=D0=B5=D0=B6=D0=B8?= =?UTF-8?q?=D0=BC=D0=B0=20=D0=B8=20diff=20#165?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/editor.js | 183 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 109 insertions(+), 74 deletions(-) diff --git a/src/editor.js b/src/editor.js index 2473c71..7c94551 100644 --- a/src/editor.js +++ b/src/editor.js @@ -576,6 +576,8 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit }, 50); }; editor.markDiffLines(); + editor.getModifiedEditor().onKeyDown(e => diffEditorOnKeyDown(e)); + editor.getOriginalEditor().onKeyDown(e => diffEditorOnKeyDown(e)); } else { @@ -587,6 +589,7 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit automaticLayout: true }); originalText = ''; + editor.onKeyDown(e => editorOnKeyDown(e)); } editor.updateOptions({ readOnly: readOnlyMode }); } @@ -1354,6 +1357,8 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit }); } + + editor.onKeyDown(e => editorOnKeyDown(e)); // #endregion // #region editor events @@ -1369,78 +1374,6 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit }); - editor.onKeyDown(e => { - - editor.lastKeyCode = e.keyCode; - - if (e.keyCode == 16 && editor.getPosition().lineNumber == 1) - // ArrowUp - scrollToTop(); - else if (e.keyCode == 3 && generateSelectSuggestEvent) { - // Enter - let element = document.querySelector('.monaco-list-row.focused'); - if (element) { - genarateEventWithSuggestData('EVENT_ON_SELECT_SUGGEST_ROW', 'selection', element); - // Prevent propagation of KeyDown event to editor if SuggestList was closed in EVENT_ON_SELECT_SUGGEST_ROW event handler https://github.com/salexdv/bsl_console/issues/90 - element = document.querySelector('.monaco-list-row.focused'); - if (!element) { - e.preventDefault() - } - } - } - else if (e.ctrlKey && (e.keyCode == 36 || e.keyCode == 38)) { - // Ctrl+F or Ctrl+H - setFindWidgetDisplay('inherit'); - } - else if (e.keyCode == 9) { - // Esc - if (document.querySelector('.find-widget')) - setFindWidgetDisplay('none'); - hideSuggestionsList(); - } - else if (e.keyCode == 61) { - // F3 - if (!e.altKey && !e.shiftKey) { - if (e.ctrlKey) { - editor.trigger('', 'actions.find'); - previousMatch(); - } - else - editor.trigger('', 'editor.action.findWithSelection'); - setFindWidgetDisplay('inherit'); - editor.focus(); - document.querySelector('.find-widget .input').focus(); - } - } - else if (e.keyCode == 2) { - // Tab - if (generateSelectSuggestEvent) { - let element = document.querySelector('.monaco-list-row.focused'); - if (element) { - genarateEventWithSuggestData('EVENT_ON_SELECT_SUGGEST_ROW', 'selection', element); - } - } - } - - if (e.altKey && e.keyCode == 87) { - // fix https://github.com/salexdv/bsl_console/issues/147 - e.preventDefault(); - setText('['); - } - - if (e.ctrlKey) - ctrlPressed = true; - - if (e.altKey) - altPressed = true; - - if (e.shiftKey) - shiftPressed = true; - - checkEmptySuggestions(); - - }); - editor.onKeyUp(e => { if (e.ctrlKey) @@ -1515,6 +1448,108 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit // #endregion // #region non-public functions + function diffEditorOnKeyDown(e) { + + if (e.ctrlKey && (e.keyCode == 36 || e.keyCode == 38)) { + // Ctrl+F or Ctrl+H + setFindWidgetDisplay('inherit'); + } + else if (e.keyCode == 9) { + // Esc + if (document.querySelector('.find-widget')) + setFindWidgetDisplay('none'); + } + else if (e.keyCode == 61) { + // F3 + if (!e.altKey && !e.shiftKey) { + if (e.ctrlKey) { + editor.trigger('', 'actions.find'); + previousMatch(); + } + else + editor.trigger('', 'editor.action.findWithSelection'); + setFindWidgetDisplay('inherit'); + editor.focus(); + document.querySelectorAll('.find-widget .input').forEach(function (element) { + element.focus(); + }); + } + } + + } + + function editorOnKeyDown(e) { + + editor.lastKeyCode = e.keyCode; + + if (e.keyCode == 16 && editor.getPosition().lineNumber == 1) + // ArrowUp + scrollToTop(); + else if (e.keyCode == 3 && generateSelectSuggestEvent) { + // Enter + let element = document.querySelector('.monaco-list-row.focused'); + if (element) { + genarateEventWithSuggestData('EVENT_ON_SELECT_SUGGEST_ROW', 'selection', element); + // Prevent propagation of KeyDown event to editor if SuggestList was closed in EVENT_ON_SELECT_SUGGEST_ROW event handler https://github.com/salexdv/bsl_console/issues/90 + element = document.querySelector('.monaco-list-row.focused'); + if (!element) { + e.preventDefault() + } + } + } + else if (e.ctrlKey && (e.keyCode == 36 || e.keyCode == 38)) { + // Ctrl+F or Ctrl+H + setFindWidgetDisplay('inherit'); + } + else if (e.keyCode == 9) { + // Esc + if (document.querySelector('.find-widget')) + setFindWidgetDisplay('none'); + hideSuggestionsList(); + } + else if (e.keyCode == 61) { + // F3 + if (!e.altKey && !e.shiftKey) { + if (e.ctrlKey) { + editor.trigger('', 'actions.find'); + previousMatch(); + } + else + editor.trigger('', 'editor.action.findWithSelection'); + setFindWidgetDisplay('inherit'); + editor.focus(); + document.querySelector('.find-widget .input').focus(); + } + } + else if (e.keyCode == 2) { + // Tab + if (generateSelectSuggestEvent) { + let element = document.querySelector('.monaco-list-row.focused'); + if (element) { + genarateEventWithSuggestData('EVENT_ON_SELECT_SUGGEST_ROW', 'selection', element); + } + } + } + + if (e.altKey && e.keyCode == 87) { + // fix https://github.com/salexdv/bsl_console/issues/147 + e.preventDefault(); + setText('['); + } + + if (e.ctrlKey) + ctrlPressed = true; + + if (e.altKey) + altPressed = true; + + if (e.shiftKey) + shiftPressed = true; + + checkEmptySuggestions(); + + } + function initContextMenuActions() { contextActions.forEach(action => { @@ -1620,9 +1655,9 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit function setFindWidgetDisplay(value) { - let element = document.querySelector('.find-widget'); - if (element) + document.querySelectorAll('.find-widget').forEach(function (element) { element.style.display = value; + }); }