@cocreate/selection 1.13.0 → 1.13.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.
- package/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/index.js +12 -2
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## [1.13.1](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.13.0...v1.13.1) (2024-06-23)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* handling empty contenteditable positioning and ensure parsing and positioning only incudes the contentedible elements content ([924bc45](https://github.com/CoCreate-app/CoCreate-selection/commit/924bc45e13d47d2a750ec2715a5b0ead9276f0ac))
|
7
|
+
|
1
8
|
# [1.13.0](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.12.2...v1.13.0) (2024-06-12)
|
2
9
|
|
3
10
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
@@ -19,7 +19,12 @@ export function getSelection(element) {
|
|
19
19
|
|
20
20
|
let range = selection.getRangeAt(0);
|
21
21
|
|
22
|
-
let contenteditable
|
22
|
+
let contenteditable
|
23
|
+
if (range.startContainer.nodeType === 3)
|
24
|
+
contenteditable = range.startContainer.parentElement.closest('[contenteditable][array][object][key]');
|
25
|
+
else
|
26
|
+
contenteditable = range.startContainer.closest('[contenteditable][array][object][key]');
|
27
|
+
|
23
28
|
if (contenteditable) {
|
24
29
|
element = contenteditable;
|
25
30
|
} else return
|
@@ -48,7 +53,10 @@ export function getSelection(element) {
|
|
48
53
|
let textStart = 0, node = range.startContainer
|
49
54
|
while (node) {
|
50
55
|
textStart += node.textContent.length;
|
51
|
-
node
|
56
|
+
if (node === contenteditable)
|
57
|
+
node = undefined
|
58
|
+
else
|
59
|
+
node = node.previousSibling;
|
52
60
|
}
|
53
61
|
let textEnd = textStart + (range.endOffset - range.startOffset)
|
54
62
|
|
@@ -75,6 +83,8 @@ export function getSelection(element) {
|
|
75
83
|
|
76
84
|
function getNodePosition(container, domTextEditor, position) {
|
77
85
|
let string = domTextEditor.htmlString
|
86
|
+
if (!string)
|
87
|
+
return 0
|
78
88
|
let node = container.previousSibling
|
79
89
|
while (node && node.nodeType === 3) {
|
80
90
|
position += node.textContent.length;
|