Skip to content

Commit

Permalink
Make code a bit cleaner
Browse files Browse the repository at this point in the history
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
  • Loading branch information
SimonBrandner committed Jul 12, 2021
1 parent 48a6a83 commit 069c1f4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/components/views/rooms/BasicMessageComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down

0 comments on commit 069c1f4

Please sign in to comment.