Skip to content

Commit e793d72

Browse files
committed
chat: implement first part of automention and also fix bug with restoring selection
1 parent 427e813 commit e793d72

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

src/packages/frontend/chat/message.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,17 @@ export default function Message(props: Readonly<Props>) {
768768
return;
769769
}
770770
const replyDate = -getThreadRootDate({ date, messages });
771+
let input;
772+
if (isLLMThread) {
773+
input = "";
774+
} else {
775+
const replying_to = message.get("history")?.first()?.get("author_id");
776+
if (!replying_to || replying_to == props.account_id) {
777+
input = "";
778+
} else {
779+
input = `<span class="user-mention" account-id=${replying_to} >@${editor_name}</span> `;
780+
}
781+
}
771782
return (
772783
<div style={{ marginLeft: mode === "standalone" ? "30px" : "0" }}>
773784
<ChatInput
@@ -778,7 +789,7 @@ export default function Message(props: Readonly<Props>) {
778789
height: "auto" /* for some reason the default 100% breaks things */,
779790
}}
780791
cacheId={`${props.path}${props.project_id}${date}-reply`}
781-
input={""}
792+
input={input}
782793
submitMentionsRef={replyMentionsRef}
783794
on_send={sendReply}
784795
height={"auto"}

src/packages/frontend/editors/markdown-input/multimode.tsx

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,10 @@ export default function MultiMarkdownInput(props: Props) {
204204

205205
const editBar2 = useRef<JSX.Element | undefined>(undefined);
206206

207+
const getKey = () => `${project_id}${path}:${cacheId}`;
208+
207209
function getCache() {
208-
return cacheId === undefined
209-
? undefined
210-
: multimodeStateCache.get(`${project_id}${path}:${cacheId}`);
210+
return cacheId == null ? undefined : multimodeStateCache.get(getKey());
211211
}
212212

213213
const [mode, setMode0] = useState<Mode>(
@@ -248,23 +248,34 @@ export default function MultiMarkdownInput(props: Props) {
248248
} | null>(null);
249249

250250
useEffect(() => {
251-
if (cacheId == null) return;
251+
if (cacheId == null) {
252+
return;
253+
}
252254
const cache = getCache();
253255
if (cache?.[mode] != null && selectionRef.current != null) {
254256
// restore selection on mount.
255257
try {
256258
selectionRef.current.setSelection(cache?.[mode]);
257259
} catch (_err) {
258-
// console.warn(_err); // definitely don't need this.
259-
// This is expected to fail, since the selection from last
260-
// use will be invalid now if another user changed the
261-
// document, etc., or you did in a different mode, possibly.
260+
// it might just be that the document isn't initialized yet
261+
setTimeout(() => {
262+
try {
263+
selectionRef.current?.setSelection(cache?.[mode]);
264+
} catch (_err2) {
265+
// console.warn(_err2); // definitely don't need this.
266+
// This is expected to fail, since the selection from last
267+
// use will be invalid now if another user changed the
268+
// document, etc., or you did in a different mode, possibly.
269+
}
270+
}, 100);
262271
}
263272
}
264273
return () => {
265-
if (selectionRef.current == null || cacheId == null) return;
274+
if (selectionRef.current == null || cacheId == null) {
275+
return;
276+
}
266277
const selection = selectionRef.current.getSelection();
267-
multimodeStateCache.set(`${project_id}${path}:${cacheId}`, {
278+
multimodeStateCache.set(getKey(), {
268279
...getCache(),
269280
[mode]: selection,
270281
});

0 commit comments

Comments
 (0)