@livingdocs/editable.js 3.0.15 → 3.0.16
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/dist/editable.js +1 -1
- package/dist/editable.js.map +1 -1
- package/package.json +4 -4
- package/src/dispatcher.js +7 -1
- package/src/util/string.js +18 -0
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.0.
|
|
4
|
+
"version": "3.0.16",
|
|
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": "
|
|
87
|
-
"build": "
|
|
86
|
+
"commit": "85752c5c2a4de6108413bc50b0433086ce0d0435",
|
|
87
|
+
"build": "469",
|
|
88
88
|
"branch": "master",
|
|
89
89
|
"isPr": false,
|
|
90
90
|
"slug": "livingdocsIO/editable.js",
|
|
91
|
-
"date": "2022-
|
|
91
|
+
"date": "2022-03-15T10:07:49.382Z"
|
|
92
92
|
}
|
|
93
93
|
}
|
package/src/dispatcher.js
CHANGED
|
@@ -5,6 +5,7 @@ import SelectionWatcher from './selection-watcher'
|
|
|
5
5
|
import config from './config'
|
|
6
6
|
import Keyboard from './keyboard'
|
|
7
7
|
import {closest} from './util/dom'
|
|
8
|
+
import {replaceLast, endsWithSingleSpace} from './util/string'
|
|
8
9
|
|
|
9
10
|
// This will be set to true once we detect the input event is working.
|
|
10
11
|
// Input event description on MDN:
|
|
@@ -134,7 +135,12 @@ export default class Dispatcher {
|
|
|
134
135
|
|
|
135
136
|
const {blocks, cursor} = clipboard.paste(block, selection, clipboardContent)
|
|
136
137
|
if (blocks.length) {
|
|
137
|
-
|
|
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)
|
|
143
|
+
}
|
|
138
144
|
|
|
139
145
|
// The input event does not fire when we process the content manually
|
|
140
146
|
// and insert it via script
|
package/src/util/string.js
CHANGED
|
@@ -61,3 +61,21 @@ export function browserEscapeHtml (str) {
|
|
|
61
61
|
div.appendChild(document.createTextNode(str))
|
|
62
62
|
return div.innerHTML
|
|
63
63
|
}
|
|
64
|
+
|
|
65
|
+
export function replaceLast (text, searchValue, replaceValue) {
|
|
66
|
+
if (!text) return ''
|
|
67
|
+
text = `${text}`
|
|
68
|
+
if (!searchValue || replaceValue == null) return text
|
|
69
|
+
const lastOccurrenceIndex = text.lastIndexOf(searchValue)
|
|
70
|
+
return `${
|
|
71
|
+
text.slice(0, lastOccurrenceIndex)
|
|
72
|
+
}${
|
|
73
|
+
replaceValue
|
|
74
|
+
}${
|
|
75
|
+
text.slice(lastOccurrenceIndex + searchValue.length)
|
|
76
|
+
}`
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function endsWithSingleSpace (text) {
|
|
80
|
+
return /\S+\s{1}$/.test(text)
|
|
81
|
+
}
|