From 09ba680f1024f108a6ca5eee7067657326ca409b Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Tue, 9 Jun 2020 22:56:56 +0200 Subject: [PATCH] Add mirroring of "[", "]" and "=" --- editor/src/index.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/editor/src/index.js b/editor/src/index.js index b66d1ec..9fe9bd0 100644 --- a/editor/src/index.js +++ b/editor/src/index.js @@ -17,6 +17,10 @@ import '../node_modules/jquery-contextmenu/dist/jquery.contextMenu.css'; moment.locale('nl') +function isMultiline(input) { + return input.value.startsWith("```", 0) +} + function addSaver(editor, saveUrl, page, beforeSave) { return { save() { @@ -272,6 +276,24 @@ if (holder) { return false } + let mirror = { + '[': ']', + '=': '=', + } + + if (!isMultiline(input) && mirror.hasOwnProperty(event.key)) { + let input = this + let val = input.value + let prefix = val.substring(0, input.selectionStart) + let selection = val.substring(input.selectionStart, input.selectionEnd) + let suffix = val.substring(input.selectionEnd) + input.value = prefix + event.key + selection + mirror[event.key] + suffix + input.selectionStart = prefix.length + event.key.length + input.selectionEnd = input.selectionStart + selection.length + $(input).trigger('input') + return false; + } + return true })