This commit is contained in:
Vanessa 2022-09-19 15:33:30 +08:00
parent 74a9ef4b51
commit 1fedca6929
4 changed files with 18 additions and 21 deletions

View file

@ -27,10 +27,6 @@ import {pasteAsPlainText, pasteText} from "../protyle/util/paste";
/// #if !MOBILE
import {openFileById, updateBacklinkGraph} from "../editor/util";
/// #endif
/// #if !BROWSER
import {getCurrentWindow} from "@electron/remote";
import {clipboard} from "electron";
/// #endif
import {isMobile} from "../util/functions";
import {removeFoldHeading} from "../protyle/util/heading";
import {lineNumberRender} from "../protyle/markdown/highlightRender";
@ -344,7 +340,7 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => {
accelerator: window.siyuan.config.keymap.editor.general.pasteAsPlainText.custom,
click() {
focusByRange(getEditorRange(nodeElement));
pasteAsPlainText(protyle)
pasteAsPlainText(protyle);
}
}).element);
/// #endif

View file

@ -427,23 +427,23 @@ export class Toolbar {
if (type === "sub" && types.includes("sup")) {
types.find((item, index) => {
if (item === "sup") {
types.splice(index, 1)
types.splice(index, 1);
if (!this.element.classList.contains("fn__none")) {
this.element.querySelector(`[data-type="sup"]`).classList.remove("protyle-toolbar__item--current");
this.element.querySelector("[data-type=\"sup\"]").classList.remove("protyle-toolbar__item--current");
}
return true;
}
})
});
} else if (type === "sup" && types.includes("sub")) {
types.find((item, index) => {
if (item === "sub") {
types.splice(index, 1);
if (!this.element.classList.contains("fn__none")) {
this.element.querySelector(`[data-type="sub"]`).classList.remove("protyle-toolbar__item--current");
this.element.querySelector("[data-type=\"sub\"]").classList.remove("protyle-toolbar__item--current");
}
return true;
}
})
});
}
types = [...new Set(types)];
if (index === 0 && previousElement && previousElement.nodeType !== 3 &&
@ -635,7 +635,7 @@ export class Toolbar {
let html = protyle.lute.SpinBlockDOM(nodeElement.outerHTML);
let title = "HTML";
let placeholder = "";
const isInlineMemo = type && type.split(" ").includes("inline-memo")
const isInlineMemo = type && type.split(" ").includes("inline-memo");
switch (renderElement.getAttribute("data-subtype")) {
case "abc":
title = window.siyuan.languages.staff;
@ -888,11 +888,11 @@ export class Toolbar {
if (!target.value) {
// https://github.com/siyuan-note/insider/issues/1046
if (type.replace("inline-memo", "") === "") {
renderElement.outerHTML = renderElement.innerHTML + "<wbr>"
renderElement.outerHTML = renderElement.innerHTML + "<wbr>";
focusByWbr(nodeElement, this.range);
} else {
renderElement.setAttribute("data-type", type.replace("inline-memo", ""))
renderElement.removeAttribute("data-inline-memo-content")
renderElement.setAttribute("data-type", type.replace("inline-memo", ""));
renderElement.removeAttribute("data-inline-memo-content");
}
} else {
renderElement.setAttribute("data-inline-memo-content", Lute.EscapeHTMLStr(target.value));
@ -935,10 +935,12 @@ export class Toolbar {
this.subElement.classList.add("fn__none");
this.subElement.querySelector('[data-type="pin"]').classList.remove("block__icon--active");
if (renderElement.tagName === "SPAN") {
const range = getEditorRange(renderElement);
range.setStartAfter(renderElement);
range.collapse(true);
focusByRange(range);
if (type === "inline-memo" && !textElement.value) {
renderElement.outerHTML = renderElement.innerHTML + "<wbr>";
focusByWbr(nodeElement, this.range);
} else {
focusByRange(this.range);
}
} else {
focusSideBlock(renderElement);
}

View file

@ -57,7 +57,7 @@ export const pasteAsPlainText = async (protyle:IProtyle) => {
insertHTML(protyle.lute.BlockDOM2Content(protyle.lute.InlineMd2BlockDOM(clipboard.readText())), protyle, false, false);
}
/// #endif
}
};
export const pasteText = (protyle: IProtyle, textPlain: string, nodeElement: Element) => {
const range = getEditorRange(protyle.wysiwyg.element);

View file

@ -58,7 +58,6 @@ import {BlockPanel} from "../../block/Panel";
import * as dayjs from "dayjs";
import {highlightRender} from "../markdown/highlightRender";
import {countBlockWord} from "../../layout/status";
import {insertHTML} from "../util/insertHTML";
import {openMobileFileById} from "../../mobile/editor";
import {pasteAsPlainText} from "../util/paste";
@ -296,7 +295,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
if (start !== 0) {
const editElement = getContenteditableElement(nodeElement);
if (editElement.tagName === "TABLE") {
const cellElement = hasClosestByMatchTag(range.startContainer, "TH") || hasClosestByMatchTag(range.startContainer, "TD") || editElement.querySelector("th, td")
const cellElement = hasClosestByMatchTag(range.startContainer, "TH") || hasClosestByMatchTag(range.startContainer, "TD") || editElement.querySelector("th, td");
if (getSelectionOffset(cellElement, cellElement, range).start !== 0) {
setFirstNodeRange(cellElement, range);
event.stopPropagation();