This commit is contained in:
parent
1ad691620a
commit
3f77e6fe97
3 changed files with 18 additions and 14 deletions
|
@ -36,7 +36,8 @@ export class Hint {
|
|||
public timeId: number;
|
||||
public element: HTMLDivElement;
|
||||
public enableSlash = true;
|
||||
public enableEmoji = false;
|
||||
private enableEmoji = true;
|
||||
public enableExtend = false;
|
||||
public splitChar = "";
|
||||
public lastIndex = -1;
|
||||
|
||||
|
@ -122,6 +123,10 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
|
|||
clearTimeout(this.timeId);
|
||||
return;
|
||||
}
|
||||
if (!this.enableExtend) {
|
||||
clearTimeout(this.timeId);
|
||||
return;
|
||||
}
|
||||
protyle.toolbar.range = getSelection().getRangeAt(0);
|
||||
const start = getSelectionOffset(protyle.toolbar.range.startContainer as HTMLElement, protyle.wysiwyg.element).start;
|
||||
const currentLineValue = protyle.toolbar.range.startContainer.textContent.substring(0, start) || "";
|
||||
|
@ -194,7 +199,7 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
|
|||
data.forEach((hintData, i) => {
|
||||
// https://github.com/siyuan-note/siyuan/issues/1229 提示时,新建文件不应默认选中
|
||||
let focusClass = "";
|
||||
if ((i === 1 && data[i].focus ) ||
|
||||
if ((i === 1 && data[i].focus) ||
|
||||
(i === 0 && (data.length === 1 || !data[1].focus))) {
|
||||
focusClass = " b3-list-item--focus";
|
||||
}
|
||||
|
@ -327,7 +332,7 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
|
|||
panelElement.nextElementSibling.classList.remove("fn__none");
|
||||
}
|
||||
} else {
|
||||
this.element.innerHTML = `<div class="emojis" style="height: auto;">
|
||||
this.element.innerHTML = `<div class="emojis">
|
||||
<div class="emojis__panel">${filterEmoji(value, 256, true)}</div>
|
||||
<div class="fn__flex${value ? " fn__none" : ""}">
|
||||
<div data-type="0" class="emojis__type" aria-label="${window.siyuan.languages.recentEmoji}">${unicode2Emoji("2b50", true)}</div>
|
||||
|
@ -365,6 +370,7 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
|
|||
if (!nodeElement) {
|
||||
return;
|
||||
}
|
||||
this.enableExtend = false
|
||||
let id = "";
|
||||
if (nodeElement) {
|
||||
id = nodeElement.getAttribute("data-node-id");
|
||||
|
@ -466,6 +472,7 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
|
|||
blockRender(protyle, protyle.wysiwyg.element);
|
||||
return;
|
||||
} else if (this.splitChar === "/" || this.splitChar === "、") {
|
||||
this.enableExtend = true;
|
||||
if (value === "((" || value === "{{") {
|
||||
if (value === "((") {
|
||||
hintRef("", protyle);
|
||||
|
@ -533,7 +540,6 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
|
|||
range.deleteContents();
|
||||
range.insertNode(document.createTextNode(":"));
|
||||
range.collapse(false);
|
||||
this.enableEmoji = true;
|
||||
this.genEmojiHTML(protyle);
|
||||
return;
|
||||
} else if (value.indexOf("style") > -1) {
|
||||
|
@ -774,11 +780,10 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
|
|||
return undefined;
|
||||
}
|
||||
// 冒号前为数字或冒号不进行emoji提示
|
||||
if (this.splitChar === ":" && (
|
||||
/\d/.test(currentLineValue.substr(this.lastIndex - 1, 1)) ||
|
||||
currentLineValue.substr(this.lastIndex - 1, 2) === "::"
|
||||
)) {
|
||||
this.enableEmoji = false;
|
||||
if (this.splitChar === ":") {
|
||||
this.enableEmoji = !(/\d/.test(currentLineValue.substr(this.lastIndex - 1, 1)) ||
|
||||
currentLineValue.substr(this.lastIndex - 1, 2) === "::");
|
||||
|
||||
}
|
||||
const lineArray = currentLineValue.split(this.splitChar);
|
||||
const lastItem = lineArray[lineArray.length - 1];
|
||||
|
|
|
@ -1415,8 +1415,8 @@ export class WYSIWYG {
|
|||
input(protyle, blockElement, range, true); // 搜狗拼音数字后面句号变为点;Mac 反向双引号无法输入
|
||||
});
|
||||
} else {
|
||||
if (event.data === ":") {
|
||||
protyle.hint.enableEmoji = true;
|
||||
if ([":", "(", "【", "(", "[", "{", "「", "#", "/", "、"].includes(event.data)) {
|
||||
protyle.hint.enableExtend = true;
|
||||
}
|
||||
input(protyle, blockElement, range, true);
|
||||
}
|
||||
|
@ -1906,7 +1906,7 @@ export class WYSIWYG {
|
|||
pushBack(protyle, newRange);
|
||||
/// #endif
|
||||
}, (isMobile() || window.webkit?.messageHandlers) ? 520 : 0); // Android/iPad 双击慢了出不来
|
||||
protyle.hint.enableEmoji = false;
|
||||
protyle.hint.enableExtend = false;
|
||||
if (window.siyuan.shiftIsPressed) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
|
|
@ -576,7 +576,6 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
|
||||
// 上下左右光标移动
|
||||
if (!event.altKey && !event.shiftKey && !isCtrl(event) && !event.isComposing && (event.key.indexOf("Arrow") > -1)) {
|
||||
protyle.hint.enableEmoji = false;
|
||||
// 需使用 editabled,否则代码块会把语言字数算入
|
||||
const nodeEditableElement = getContenteditableElement(nodeElement) || nodeElement;
|
||||
const position = getSelectionOffset(nodeEditableElement, protyle.wysiwyg.element, range);
|
||||
|
@ -1156,7 +1155,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
|||
!protyle.hint.element.classList.contains("fn__none") ||
|
||||
!protyle.toolbar.subElement.classList.contains("fn__none")) {
|
||||
hideElements(["toolbar", "hint", "util"], protyle);
|
||||
protyle.hint.enableEmoji = false;
|
||||
protyle.hint.enableExtend = false;
|
||||
} else if (nodeElement.classList.contains("protyle-wysiwyg--select")) {
|
||||
hideElements(["select"], protyle);
|
||||
countBlockWord([], protyle.block.rootID);
|
||||
|
|
Loading…
Add table
Reference in a new issue