mirror of
https://github.com/nexu-io/open-design.git
synced 2026-05-31 19:04:39 +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.
|
||||
const pos = cursor + 1;
|
||||
const textBefore = next.slice(0, pos);
|
||||
const m = /(^|\s)@([^\s@]*)$/.exec(textBefore);
|
||||
if (m) setMention({ q: m[2] ?? '', cursor: pos });
|
||||
const m = /(^|\\s)@([^\\s@]*)$/.exec(textBefore);
|
||||
if (m) {
|
||||
setMention({ q: m[2] ?? '', cursor: pos });
|
||||
} else {
|
||||
setMention(null);
|
||||
}
|
||||
requestAnimationFrame(() => {
|
||||
ta.focus();
|
||||
ta.setSelectionRange(pos, pos);
|
||||
|
|
|
|||
Loading…
Reference in a new issue