cm-md-editor 2.2.0 → 2.2.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/MdEditor.js +2 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-md-editor",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "a simple markdown editor",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/MdEditor.js CHANGED
@@ -341,7 +341,7 @@ export class MdEditor {
341
341
  getCurrentLineInfo() {
342
342
  const start = this.element.selectionStart
343
343
  const text = this.element.value
344
- const lineStart = text.lastIndexOf('\n', start - 1) + 1
344
+ const lineStart = start === 0 ? 0 : text.lastIndexOf('\n', start - 1) + 1
345
345
  let lineEnd = text.indexOf('\n', start)
346
346
  if (lineEnd === -1) lineEnd = text.length
347
347
  const line = text.substring(lineStart, lineEnd)
@@ -354,6 +354,7 @@ export class MdEditor {
354
354
  }
355
355
 
356
356
  toggleHeading(level) {
357
+ this.element.focus()
357
358
  const {lineStart, lineEnd, line} = this.getCurrentLineInfo()
358
359
  const prefix = '#'.repeat(level) + ' '
359
360
  const headingMatch = line.match(/^(#{1,6}) /)