Skip to content

Commit e4b050d

Browse files
committed
fix(web): double space edge case
1 parent 71fbb85 commit e4b050d

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/web/pmPlugins/MentionPlugin/setMention.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ export function setMention(
4141

4242
// avoid inserting a space if there already is one
4343
const parentEnd = state.doc.resolve(extendedTo).end();
44-
const charAfter = state.doc.textBetween(extendedTo, extendedTo + 1, '');
45-
const hasSpaceAfter = extendedTo < parentEnd && /\s/.test(charAfter);
44+
let hasSpaceAfter = false;
45+
if (extendedTo < parentEnd) {
46+
const charAfter = state.doc.textBetween(extendedTo, extendedTo + 1, '');
47+
hasSpaceAfter = /\s/.test(charAfter);
48+
}
4649

4750
const mentionMark = mentionType.create({
4851
indicator,

src/web/pmPlugins/MentionPlugin/useMentionEvents.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ export function useMentionEvents(
4747

4848
const mention = getMentionInCurrentSelection(editor);
4949
if (!mention) {
50-
wasInMention = false;
51-
prevMentionKey = null;
5250
if (wasInMention) {
5351
cb.onMentionDetected({
5452
text: '',
5553
indicator: '',
5654
attributes: {},
5755
});
56+
wasInMention = false;
57+
prevMentionKey = null;
5858
}
5959
} else {
6060
wasInMention = true;

0 commit comments

Comments
 (0)