Skip to content

Commit

Permalink
Fix tab replacement composition crash
Browse files Browse the repository at this point in the history
  • Loading branch information
zurfyx committed Sep 28, 2023
1 parent 0e5671a commit 9d73c10
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/lexical/src/LexicalSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import {
scrollIntoViewIfNeeded,
toggleTextFormatType,
} from './LexicalUtils';
import {$createTabNode} from './nodes/LexicalTabNode';
import {$createTabNode, $isTabNode} from './nodes/LexicalTabNode';

export type TextPointType = {
_selection: RangeSelection | GridSelection;
Expand Down Expand Up @@ -1205,6 +1205,15 @@ export class RangeSelection implements BaseSelection {
}
return;
}
} else if ($isTabNode(firstNode)) {
// We don't need to check for delCount because there is only the entire selected node case
// that can hit here for content size 1 and with canInsertTextBeforeAfter false
const textNode = $createTextNode(text);
textNode.setFormat(format);
textNode.setStyle(style);
textNode.select();
firstNode.replace(textNode);
return;
}
const delCount = endOffset - startOffset;

Expand Down
9 changes: 9 additions & 0 deletions packages/lexical/src/nodes/LexicalTabNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ export class TabNode extends TextNode {
invariant(false, 'TabNode does not support setTextContent');
}

spliceText(
_offset: number,
_delCount: number,
_newText: string,
_moveSelection?: boolean | undefined,
): TextNode {
invariant(false, 'TabNode does not support spliceText');
}

setDetail(_detail: TextDetailType | number): this {
invariant(false, 'TabNode does not support setDetail');
}
Expand Down

0 comments on commit 9d73c10

Please sign in to comment.