@cocreate/selection 1.2.20 → 1.2.21

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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/selection",
3
- "version": "1.2.20",
3
+ "version": "1.2.21",
4
4
  "description": "A simple selection component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "selection",
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
- return string.split(subString, index).join(subString).length;
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};