Make code a bit cleaner

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
pull/21833/head
Šimon Brandner 2021-07-12 12:52:05 +02:00
parent 48a6a83745
commit 069c1f4665
No known key found for this signature in database
GPG Key ID: 9760693FDD98A790
1 changed files with 4 additions and 4 deletions

View File

@ -507,7 +507,7 @@ export default class BasicMessageEditor extends React.Component<IProps, IState>
handled = true;
} else if (event.key === Key.BACKSPACE || event.key === Key.DELETE) {
this.formatBarRef.current.hide();
handled = this.fakeDeletion(event.key === Key.BACKSPACE ? "deleteContentBackward" : "deleteContentForward");
handled = this.fakeDeletion(event.key === Key.BACKSPACE);
}
if (handled) {
@ -523,7 +523,7 @@ export default class BasicMessageEditor extends React.Component<IProps, IState>
* @param direction in which to delete
* @returns handled
*/
private fakeDeletion(direction: "deleteContentForward" | "deleteContentBackward" ): boolean {
private fakeDeletion(backward: boolean): boolean {
const selection = document.getSelection();
// Use the default handling for ranges
if (selection.type === "Range") return false;
@ -532,10 +532,10 @@ export default class BasicMessageEditor extends React.Component<IProps, IState>
const { caret, text } = getCaretOffsetAndText(this.editorRef.current, selection);
// Do the deletion itself
if (direction === "deleteContentBackward") caret.offset--;
if (backward) caret.offset--;
const newText = text.slice(0, caret.offset) + text.slice(caret.offset + 1);
this.props.model.update(newText, direction, caret);
this.props.model.update(newText, backward ? "deleteContentBackward" : "deleteContentForward", caret);
return true;
}