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 /// #if !MOBILE
import {openFileById, updateBacklinkGraph} from "../editor/util"; import {openFileById, updateBacklinkGraph} from "../editor/util";
/// #endif /// #endif
/// #if !BROWSER
import {getCurrentWindow} from "@electron/remote";
import {clipboard} from "electron";
/// #endif
import {isMobile} from "../util/functions"; import {isMobile} from "../util/functions";
import {removeFoldHeading} from "../protyle/util/heading"; import {removeFoldHeading} from "../protyle/util/heading";
import {lineNumberRender} from "../protyle/markdown/highlightRender"; 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, accelerator: window.siyuan.config.keymap.editor.general.pasteAsPlainText.custom,
click() { click() {
focusByRange(getEditorRange(nodeElement)); focusByRange(getEditorRange(nodeElement));
pasteAsPlainText(protyle) pasteAsPlainText(protyle);
} }
}).element); }).element);
/// #endif /// #endif

View file

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

View file

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