Skip to content

Commit 5744a08

Browse files
[lexical][lexical-clipboard][lexical-playground][lexical-react][lexical-selection][lexical-table][lexical-utils] Clean up createSelectionWithComposedRanges
1 parent 02a5c56 commit 5744a08

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

packages/lexical/src/LexicalUtils.ts

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,31 +1895,16 @@ export function createSelectionWithComposedRanges(
18951895
): void {
18961896
// For shadow DOM, sync ranges and delegate to native modify
18971897
// Complex logic is handled at higher levels in Lexical
1898-
try {
1899-
if (composedRanges.length > 0 && firstRange) {
1900-
// Sync our composed ranges to the base DOM selection
1901-
const range = document.createRange();
1902-
range.setStart(
1903-
firstRange.startContainer,
1904-
firstRange.startOffset,
1905-
);
1906-
range.setEnd(firstRange.endContainer, firstRange.endOffset);
1907-
1908-
target.removeAllRanges();
1909-
target.addRange(range);
1910-
1911-
// For Shadow DOM, delegate to native modify first, then handle manually if needed
1912-
try {
1913-
target.modify(alter, direction, granularity);
1914-
} catch (_error) {
1915-
// If native modify fails, we'll handle it at a higher level in Lexical
1916-
}
1917-
}
1898+
if (composedRanges.length > 0 && firstRange) {
1899+
// Sync our composed ranges to the base DOM selection
1900+
const range = document.createRange();
1901+
range.setStart(firstRange.startContainer, firstRange.startOffset);
1902+
range.setEnd(firstRange.endContainer, firstRange.endOffset);
19181903

1919-
// Fallback to base selection modify for non-shadow DOM cases
1920-
target.modify(alter, direction, granularity);
1921-
} catch (_error) {
1922-
// If anything fails, just delegate to the base selection
1904+
target.removeAllRanges();
1905+
target.addRange(range);
1906+
1907+
// For Shadow DOM, delegate to native modify first, then handle manually if needed
19231908
target.modify(alter, direction, granularity);
19241909
}
19251910
};

0 commit comments

Comments
 (0)