Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Close editing when end of message is reached
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Jan 26, 2023
1 parent d94f388 commit 156b787
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import EditorStateTransfer from "../../../../../utils/EditorStateTransfer";
import { useMatrixClientContext } from "../../../../../contexts/MatrixClientContext";
import { isCaretAtEnd, isCaretAtStart } from "../utils/selection";
import { getEventsFromEditorStateTransfer } from "../utils/event";
import { endEditing } from "../utils/editing";

export function useInputEventProcessor(
onSend: () => void,
Expand Down Expand Up @@ -112,8 +113,13 @@ function handleKeyboardEvent(
break;
}

dispatchEditEvent(event, true, editorStateTransfer, roomContext, mxClient);
// TODO cancel edit if no newEvent
const isDispatched = dispatchEditEvent(event, true, editorStateTransfer, roomContext, mxClient);
if (!isDispatched) {
endEditing(roomContext);
event.preventDefault();
event.stopPropagation();
}

break;
}
}
Expand All @@ -127,10 +133,10 @@ function dispatchEditEvent(
editorStateTransfer: EditorStateTransfer,
roomContext: IRoomState,
mxClient: MatrixClient,
): void {
): boolean {
const foundEvents = getEventsFromEditorStateTransfer(editorStateTransfer, roomContext, mxClient);
if (!foundEvents) {
return;
return false;
}

const newEvent = findEditableEvent({
Expand All @@ -146,7 +152,9 @@ function dispatchEditEvent(
});
event.stopPropagation();
event.preventDefault();
return true;
}
return false;
}

type InputEvent = Exclude<WysiwygEvent, KeyboardEvent | ClipboardEvent>;
Expand Down

0 comments on commit 156b787

Please sign in to comment.