1
0
mirror of https://github.com/salexdv/bsl_console.git synced 2024-11-28 08:48:48 +02:00

Переопределение действий "Копировать/Вставить", чтобы в 1С нормально работали сочетания клавиш CTRL+C и CTRL+V

Изменение функции вставки текста, чтобы работал откат действия CTRL+Z
This commit is contained in:
salexdv 2020-07-22 18:01:16 +03:00
parent ce88c9d2fb
commit e2859feffa
2 changed files with 53 additions and 6 deletions

24
src/actions.js Normal file
View File

@ -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;
}
}
}
});

View File

@ -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) { setText = function(txt, range) {
editor.getModel().applyEdits([{ let insertRange = range ? range : monaco.Range.fromPositions(editor.getPosition());
range: range ? range : monaco.Range.fromPositions(editor.getPosition()), let operation = {
text: txt 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"), { editor = monaco.editor.create(document.getElementById("container"), {
theme: "bsl-white", theme: "bsl-white",
value: getCode(), 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
}); });