mirror of
https://github.com/nexu-io/open-design.git
synced 2026-06-01 03:14:35 +07:00
fix: clear stale mention state when @ button insertion is invalid
When the @ button is clicked at a position where the regex does not match (e.g., immediately after a word or on a second click after the button just inserted @), the handler now explicitly clears any existing mention state instead of leaving it intact. This prevents the popover from remaining bound to a previous cursor position, which would cause picking a file to replace the old mention location and leave the newly inserted @ behind. Mirrors the handleChange behavior which already clears mention when the regex stops matching.
This commit is contained in:
parent
7b64564b5c
commit
79554198ec
1 changed files with 6 additions and 2 deletions
|
|
@ -774,8 +774,12 @@ export const ChatComposer = forwardRef<ChatComposerHandle, Props>(
|
||||||
// does when it detects a fresh @ in the typed input.
|
// does when it detects a fresh @ in the typed input.
|
||||||
const pos = cursor + 1;
|
const pos = cursor + 1;
|
||||||
const textBefore = next.slice(0, pos);
|
const textBefore = next.slice(0, pos);
|
||||||
const m = /(^|\s)@([^\s@]*)$/.exec(textBefore);
|
const m = /(^|\\s)@([^\\s@]*)$/.exec(textBefore);
|
||||||
if (m) setMention({ q: m[2] ?? '', cursor: pos });
|
if (m) {
|
||||||
|
setMention({ q: m[2] ?? '', cursor: pos });
|
||||||
|
} else {
|
||||||
|
setMention(null);
|
||||||
|
}
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
ta.focus();
|
ta.focus();
|
||||||
ta.setSelectionRange(pos, pos);
|
ta.setSelectionRange(pos, pos);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue