Vanessa 2022-09-17 17:55:02 +08:00
parent 9062f36016
commit cd3da736db

View File

@ -104,6 +104,7 @@ export class WYSIWYG {
}); });
} }
// text block-ref file-annotation-ref a 结尾处打字应为普通文本
private escapeInline(protyle: IProtyle, range: Range, event: InputEvent) { private escapeInline(protyle: IProtyle, range: Range, event: InputEvent) {
if (!event.data) { if (!event.data) {
return; return;
@ -111,17 +112,14 @@ export class WYSIWYG {
const inputData = event.data; const inputData = event.data;
protyle.toolbar.range = range; protyle.toolbar.range = range;
const inlineElement = range.startContainer.parentElement; const inlineElement = range.startContainer.parentElement;
let outElement = inlineElement; const currentTypes = protyle.toolbar.getCurrentType()
if (!["DIV", "TD", "TH"].includes(inlineElement.tagName) && !["DIV", "TD", "TH"].includes(inlineElement.parentElement.tagName) && !hasNextSibling(inlineElement)) {
// 表格行内公式之前无法插入文字 https://github.com/siyuan-note/siyuan/issues/3908
// 引用外面加粗体且引用后无文字 https://github.com/siyuan-note/siyuan/issues/3103
outElement = inlineElement.parentElement;
}
if (// 表格行内公式之前无法插入文字 https://github.com/siyuan-note/siyuan/issues/3908 if (// 表格行内公式之前无法插入文字 https://github.com/siyuan-note/siyuan/issues/3908
!["DIV", "TD", "TH"].includes(inlineElement.tagName) && inlineElement.tagName==="SPAN" &&
range.toString() === "" && range.startContainer.nodeType === 3 && protyle.toolbar.getCurrentType().length > 0 && range.toString() === "" && range.startContainer.nodeType === 3 &&
inlineElement.textContent.replace(Constants.ZWSP, "").length >= inputData.length && // 为空的时候需要等于 (currentTypes.includes("text") || currentTypes.includes("block-ref")|| currentTypes.includes("file-annotation-ref")|| currentTypes.includes("a")) &&
!protyle.toolbar.isNewEmptyInline) { !hasNextSibling(range.startContainer) && range.startContainer.textContent.length === range.startOffset &&
inlineElement.textContent.replace(Constants.ZWSP, "").length >= inputData.length // 为空的时候需要等于
) {
const position = getSelectionOffset(inlineElement, protyle.wysiwyg.element, range); const position = getSelectionOffset(inlineElement, protyle.wysiwyg.element, range);
let dataLength = inputData.length; let dataLength = inputData.length;
if (inputData === "<" || inputData === ">") { if (inputData === "<" || inputData === ">") {
@ -134,13 +132,13 @@ export class WYSIWYG {
// 使用 inlineElement.textContent **$a$b** 中数学公式消失 // 使用 inlineElement.textContent **$a$b** 中数学公式消失
inlineElement.innerHTML = html.substr(0, html.length - dataLength); inlineElement.innerHTML = html.substr(0, html.length - dataLength);
const textNode = document.createTextNode(inputData); const textNode = document.createTextNode(inputData);
outElement.after(textNode); inlineElement.after(textNode);
range.selectNodeContents(textNode); range.selectNodeContents(textNode);
range.collapse(false); range.collapse(false);
} else if (position.start === inputData.length) { } else if (position.start === inputData.length) {
inlineElement.innerHTML = html.substr(dataLength); inlineElement.innerHTML = html.substr(dataLength);
const textNode = document.createTextNode(inputData); const textNode = document.createTextNode(inputData);
outElement.before(textNode); inlineElement.before(textNode);
range.selectNodeContents(textNode); range.selectNodeContents(textNode);
range.collapse(false); range.collapse(false);
} }
@ -1753,7 +1751,6 @@ export class WYSIWYG {
/// #endif /// #endif
}, isMobile() ? 520 : 0); // Android 双击慢了出不来 }, isMobile() ? 520 : 0); // Android 双击慢了出不来
protyle.toolbar.isNewEmptyInline = false;
protyle.hint.enableEmoji = false; protyle.hint.enableEmoji = false;
if (window.siyuan.shiftIsPressed) { if (window.siyuan.shiftIsPressed) {
event.preventDefault(); event.preventDefault();