Skip to content

Commit

Permalink
fix: Verify if there are text nodes before continue (facebook#2616)
Browse files Browse the repository at this point in the history
* fix: Verify if there are text nodes before continue

* Update packages/lexical/src/LexicalSelection.ts

Co-authored-by: Gerard Rovira <zurfyx@users.noreply.github.com>

* fix: Before returning, apply format

Co-authored-by: Gerard Rovira <zurfyx@users.noreply.github.com>
  • Loading branch information
nalejandroveron and zurfyx authored Aug 1, 2022
1 parent 27430b1 commit 7c18bd3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/lexical/src/LexicalSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,14 @@ export class RangeSelection implements BaseSelection {
}
}
const selectedTextNodesLength = selectedTextNodes.length;

if (selectedTextNodesLength === 0) {
this.toggleFormat(formatType);
// When changing format, we should stop composition
$setCompositionKey(null);
return;
}

let firstIndex = 0;
const lastIndex = selectedTextNodesLength - 1;
let firstNode = selectedTextNodes[0];
Expand Down

0 comments on commit 7c18bd3

Please sign in to comment.