Skip to content

Commit

Permalink
Use Content Model to handle Delete/Backspace key in more cases (#2162)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiuqingSong authored Oct 24, 2023
1 parent 1ffe2e3 commit bc809e7
Showing 1 changed file with 2 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,12 @@ function shouldDeleteWithContentModel(range: Range | null, rawEvent: KeyboardEve
}

function canDeleteBefore(rawEvent: KeyboardEvent, range: Range) {
return (
rawEvent.key == 'Backspace' &&
(range.startOffset > 1 || range.startContainer.previousSibling)
);
return rawEvent.key == 'Backspace' && range.startOffset > 1;
}

function canDeleteAfter(rawEvent: KeyboardEvent, range: Range) {
return (
rawEvent.key == 'Delete' &&
(range.startOffset < (range.startContainer.nodeValue?.length ?? 0) - 1 ||
range.startContainer.nextSibling)
range.startOffset < (range.startContainer.nodeValue?.length ?? 0) - 1
);
}

0 comments on commit bc809e7

Please sign in to comment.