reimplement up arrow to edit

This commit is contained in:
7w1 committed 2026-03-20 21:22:15 -05:00
1 parent 5bcfe23b58
commit 849bc7694c
4 files changed
+38 -1

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
default: patch
---
Fix up arrow to edit messages not editing messages.
+11 -1
View File
@@ -231,9 +231,10 @@ interface RoomInputProps {
roomId: string;
room: Room;
threadRootId?: string;
onEditLastMessage?: () => void;
}
export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
({ editor, fileDropContainerRef, roomId, room, threadRootId }, ref) => {
({ editor, fileDropContainerRef, roomId, room, threadRootId, onEditLastMessage }, ref) => {
// When in thread mode, isolate drafts by thread root ID so thread replies
// don't clobber the main room draft (and vice versa).
const draftKey = threadRootId ?? roomId;
@@ -891,6 +892,15 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
}
}
if (isKeyHotkey('arrowup', evt) && isEmptyEditor(editor)) {
const { selection } = editor;
if (selection && Editor.isStart(editor, selection.anchor, [])) {
evt.preventDefault();
onEditLastMessage?.();
return;
}
}
if (
(isKeyHotkey('mod+enter', evt) || (!enterForNewline && isKeyHotkey('enter', evt))) &&
!isComposing(evt)
+19
View File
@@ -109,6 +109,7 @@ export type RoomTimelineProps = {
eventId?: string;
editor: Editor;
onEditorReset?: () => void;
onEditLastMessageRef?: React.MutableRefObject<(() => void) | undefined>;
};
export function RoomTimeline({
@@ -116,6 +117,7 @@ export function RoomTimeline({
eventId,
editor,
onEditorReset,
onEditLastMessageRef,
}: Readonly<RoomTimelineProps>) {
const mx = useMatrixClient();
const alive = useAlive();
@@ -660,6 +662,23 @@ export function RoomTimeline({
processedEventsRef.current = processedEvents;
useEffect(() => {
if (!onEditLastMessageRef) return;
const ref = onEditLastMessageRef;
ref.current = () => {
const myUserId = mx.getUserId();
const found = [...processedEventsRef.current]
.reverse()
.find(
(e) =>
e.mEvent.getSender() === myUserId &&
e.mEvent.getType() === 'm.room.message' &&
!e.mEvent.isRedacted()
);
if (found?.mEvent.getId()) actions.handleEdit(found.mEvent.getId());
};
}, [onEditLastMessageRef, mx, actions]);
useEffect(() => {
const v = vListRef.current;
if (!v) return;
+3
View File
@@ -73,6 +73,7 @@ const shouldFocusMessageField = (evt: KeyboardEvent): boolean => {
export function RoomView({ eventId }: { eventId?: string }) {
const roomInputRef = useRef<HTMLDivElement>(null);
const roomViewRef = useRef<HTMLDivElement>(null);
const editLastMessageRef = useRef<(() => void) | undefined>();
const [hideReads] = useSetting(settingsAtom, 'hideReads');
const screenSize = useScreenSizeContext();
@@ -161,6 +162,7 @@ export function RoomView({ eventId }: { eventId?: string }) {
eventId={eventId}
editor={editor}
onEditorReset={handleResetEditor}
onEditLastMessageRef={editLastMessageRef}
/>
<RoomViewTyping room={room} />
<GlobalModalManager />
@@ -186,6 +188,7 @@ export function RoomView({ eventId }: { eventId?: string }) {
roomId={roomId}
fileDropContainerRef={roomViewRef}
ref={roomInputRef}
onEditLastMessage={() => editLastMessageRef.current?.()}
/>
)}
{!canMessage && (