Add mirroring of "[", "]" and "="

This commit is contained in:
Peter Stuifzand 2020-06-09 22:56:56 +02:00
parent fd3c8d8e10
commit 09ba680f10

View File

@ -17,6 +17,10 @@ import '../node_modules/jquery-contextmenu/dist/jquery.contextMenu.css';
moment.locale('nl') moment.locale('nl')
function isMultiline(input) {
return input.value.startsWith("```", 0)
}
function addSaver(editor, saveUrl, page, beforeSave) { function addSaver(editor, saveUrl, page, beforeSave) {
return { return {
save() { save() {
@ -272,6 +276,24 @@ if (holder) {
return false 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 return true
}) })