leksy-editor 2.2.1 → 2.2.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/utilities.js +46 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leksy-editor",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "Leksy Editor is an alternative to traditional WYSIWYG editors, designed primarily for creating mail templates, blogs, and documents without any content manipulation.",
5
5
  "main": "index.js",
6
6
  "directories": {
package/utilities.js CHANGED
@@ -3943,32 +3943,68 @@ const handleBackspaceInList = (event, core) => {
3943
3943
  const nestedList = li.querySelector('ul, ol');
3944
3944
  if (!nestedList) return;
3945
3945
 
3946
+
3947
+ if (!isCaretAtStart(range, li)) return;
3948
+
3949
+ event.preventDefault();
3950
+
3951
+ const parentList = li.parentElement;
3952
+ const prevLi = li.previousElementSibling;
3953
+
3946
3954
  const clone = li.cloneNode(true);
3947
3955
  const nestedInClone = clone.querySelector('ul, ol');
3948
3956
  if (nestedInClone) nestedInClone.remove();
3949
- const textContent = clone.textContent.replace(/\u200B/g, '').trim();
3950
-
3951
- if (textContent.length > 0 && !isCaretAtStart(range, li)) return;
3952
3957
 
3953
- event.preventDefault();
3958
+ const parentText = clone.textContent.replace(/\u200B/g, '').trim();
3954
3959
 
3955
- const parentList = li.parentElement;
3956
3960
  const fragment = document.createDocumentFragment();
3957
3961
  const children = Array.from(nestedList.children);
3958
3962
 
3959
3963
  children.forEach(child => fragment.appendChild(child));
3960
3964
 
3961
- if (children.length > 0) {
3962
- parentList.insertBefore(fragment, li);
3963
- const firstChild = children[0];
3965
+ // Case 1: previous list item exists
3966
+ if (prevLi) {
3967
+
3968
+ if (parentText.length > 0) {
3969
+ prevLi.appendChild(document.createTextNode(parentText));
3970
+ }
3971
+
3972
+ if (children.length > 0) {
3973
+ parentList.insertBefore(fragment, li);
3974
+ }
3975
+
3976
+ li.remove();
3977
+
3978
+ const newRange = document.createRange();
3979
+ newRange.selectNodeContents(prevLi);
3980
+ newRange.collapse(false);
3981
+
3982
+ selection.removeAllRanges();
3983
+ selection.addRange(newRange);
3984
+
3985
+ }
3986
+ else {newRange.collapse(false);
3987
+
3988
+ // Case 2: first list item
3989
+ const p = document.createElement('p');
3990
+ p.textContent = parentText;
3991
+
3992
+ parentList.parentElement.insertBefore(p, parentList);
3993
+
3994
+ if (children.length > 0) {
3995
+ parentList.insertBefore(fragment, li);
3996
+ }
3997
+
3998
+ li.remove();
3999
+
3964
4000
  const newRange = document.createRange();
3965
- newRange.setStart(firstChild, 0);
4001
+ newRange.selectNodeContents(p);
3966
4002
  newRange.collapse(true);
4003
+
3967
4004
  selection.removeAllRanges();
3968
4005
  selection.addRange(newRange);
3969
4006
  }
3970
4007
 
3971
- li.remove();
3972
4008
  core.updateCaretPosition();
3973
4009
  };
3974
4010