diff --git a/src/components/EditorEasyMDE.vue b/src/components/EditorEasyMDE.vue index ec29c7176..1db1d7213 100644 --- a/src/components/EditorEasyMDE.vue +++ b/src/components/EditorEasyMDE.vue @@ -13,7 +13,7 @@ - + @@ -53,6 +53,7 @@ import { ActionButton, } from '@nextcloud/vue' import EmojiPicker from '@nextcloud/vue/dist/Components/EmojiPicker' +import * as CodeMirror from "codemirror"; export default { name: 'EditorEasyMDE', @@ -128,6 +129,7 @@ export default { this.mde.codemirror.addKeyMap({ Home: 'goLineLeft', End: 'goLineRight', + Enter: this.onEnter, }) // pass event for changes @@ -135,6 +137,7 @@ export default { this.$emit('input', this.mde.value()) }) + // listen for click/touch events in order to toggle checkboxes document.querySelectorAll('.CodeMirror-code').forEach((codeElement) => { codeElement.addEventListener('mousedown', this.onClickCodeElement) @@ -282,6 +285,11 @@ export default { this.insertTextInfront('- [ ] ') }, + + makeH1() { + this.insertTextInfront('# ') + }, + makeBold() { this.surroundText('**') }, @@ -312,6 +320,32 @@ export default { reverseString(string) { return string.split('').reverse().join('') + }, + + onEnter() { + const cursor = this.mde.codemirror.getCursor(); + const text = this.mde.codemirror.getValue().split('\n')[cursor.line].trim() + + if(text.startsWith("- [ ]") && text !== "- [ ]") { + this.insertText("\n") + this.insertText("- [ ] ") + this.mde.codemirror.setCursor(this.mde.codemirror.getCursor()) + return; + } + if(text.startsWith("- [x]")) { + this.insertText("\n") + this.insertText("- [ ] ") + this.mde.codemirror.setCursor(this.mde.codemirror.getCursor()) + return; + } + if(text.startsWith("-") && text !== "-" && !text.startsWith("- [")) { + this.insertText("\n") + this.insertText(" - ") + this.mde.codemirror.setCursor(this.mde.codemirror.getCursor()) + return; + } + + return CodeMirror.Pass } }, }