Skip to content

Commit 0e90dc1

Browse files
committed
chat: fix cursor jumping bug in chat
1 parent 085c16f commit 0e90dc1

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/packages/frontend/chat/input.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ interface Props {
3636
editBarStyle?: CSS;
3737
placeholder?: string;
3838
autoFocus?: boolean;
39+
moveCursorToEndOfLine?: boolean;
3940
}
4041

4142
export default function ChatInput({
@@ -55,6 +56,7 @@ export default function ChatInput({
5556
style,
5657
submitMentionsRef,
5758
syncdb,
59+
moveCursorToEndOfLine,
5860
}: Props) {
5961
const intl = useIntl();
6062
const onSendRef = useRef<Function>(on_send);
@@ -82,7 +84,7 @@ export default function ChatInput({
8284
// See https://github.com/sagemathinc/cocalc/issues/6415
8385
const input = dbInput ?? propsInput;
8486
setInput(input);
85-
if (input?.trim()) {
87+
if (input?.trim() && moveCursorToEndOfLine) {
8688
// have to wait until it's all rendered -- i hate code like this...
8789
for (const n of [1, 10, 50]) {
8890
setTimeout(() => {

src/packages/frontend/chat/message.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ export default function Message(props: Readonly<Props>) {
769769
}
770770
const replyDate = -getThreadRootDate({ date, messages });
771771
let input;
772+
let moveCursorToEndOfLine = false;
772773
if (isLLMThread) {
773774
input = "";
774775
} else {
@@ -777,13 +778,15 @@ export default function Message(props: Readonly<Props>) {
777778
input = "";
778779
} else {
779780
input = `<span class="user-mention" account-id=${replying_to} >@${editor_name}</span> `;
781+
moveCursorToEndOfLine = autoFocusReply;
780782
}
781783
}
782784
return (
783785
<div style={{ marginLeft: mode === "standalone" ? "30px" : "0" }}>
784786
<ChatInput
785787
fontSize={font_size}
786788
autoFocus={autoFocusReply}
789+
moveCursorToEndOfLine={moveCursorToEndOfLine}
787790
style={{
788791
borderRadius: "8px",
789792
height: "auto" /* for some reason the default 100% breaks things */,
@@ -879,8 +882,9 @@ export default function Message(props: Readonly<Props>) {
879882
!props.allowReply ||
880883
is_folded ||
881884
props.actions == null
882-
)
885+
) {
883886
return;
887+
}
884888

885889
return (
886890
<div style={{ textAlign: "center", marginBottom: "5px", width: "100%" }}>

0 commit comments

Comments
 (0)