Make code a bit cleaner

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Š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

View file

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