@cocreate/selection 1.2.20 → 1.2.21
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/index.js +10 -1
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## [1.2.21](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.20...v1.2.21) (2021-12-08)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* check parent for closest contenteditable, return range.element ([dbe5d32](https://github.com/CoCreate-app/CoCreate-selection/commit/dbe5d32fbfdb3912ddcbe005f24c315fc444f17b))
|
7
|
+
|
1
8
|
## [1.2.20](https://github.com/CoCreate-app/CoCreate-selection/compare/v1.2.19...v1.2.20) (2021-11-27)
|
2
9
|
|
3
10
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
@@ -33,6 +33,10 @@ export function getSelection(element) {
|
|
33
33
|
if(range.startContainer != range.endContainer) {
|
34
34
|
// toDo: replace common ancestor value
|
35
35
|
}
|
36
|
+
let contenteditable = range.startContainer.parentElement.closest('[contenteditable][collection][document_id][name]');
|
37
|
+
if (contenteditable){
|
38
|
+
element = contenteditable;
|
39
|
+
}
|
36
40
|
let domTextEditor = element;
|
37
41
|
if (!domTextEditor.htmlString){
|
38
42
|
domTextEditor = element.closest('[contenteditable]');
|
@@ -57,6 +61,7 @@ export function getSelection(element) {
|
|
57
61
|
endContainer = range.endContainer.parentElement;
|
58
62
|
|
59
63
|
let rangeObj = {
|
64
|
+
element: contenteditable,
|
60
65
|
startOffset: range.startOffset,
|
61
66
|
endOffset: range.endOffset,
|
62
67
|
startContainer,
|
@@ -418,7 +423,11 @@ function getElFromString(dom, string, element, position, isAttribute) {
|
|
418
423
|
}
|
419
424
|
|
420
425
|
function getPosition(string, subString, index) {
|
421
|
-
|
426
|
+
let angleArray = string.split(subString, index);
|
427
|
+
let startstring = angleArray.join(subString);
|
428
|
+
let start = startstring.length;
|
429
|
+
return start;
|
430
|
+
// return string.split(subString, index).join(subString).length;
|
422
431
|
}
|
423
432
|
|
424
433
|
export default {getSelection, setSelection, hasSelection, processSelection, getStringPosition, getElementPosition};
|