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