cm-md-editor 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.html CHANGED
@@ -12,8 +12,6 @@
12
12
  height: calc(100vh - 4rem);
13
13
  padding: 0.7rem;
14
14
  font-family: monospace;
15
- white-space: pre-wrap;
16
- overflow-wrap: break-word;
17
15
  tab-size: 4;
18
16
  line-height: 1.3;
19
17
  }
@@ -39,8 +37,7 @@ This is a minimal **markdown editor** which is used in chessmail.de.
39
37
  - easy to use
40
38
  - fast
41
39
 
42
- ☝️ [Check out the Demo page](https://shaack.com/projekte/cm-md-editor/)
43
- </textarea>
40
+ ☝️ [Check out the Demo page](https://shaack.com/projekte/cm-md-editor/)</textarea>
44
41
  </div>
45
42
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"
46
43
  integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-md-editor",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "a simple markdown editor",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/MdEditor.js CHANGED
@@ -6,12 +6,11 @@ export class MdEditor {
6
6
 
7
7
  constructor(element) {
8
8
  this.element = element
9
-
10
- // listen to typing
11
9
  this.element.addEventListener('keydown', (e) => this.handleKeyDown(e))
12
10
  }
13
11
 
14
12
  insertTextAtCursor(text) {
13
+ // execCommand is deprecated, but without alternative to insert text and preserve the correct undo/redo stack
15
14
  document.execCommand("insertText", false, text)
16
15
  }
17
16
 
@@ -64,16 +63,13 @@ export class MdEditor {
64
63
  const before = this.element.value.substring(0, start)
65
64
  const currentLine = before.substring(before.lastIndexOf('\n') + 1)
66
65
  const matchEmpty = currentLine.match(/^(\s*- )$/)
67
- const match = currentLine.match(/^(\s*- )/)
68
- if(matchEmpty) {
69
- e.preventDefault()
66
+ const matchHyphen = currentLine.match(/^(\s*- )/)
67
+ if (matchEmpty) {
70
68
  const pre = matchEmpty[1]
71
- this.element.selectionStart = before.lastIndexOf('\n') + 1
72
- this.element.selectionEnd = this.element.selectionStart + pre.length
73
- this.insertTextAtCursor('')
74
- } else if (match) {
69
+ this.element.selectionStart = this.element.selectionEnd - pre.length - 1
70
+ } else if (matchHyphen) {
75
71
  e.preventDefault()
76
- const pre = match[1]
72
+ const pre = matchHyphen[1]
77
73
  this.insertTextAtCursor('\n' + pre)
78
74
  }
79
75
  }