Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit 73f96a3

Browse files
authored
chore: LSDV-1376: Remove ff for 2480 (empty nodes) (#1162)
1 parent 6a8b1db commit 73f96a3

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

src/utils/feature-flags.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ export const FF_DEV_2244 = 'ff_front_dev_2244_nested_choices_des_107_160522_shor
5757

5858
export const FF_DEV_2132 = 'ff_front_dev_2132_rotating_bounding_box';
5959

60-
export const FF_DEV_2480 = 'ff_dev_2480_convenient_offsets_270522_short';
61-
6260
export const FF_DEV_1442 = 'ff_front_dev_1442_unselect_shape_on_click_outside_080622_short';
6361

6462
export const FF_DEV_2431 = 'ff_front_dev_2431_delete_polygon_points_080622_short';

src/utils/selection-tools.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { FF_DEV_2480, isFF } from './feature-flags';
21
import { clamp, isDefined } from './utilities';
32

43
export const isTextNode = node => node && node.nodeType === Node.TEXT_NODE;
@@ -287,6 +286,8 @@ const textNodeLookup = (commonContainer, node, offset, direction = 'forward') =>
287286

288287
const walker = commonContainer.ownerDocument.createTreeWalker(commonContainer, NodeFilter.SHOW_ALL);
289288
let currentNode = walker.nextNode();
289+
// tree walker can't go backward, so we go forward to startNode and record every text node
290+
// to find the last one before startNode
290291
let lastTextNode;
291292

292293
while (currentNode && currentNode !== startNode) {
@@ -325,10 +326,10 @@ const fixRange = range => {
325326
// if user started selection from the end of the tag, start could be this tag,
326327
// so we should move it to more relevant one
327328
const selectionFromTheEnd = startContainer.wholeText.length === startOffset;
328-
// we skip ephemeral whitespace only text nodes, like \n between tags in original html
329+
// we skip ephemeral whitespace-only text nodes, like \n between tags in original html
329330
const isBasicallyEmpty = textNode => /^\s*$/.test(textNode.wholeText);
330331

331-
if (isFF(FF_DEV_2480) && (selectionFromTheEnd || isBasicallyEmpty(startContainer))) {
332+
if (selectionFromTheEnd || isBasicallyEmpty(startContainer)) {
332333
do {
333334
startContainer = textNodeLookup(commonContainer, startContainer, startOffset, 'forward-next');
334335
if (!startContainer) return null;
@@ -339,23 +340,15 @@ const fixRange = range => {
339340
}
340341

341342
if (!isTextNode(endContainer)) {
342-
let isIncluded = false;
343-
344343
endContainer = textNodeLookup(commonContainer, endContainer, endOffset, 'backward');
345344
if (!endContainer) return null;
346345

347-
if (isFF(FF_DEV_2480)) {
348-
while (/^\s*$/.test(endContainer.wholeText)) {
349-
endContainer = textNodeLookup(commonContainer, endContainer, endOffset, 'backward-next');
350-
if (!endContainer) return null;
351-
}
352-
// we skip empty whitespace only text nodes, so we need the found one to be included
353-
isIncluded = true;
354-
} else {
355-
isIncluded = range.toString().includes(endContainer.wholeText);
346+
while (/^\s*$/.test(endContainer.wholeText)) {
347+
endContainer = textNodeLookup(commonContainer, endContainer, endOffset, 'backward-next');
348+
if (!endContainer) return null;
356349
}
357-
358-
range.setEnd(endContainer, isIncluded ? endContainer.length : 0);
350+
// we skip empty whitespace-only text nodes, so we need the found one to be included
351+
range.setEnd(endContainer, endContainer.length);
359352
}
360353

361354
return range;

0 commit comments

Comments
 (0)