@livingdocs/editable.js 3.1.1 → 3.1.2

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@livingdocs/editable.js",
3
3
  "description": "Friendly contenteditable API",
4
- "version": "3.1.1",
4
+ "version": "3.1.2",
5
5
  "dependencies": {
6
6
  "@babel/runtime": "^7.16.7",
7
7
  "bowser": "2.11.0",
@@ -83,11 +83,11 @@
83
83
  "isCi": true,
84
84
  "name": "Drone",
85
85
  "service": "drone",
86
- "commit": "9957094d8242121b94e2584b57ba04cd1c7067ed",
87
- "build": "495",
86
+ "commit": "fd0647cdc6be93eb00f3c1f749b70fc7e6a42a4d",
87
+ "build": "505",
88
88
  "branch": "master",
89
89
  "isPr": false,
90
90
  "slug": "livingdocsIO/editable.js",
91
- "date": "2022-05-17T13:22:55.296Z"
91
+ "date": "2022-06-14T12:48:39.898Z"
92
92
  }
93
93
  }
package/src/dispatcher.js CHANGED
@@ -136,12 +136,11 @@ export default class Dispatcher {
136
136
  const {blocks, cursor} = clipboard.paste(block, selection, clipboardContent)
137
137
  if (blocks.length) {
138
138
  if (endsWithSingleSpace(evt.target.innerText)) {
139
- block.innerHTML = replaceLast(block.innerHTML, ' ', ' ')
140
- this.notify('paste', block, blocks, this.editable.createCursorAtEnd(block))
141
- } else {
142
- this.notify('paste', block, blocks, cursor)
139
+ cursor.retainVisibleSelection(() => {
140
+ block.innerHTML = replaceLast(block.innerHTML, ' ', ' ')
141
+ })
143
142
  }
144
-
143
+ this.notify('paste', block, blocks, cursor)
145
144
  // The input event does not fire when we process the content manually
146
145
  // and insert it via script
147
146
  this.notify('change', block)
@@ -67,6 +67,7 @@ export function replaceLast (text, searchValue, replaceValue) {
67
67
  text = `${text}`
68
68
  if (!searchValue || replaceValue == null) return text
69
69
  const lastOccurrenceIndex = text.lastIndexOf(searchValue)
70
+ if (lastOccurrenceIndex === -1) return text
70
71
  return `${
71
72
  text.slice(0, lastOccurrenceIndex)
72
73
  }${