From e2859feffaa722fe4c3adb0d30ab5ab296ba8043 Mon Sep 17 00:00:00 2001 From: salexdv Date: Wed, 22 Jul 2020 18:01:16 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BE=D0=BF=D1=80?= =?UTF-8?q?=D0=B5=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=B5?= =?UTF-8?q?=D0=B9=D1=81=D1=82=D0=B2=D0=B8=D0=B9=20"=D0=9A=D0=BE=D0=BF?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D1=82=D1=8C/=D0=92=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D0=B2=D0=B8=D1=82=D1=8C",=20=D1=87=D1=82=D0=BE=D0=B1?= =?UTF-8?q?=D1=8B=20=D0=B2=201=D0=A1=20=D0=BD=D0=BE=D1=80=D0=BC=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D0=BE=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=20=D1=81=D0=BE=D1=87=D0=B5=D1=82=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BA=D0=BB=D0=B0=D0=B2=D0=B8=D1=88=20CTRL+C=20=D0=B8?= =?UTF-8?q?=20CTRL+V=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8=20=D0=B2?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=B2=D0=BA=D0=B8=20=D1=82=D0=B5=D0=BA=D1=81?= =?UTF-8?q?=D1=82=D0=B0,=20=D1=87=D1=82=D0=BE=D0=B1=D1=8B=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=B0=D0=BB=20=D0=BE=D1=82=D0=BA=D0=B0=D1=82?= =?UTF-8?q?=20=D0=B4=D0=B5=D0=B9=D1=81=D1=82=D0=B2=D0=B8=D1=8F=20CTRL+Z?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/actions.js | 24 ++++++++++++++++++++++++ src/editor.js | 35 +++++++++++++++++++++++++++++------ 2 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 src/actions.js diff --git a/src/actions.js b/src/actions.js new file mode 100644 index 0000000..6650955 --- /dev/null +++ b/src/actions.js @@ -0,0 +1,24 @@ +define(['vs/editor/editor.main'], function () { + + actions = { + copy_bsl: { + label: 'Копировать', + key: monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_C, + cmd: monaco.KeyMod.chord(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_C), + callback: function (ed) { + selectionText = editor.getModel().getValueInRange(editor.getSelection()); + return null; + } + }, + paste_bsl: { + label: 'Вставить', + key: monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_V, + cmd: monaco.KeyMod.chord(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_V), + callback: function (ed) { + setText(selectionText, null); + return null; + } + } + } + +}); \ No newline at end of file diff --git a/src/editor.js b/src/editor.js index 35b36cc..3e0d09e 100644 --- a/src/editor.js +++ b/src/editor.js @@ -1,11 +1,16 @@ -define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/editor.main'], function () { +define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/editor.main', 'actions'], function () { + + selectionText = ''; setText = function(txt, range) { - editor.getModel().applyEdits([{ - range: range ? range : monaco.Range.fromPositions(editor.getPosition()), - text: txt - }]); + let insertRange = range ? range : monaco.Range.fromPositions(editor.getPosition()); + let operation = { + range: insertRange, + text: txt, + forceMoveMarkers: true + }; + editor.executeEdits(txt, [operation]); } @@ -95,7 +100,25 @@ define(['bslGlobals', 'bslMetadata', 'snippets', 'bsl_language', 'vs/editor/edit editor = monaco.editor.create(document.getElementById("container"), { theme: "bsl-white", value: getCode(), - language: language.id + language: language.id, + contextmenu: false }); + + for (const [action_id, action] of Object.entries(actions)) { + editor.addAction({ + id: action_id, + label: action.label, + keybindings: [action.key, action.cmd], + precondition: null, + keybindingContext: null, + contextMenuGroupId: 'navigation', + contextMenuOrder: 1.5, + run: action.callback + }); + } + + // Replace keybinding for action "Change All Occurrences" + //editor._standaloneKeybindingService.addDynamicKeybinding('-editor.action.changeAll') + //editor._standaloneKeybindingService.addDynamicKeybinding('editor.action.changeAll', monaco.KeyMod.CtrlCmd | monaco.KeyCode.F5) // Ctrl+F5 }); \ No newline at end of file