From 8018a20680af1ad316f6964d29d2c7405b7ec3a7 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 21 Jul 2020 17:40:34 +0100 Subject: [PATCH 1/4] create acceptance tests Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- test/editor/model-test.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/editor/model-test.js b/test/editor/model-test.js index 2a3584d508..2ba82d3c01 100644 --- a/test/editor/model-test.js +++ b/test/editor/model-test.js @@ -281,5 +281,38 @@ describe('editor/model', function() { expect(model.parts[0].type).toBe("plain"); expect(model.parts[0].text).toBe("try #define"); }); + + it('insert room pill without splitting at the semi-colon', () => { + const renderer = createRenderer(); + const pc = createPartCreator([{resourceId: "#room:server"}]); + const model = new EditorModel([], pc, renderer); + + model.update("#roo", "insertText", {offset: 4, atNodeEnd: true}); + + expect(renderer.count).toBe(1); + expect(model.parts.length).toBe(1); + expect(model.parts[0].type).toBe("pill-candidate"); + expect(model.parts[0].text).toBe("#roo"); + + model.update("#room:s", "insertText", {offset: 7, atNodeEnd: true}); + + expect(renderer.count).toBe(2); + expect(model.parts.length).toBe(1); + expect(model.parts[0].type).toBe("pill-candidate"); + expect(model.parts[0].text).toBe("#room:s"); + }); + + it('allow typing e-mail addresses without splitting at the @', () => { + const renderer = createRenderer(); + const pc = createPartCreator([{resourceId: "@alice", label: "Alice"}]); + const model = new EditorModel([], pc, renderer); + + model.update("foo@a", "insertText", {offset: 5, atNodeEnd: true}); + + expect(renderer.count).toBe(1); + expect(model.parts.length).toBe(1); + expect(model.parts[0].type).toBe("plain"); + expect(model.parts[0].text).toBe("foo@a"); + }); }); }); From 93884cb89ba25ba35db85ce4e4c9182b889f863e Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 21 Jul 2020 17:50:24 +0100 Subject: [PATCH 2/4] Update PlainBasePart to only split on space boundaries Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/editor/parts.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/editor/parts.ts b/src/editor/parts.ts index ed48fcbe4e..f707d8374e 100644 --- a/src/editor/parts.ts +++ b/src/editor/parts.ts @@ -186,7 +186,11 @@ abstract class PlainBasePart extends BasePart { } // when not pasting or dropping text, reject characters that should start a pill candidate if (inputType !== "insertFromPaste" && inputType !== "insertFromDrop") { - return chr !== "@" && chr !== "#" && chr !== ":"; + if (chr !== "@" && chr !== "#" && chr !== ":") { + return true; + } + // only split if the previous character is a space + return this._text[offset - 1] !== " "; } return true; } From 0075ae21875d749f49aaec9cbbcc211c2af2b6ee Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 21 Jul 2020 17:53:16 +0100 Subject: [PATCH 3/4] update emoji provider regex Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/autocomplete/EmojiProvider.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/autocomplete/EmojiProvider.tsx b/src/autocomplete/EmojiProvider.tsx index c4dd3ec9cc..147d68f5ff 100644 --- a/src/autocomplete/EmojiProvider.tsx +++ b/src/autocomplete/EmojiProvider.tsx @@ -34,7 +34,8 @@ import EMOTICON_REGEX from 'emojibase-regex/emoticon'; const LIMIT = 20; // Match for ascii-style ";-)" emoticons or ":wink:" shortcodes provided by emojibase -const EMOJI_REGEX = new RegExp('(' + EMOTICON_REGEX.source + '|:[+-\\w]*:?)$', 'g'); +// anchored to only match from the start of parts otherwise it'll show emoji suggestions whilst typing matrix IDs +const EMOJI_REGEX = new RegExp('(' + EMOTICON_REGEX.source + '|(?:^|\\s):[+-\\w]*:?)$', 'g'); interface IEmojiShort { emoji: IEmoji; From 93b0287e11fb7056bdb7cc4c353d7b1908bd1bae Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 24 Jul 2020 00:04:50 +0100 Subject: [PATCH 4/4] s/semi-colon/colon/ Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- test/editor/model-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/editor/model-test.js b/test/editor/model-test.js index 2ba82d3c01..2df9fdd573 100644 --- a/test/editor/model-test.js +++ b/test/editor/model-test.js @@ -282,7 +282,7 @@ describe('editor/model', function() { expect(model.parts[0].text).toBe("try #define"); }); - it('insert room pill without splitting at the semi-colon', () => { + it('insert room pill without splitting at the colon', () => { const renderer = createRenderer(); const pc = createPartCreator([{resourceId: "#room:server"}]); const model = new EditorModel([], pc, renderer);