reimplement up arrow to edit
This commit is contained in:
4 files changed
+38
-1
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
default: patch
|
||||
---
|
||||
|
||||
Fix up arrow to edit messages not editing messages.
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 && (
|
||||
|
||||
Reference in new issue
Block a user