|
13 | 13 | <button class="button" @click="makeStrikethrough">
|
14 | 14 | <span class="icon-strike"></span>
|
15 | 15 | </button>
|
16 |
| - <button class="button" @click="makeMonospace"> |
| 16 | + <button class="button" @click="makeH1"> |
17 | 17 | <span class="icon-h1"></span>
|
18 | 18 | </button>
|
19 | 19 | <button class="button" @click="insertLink">
|
@@ -53,6 +53,7 @@ import {
|
53 | 53 | ActionButton,
|
54 | 54 | } from '@nextcloud/vue'
|
55 | 55 | import EmojiPicker from '@nextcloud/vue/dist/Components/EmojiPicker'
|
| 56 | +import * as CodeMirror from "codemirror"; |
56 | 57 |
|
57 | 58 | export default {
|
58 | 59 | name: 'EditorEasyMDE',
|
@@ -128,13 +129,15 @@ export default {
|
128 | 129 | this.mde.codemirror.addKeyMap({
|
129 | 130 | Home: 'goLineLeft',
|
130 | 131 | End: 'goLineRight',
|
| 132 | + Enter: this.onEnter, |
131 | 133 | })
|
132 | 134 |
|
133 | 135 | // pass event for changes
|
134 | 136 | this.mde.codemirror.on('change', () => {
|
135 | 137 | this.$emit('input', this.mde.value())
|
136 | 138 | })
|
137 | 139 |
|
| 140 | +
|
138 | 141 | // listen for click/touch events in order to toggle checkboxes
|
139 | 142 | document.querySelectorAll('.CodeMirror-code').forEach((codeElement) => {
|
140 | 143 | codeElement.addEventListener('mousedown', this.onClickCodeElement)
|
@@ -282,6 +285,11 @@ export default {
|
282 | 285 | this.insertTextInfront('- [ ] ')
|
283 | 286 | },
|
284 | 287 |
|
| 288 | +
|
| 289 | + makeH1() { |
| 290 | + this.insertTextInfront('# ') |
| 291 | + }, |
| 292 | +
|
285 | 293 | makeBold() {
|
286 | 294 | this.surroundText('**')
|
287 | 295 | },
|
@@ -312,6 +320,32 @@ export default {
|
312 | 320 |
|
313 | 321 | reverseString(string) {
|
314 | 322 | return string.split('').reverse().join('')
|
| 323 | + }, |
| 324 | +
|
| 325 | + onEnter() { |
| 326 | + const cursor = this.mde.codemirror.getCursor(); |
| 327 | + const text = this.mde.codemirror.getValue().split('\n')[cursor.line].trim() |
| 328 | +
|
| 329 | + if(text.startsWith("- [ ]") && text !== "- [ ]") { |
| 330 | + this.insertText("\n") |
| 331 | + this.insertText("- [ ] ") |
| 332 | + this.mde.codemirror.setCursor(this.mde.codemirror.getCursor()) |
| 333 | + return; |
| 334 | + } |
| 335 | + if(text.startsWith("- [x]")) { |
| 336 | + this.insertText("\n") |
| 337 | + this.insertText("- [ ] ") |
| 338 | + this.mde.codemirror.setCursor(this.mde.codemirror.getCursor()) |
| 339 | + return; |
| 340 | + } |
| 341 | + if(text.startsWith("-") && text !== "-" && !text.startsWith("- [")) { |
| 342 | + this.insertText("\n") |
| 343 | + this.insertText(" - ") |
| 344 | + this.mde.codemirror.setCursor(this.mde.codemirror.getCursor()) |
| 345 | + return; |
| 346 | + } |
| 347 | +
|
| 348 | + return CodeMirror.Pass |
315 | 349 | }
|
316 | 350 | },
|
317 | 351 | }
|
|
0 commit comments