Skip to content

Commit a8cd95a

Browse files
SethFalconeilj
authored andcommitted
Release v2.0.2
1 parent c84f48e commit a8cd95a

File tree

8 files changed

+96
-68
lines changed

8 files changed

+96
-68
lines changed

dist/squire-raw.js

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -338,15 +338,15 @@
338338
if (!child || isLeaf(child)) {
339339
if (startOffset) {
340340
child = startContainer.childNodes[startOffset - 1];
341-
let prev = child.previousSibling;
342-
while (child instanceof Text && !child.length && prev && prev instanceof Text) {
343-
child.remove();
344-
child = prev;
345-
continue;
346-
}
347341
if (child instanceof Text) {
348-
startContainer = child;
349-
startOffset = child.data.length;
342+
let textChild = child;
343+
let prev;
344+
while (!textChild.length && (prev = textChild.previousSibling) && prev instanceof Text) {
345+
textChild.remove();
346+
textChild = prev;
347+
}
348+
startContainer = textChild;
349+
startOffset = textChild.data.length;
350350
}
351351
}
352352
break;
@@ -466,18 +466,14 @@
466466
return node;
467467
};
468468
var fixContainer = (container, root) => {
469-
const children = container.childNodes;
470469
let wrapper = null;
471-
for (let i = 0, l = children.length; i < l; i += 1) {
472-
const child = children[i];
470+
Array.from(container.childNodes).forEach((child) => {
473471
const isBR = child.nodeName === "BR";
474472
if (!isBR && isInline(child)) {
475473
if (!wrapper) {
476474
wrapper = createElement("DIV");
477475
}
478476
wrapper.appendChild(child);
479-
i -= 1;
480-
l -= 1;
481477
} else if (isBR || wrapper) {
482478
if (!wrapper) {
483479
wrapper = createElement("DIV");
@@ -487,15 +483,13 @@
487483
container.replaceChild(wrapper, child);
488484
} else {
489485
container.insertBefore(wrapper, child);
490-
i += 1;
491-
l += 1;
492486
}
493487
wrapper = null;
494488
}
495489
if (isContainer(child)) {
496490
fixContainer(child, root);
497491
}
498-
}
492+
});
499493
if (wrapper) {
500494
container.appendChild(fixCursor(wrapper));
501495
}
@@ -1721,6 +1715,7 @@
17211715
text.deleteData(offset - 1, 1);
17221716
self.setSelection(range);
17231717
self.removeLink();
1718+
event.preventDefault();
17241719
} else {
17251720
self.setSelection(range);
17261721
setTimeout(() => {
@@ -1928,8 +1923,27 @@
19281923
"ArrowLeft"(self) {
19291924
self._removeZWS();
19301925
},
1931-
"ArrowRight"(self) {
1926+
"ArrowRight"(self, event, range) {
19321927
self._removeZWS();
1928+
const root = self.getRoot();
1929+
if (rangeDoesEndAtBlockBoundary(range, root)) {
1930+
moveRangeBoundariesDownTree(range);
1931+
let node = range.endContainer;
1932+
do {
1933+
if (node.nodeName === "CODE") {
1934+
let next = node.nextSibling;
1935+
if (!(next instanceof Text)) {
1936+
const textNode = document.createTextNode("\xA0");
1937+
node.parentNode.insertBefore(textNode, next);
1938+
next = textNode;
1939+
}
1940+
range.setStart(next, 1);
1941+
self.setSelection(range);
1942+
event.preventDefault();
1943+
break;
1944+
}
1945+
} while (!node.nextSibling && (node = node.parentNode) && node !== root);
1946+
}
19331947
}
19341948
};
19351949
if (!supportsInputEvents) {
@@ -4032,7 +4046,7 @@
40324046
range = this.getSelection();
40334047
}
40344048
if (range.collapsed) {
4035-
return this;
4049+
return this.focus();
40364050
}
40374051
const root = this._root;
40384052
let stopNode = range.commonAncestorContainer;
@@ -4044,7 +4058,7 @@
40444058
stopNode = root;
40454059
}
40464060
if (stopNode instanceof Text) {
4047-
return this;
4061+
return this.focus();
40484062
}
40494063
this.saveUndoState(range);
40504064
moveRangeBoundariesUpTree(range, stopNode, stopNode, root);

dist/squire-raw.mjs

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,15 @@ var moveRangeBoundariesDownTree = (range) => {
340340
if (!child || isLeaf(child)) {
341341
if (startOffset) {
342342
child = startContainer.childNodes[startOffset - 1];
343-
let prev = child.previousSibling;
344-
while (child instanceof Text && !child.length && prev && prev instanceof Text) {
345-
child.remove();
346-
child = prev;
347-
continue;
348-
}
349343
if (child instanceof Text) {
350-
startContainer = child;
351-
startOffset = child.data.length;
344+
let textChild = child;
345+
let prev;
346+
while (!textChild.length && (prev = textChild.previousSibling) && prev instanceof Text) {
347+
textChild.remove();
348+
textChild = prev;
349+
}
350+
startContainer = textChild;
351+
startOffset = textChild.data.length;
352352
}
353353
}
354354
break;
@@ -468,18 +468,14 @@ var fixCursor = (node) => {
468468
return node;
469469
};
470470
var fixContainer = (container, root) => {
471-
const children = container.childNodes;
472471
let wrapper = null;
473-
for (let i = 0, l = children.length; i < l; i += 1) {
474-
const child = children[i];
472+
Array.from(container.childNodes).forEach((child) => {
475473
const isBR = child.nodeName === "BR";
476474
if (!isBR && isInline(child)) {
477475
if (!wrapper) {
478476
wrapper = createElement("DIV");
479477
}
480478
wrapper.appendChild(child);
481-
i -= 1;
482-
l -= 1;
483479
} else if (isBR || wrapper) {
484480
if (!wrapper) {
485481
wrapper = createElement("DIV");
@@ -489,15 +485,13 @@ var fixContainer = (container, root) => {
489485
container.replaceChild(wrapper, child);
490486
} else {
491487
container.insertBefore(wrapper, child);
492-
i += 1;
493-
l += 1;
494488
}
495489
wrapper = null;
496490
}
497491
if (isContainer(child)) {
498492
fixContainer(child, root);
499493
}
500-
}
494+
});
501495
if (wrapper) {
502496
container.appendChild(fixCursor(wrapper));
503497
}
@@ -1723,6 +1717,7 @@ var Backspace = (self, event, range) => {
17231717
text.deleteData(offset - 1, 1);
17241718
self.setSelection(range);
17251719
self.removeLink();
1720+
event.preventDefault();
17261721
} else {
17271722
self.setSelection(range);
17281723
setTimeout(() => {
@@ -1930,8 +1925,27 @@ var keyHandlers = {
19301925
"ArrowLeft"(self) {
19311926
self._removeZWS();
19321927
},
1933-
"ArrowRight"(self) {
1928+
"ArrowRight"(self, event, range) {
19341929
self._removeZWS();
1930+
const root = self.getRoot();
1931+
if (rangeDoesEndAtBlockBoundary(range, root)) {
1932+
moveRangeBoundariesDownTree(range);
1933+
let node = range.endContainer;
1934+
do {
1935+
if (node.nodeName === "CODE") {
1936+
let next = node.nextSibling;
1937+
if (!(next instanceof Text)) {
1938+
const textNode = document.createTextNode("\xA0");
1939+
node.parentNode.insertBefore(textNode, next);
1940+
next = textNode;
1941+
}
1942+
range.setStart(next, 1);
1943+
self.setSelection(range);
1944+
event.preventDefault();
1945+
break;
1946+
}
1947+
} while (!node.nextSibling && (node = node.parentNode) && node !== root);
1948+
}
19351949
}
19361950
};
19371951
if (!supportsInputEvents) {
@@ -4053,7 +4067,7 @@ var Squire = class {
40534067
range = this.getSelection();
40544068
}
40554069
if (range.collapsed) {
4056-
return this;
4070+
return this.focus();
40574071
}
40584072
const root = this._root;
40594073
let stopNode = range.commonAncestorContainer;
@@ -4065,7 +4079,7 @@ var Squire = class {
40654079
stopNode = root;
40664080
}
40674081
if (stopNode instanceof Text) {
4068-
return this;
4082+
return this.focus();
40694083
}
40704084
this.saveUndoState(range);
40714085
moveRangeBoundariesUpTree(range, stopNode, stopNode, root);

0 commit comments

Comments
 (0)