From 2071a225ce015e1ae00a86c9953665e823e26b30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B3=E5=BB=B7=E5=AE=89?= <73953029+nrps9909@users.noreply.github.com> Date: Fri, 28 Aug 2026 15:18:48 +0800 Subject: [PATCH] fix: preserve multi-character mention splits --- src/util.ts | 2 +- tests/FullProcess.spec.tsx | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/util.ts b/src/util.ts index 11c08f1b..be95bea0 100644 --- a/src/util.ts +++ b/src/util.ts @@ -80,7 +80,7 @@ export function replaceWithMeasure(text: string, measureConfig: MeasureConfig) { // Before text will append one space if have other text let beforeMeasureText = text.slice(0, measureLocation); - if (beforeMeasureText[beforeMeasureText.length - split.length] === split) { + if (split && beforeMeasureText.endsWith(split)) { beforeMeasureText = beforeMeasureText.slice( 0, beforeMeasureText.length - split.length, diff --git a/tests/FullProcess.spec.tsx b/tests/FullProcess.spec.tsx index e7f6478b..b63b8cfc 100644 --- a/tests/FullProcess.spec.tsx +++ b/tests/FullProcess.spec.tsx @@ -88,6 +88,19 @@ describe('Full Process', () => { expect(onChange).toBeCalledWith('1 @bamboo 2'); }); + it('does not duplicate a multi-character split before a mention', () => { + const onChange = jest.fn(); + const { container } = createMentions({ onChange, split: '::' }); + + simulateInput(container, 'hello::@b'); + fireEvent.keyDown(container.querySelector('textarea'), { + keyCode: KeyCode.ENTER, + which: KeyCode.ENTER, + }); + + expect(onChange).toHaveBeenLastCalledWith('hello::@bamboo::'); + }); + it('azerty Keyboards ', () => { const onChange = jest.fn(); const { container } = createMentions({ onChange });