Merge pull request #5030 from matrix-org/t3chguy/fix/13641
Fix autocomplete suggesting a different thing mid-composition
This commit is contained in:
commit
6635a44314
3 changed files with 40 additions and 2 deletions
|
@ -34,7 +34,8 @@ import EMOTICON_REGEX from 'emojibase-regex/emoticon';
|
||||||
const LIMIT = 20;
|
const LIMIT = 20;
|
||||||
|
|
||||||
// Match for ascii-style ";-)" emoticons or ":wink:" shortcodes provided by emojibase
|
// 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 {
|
interface IEmojiShort {
|
||||||
emoji: IEmoji;
|
emoji: IEmoji;
|
||||||
|
|
|
@ -186,7 +186,11 @@ abstract class PlainBasePart extends BasePart {
|
||||||
}
|
}
|
||||||
// when not pasting or dropping text, reject characters that should start a pill candidate
|
// when not pasting or dropping text, reject characters that should start a pill candidate
|
||||||
if (inputType !== "insertFromPaste" && inputType !== "insertFromDrop") {
|
if (inputType !== "insertFromPaste" && inputType !== "insertFromDrop") {
|
||||||
return chr !== "@" && chr !== "#" && chr !== ":" && chr !== "+";
|
if (chr !== "@" && chr !== "#" && chr !== ":" && chr !== "+") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// only split if the previous character is a space
|
||||||
|
return this._text[offset - 1] !== " ";
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -281,5 +281,38 @@ describe('editor/model', function() {
|
||||||
expect(model.parts[0].type).toBe("plain");
|
expect(model.parts[0].type).toBe("plain");
|
||||||
expect(model.parts[0].text).toBe("try #define");
|
expect(model.parts[0].text).toBe("try #define");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('insert room pill without splitting at the 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");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue