fix: safari 浏览器在组合输入法中会直接插入@导致会有两个@符号

This commit is contained in:
yanmao 2021-12-17 23:16:54 +08:00
parent 919e7cac8c
commit 357f5270ce
2 changed files with 11 additions and 8 deletions

View File

@ -101,6 +101,14 @@ class ChangeEvent implements ChangeEventInterface {
//https://rawgit.com/w3c/input-events/v1/index.html#interface-InputEvent-Attributes
this.onContainer('beforeinput', (event: InputEvent) => {
if (this.engine.readonly) return;
// safari 组合输入法会直接输入字符
if (isSafari && event.data === '@') {
const result = this.engine.trigger('keydown:at', event);
if (result === false) {
event.preventDefault();
return;
}
}
const { change, card, node, block, list } = this.engine;
if (!change.rangePathBeforeCommand)
change.cacheRangeBeforeCommand();

View File

@ -160,11 +160,6 @@ class MentionPlugin extends Plugin<Options> {
if (!isEngine(this.editor)) return;
const { change } = this.editor;
let range = change.range.get();
const block = this.editor.block.closest(range.startNode);
const text = block.text().trim();
if (text === '@' && isSafari) {
block.empty();
}
// 空格触发
if (this.options.spaceTrigger) {
@ -181,9 +176,8 @@ class MentionPlugin extends Plugin<Options> {
}
}
event.preventDefault(); // 插入 @,并弹出选择器
range = change.range.get();
event.preventDefault();
// 插入 @,并弹出选择器
if (range.collapsed) {
event.preventDefault();
const card = this.editor.card.insert(MentionComponent.cardName);
@ -196,6 +190,7 @@ class MentionPlugin extends Plugin<Options> {
range.collapse(false);
change.range.select(range);
}
return false;
}
getList() {