(core) Handling shift+enter on ace editor

Summary:
Shift+Enter doesn't work on ace editor when suggestions
are shown. Propobly this is bug in the ace-editor.

Test Plan:
Manual:
Start ace editor, and trigger auto-completion menu.
Pressing shift+enter should add new line (with proper indention). Previously
it did nothing.

Reviewers: georgegevoian

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D3625
This commit is contained in:
Jarosław Sadziński 2022-10-06 12:37:50 +02:00
parent ce0c912a18
commit dd22ebdaf0

View File

@ -20,6 +20,13 @@ export function setupAceEditorCompletions(editor: Ace.Editor, options: ICompleti
const {Autocomplete} = ace.require('ace/autocomplete'); const {Autocomplete} = ace.require('ace/autocomplete');
const completer = new Autocomplete(); const completer = new Autocomplete();
// Here is the source code:
// https://github.com/ajaxorg/ace/blob/23208f2f19020d1f69b90bc3b02460bda8422072/src/autocomplete.js#L180
// It seems that this function wasn't doing anything special, and wasn't returning anything, so
// AceEditor refused to insert new line. Option 'deleteSuffix is also not supported (line 150).
if (completer.keyboardHandler?.commands?.["Shift-Return"]) {
completer.keyboardHandler.commands["Shift-Return"].exec = () => false;
}
completer.autoSelect = false; completer.autoSelect = false;
(editor as any).completer = completer; (editor as any).completer = completer;