Skip to content

Commit 060f992

Browse files
committed
fix slate case of #7563 -- @mentions are too aggressive
1 parent 96fcca5 commit 060f992

File tree

1 file changed

+8
-1
lines changed
  • src/packages/frontend/editors/slate/slate-mentions

1 file changed

+8
-1
lines changed

src/packages/frontend/editors/slate/slate-mentions/hook.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ export const useMentions: (Options) => MentionsControl = ({
9494
}
9595
if (Text.isText(current)) {
9696
const charBeforeCursor = current.text[focus.offset - 1];
97+
const charBeforeBefore = current.text[focus.offset - 2]?.trim();
9798
let afterMatch, beforeMatch, beforeRange, search;
99+
// try to keep this consistent with before stuff in frontend/editors/markdown-input/component.tsx
98100
if (charBeforeCursor == "@") {
99101
beforeRange = {
100102
focus: editor.selection.focus,
@@ -118,7 +120,12 @@ export const useMentions: (Options) => MentionsControl = ({
118120
const afterText = Editor.string(editor, afterRange);
119121
afterMatch = afterText.match(/^(\s|$)/);
120122
}
121-
if (charBeforeCursor == "@" || (beforeMatch && afterMatch)) {
123+
if (
124+
(charBeforeCursor == "@" || (beforeMatch && afterMatch)) &&
125+
(!charBeforeBefore ||
126+
charBeforeBefore == "(" ||
127+
charBeforeBefore == "[")
128+
) {
122129
setTarget(beforeRange);
123130
setSearch(search);
124131
return;

0 commit comments

Comments
 (0)