Skip to content

Commit

Permalink
chat: implement first part of automention and also fix bug with resto…
Browse files Browse the repository at this point in the history
…ring selection
  • Loading branch information
williamstein committed Oct 12, 2024
1 parent 427e813 commit e793d72
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
13 changes: 12 additions & 1 deletion src/packages/frontend/chat/message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,17 @@ export default function Message(props: Readonly<Props>) {
return;
}
const replyDate = -getThreadRootDate({ date, messages });
let input;
if (isLLMThread) {
input = "";
} else {
const replying_to = message.get("history")?.first()?.get("author_id");
if (!replying_to || replying_to == props.account_id) {
input = "";
} else {
input = `<span class="user-mention" account-id=${replying_to} >@${editor_name}</span> `;
}
}
return (
<div style={{ marginLeft: mode === "standalone" ? "30px" : "0" }}>
<ChatInput
Expand All @@ -778,7 +789,7 @@ export default function Message(props: Readonly<Props>) {
height: "auto" /* for some reason the default 100% breaks things */,
}}
cacheId={`${props.path}${props.project_id}${date}-reply`}
input={""}
input={input}
submitMentionsRef={replyMentionsRef}
on_send={sendReply}
height={"auto"}
Expand Down
31 changes: 21 additions & 10 deletions src/packages/frontend/editors/markdown-input/multimode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ export default function MultiMarkdownInput(props: Props) {

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

const getKey = () => `${project_id}${path}:${cacheId}`;

function getCache() {
return cacheId === undefined
? undefined
: multimodeStateCache.get(`${project_id}${path}:${cacheId}`);
return cacheId == null ? undefined : multimodeStateCache.get(getKey());
}

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

useEffect(() => {
if (cacheId == null) return;
if (cacheId == null) {
return;
}
const cache = getCache();
if (cache?.[mode] != null && selectionRef.current != null) {
// restore selection on mount.
try {
selectionRef.current.setSelection(cache?.[mode]);
} catch (_err) {
// console.warn(_err); // definitely don't need this.
// This is expected to fail, since the selection from last
// use will be invalid now if another user changed the
// document, etc., or you did in a different mode, possibly.
// it might just be that the document isn't initialized yet
setTimeout(() => {
try {
selectionRef.current?.setSelection(cache?.[mode]);
} catch (_err2) {
// console.warn(_err2); // definitely don't need this.
// This is expected to fail, since the selection from last
// use will be invalid now if another user changed the
// document, etc., or you did in a different mode, possibly.
}
}, 100);
}
}
return () => {
if (selectionRef.current == null || cacheId == null) return;
if (selectionRef.current == null || cacheId == null) {
return;
}
const selection = selectionRef.current.getSelection();
multimodeStateCache.set(`${project_id}${path}:${cacheId}`, {
multimodeStateCache.set(getKey(), {
...getCache(),
[mode]: selection,
});
Expand Down

0 comments on commit e793d72

Please sign in to comment.