mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 08:30:12 +01:00
This commit is contained in:
parent
563e2d03ba
commit
be4611bf31
6 changed files with 43 additions and 42 deletions
|
|
@ -23,7 +23,7 @@ import {writeText} from "../protyle/util/compatibility";
|
||||||
import {preventScroll} from "../protyle/scroll/preventScroll";
|
import {preventScroll} from "../protyle/scroll/preventScroll";
|
||||||
import {onGet} from "../protyle/util/onGet";
|
import {onGet} from "../protyle/util/onGet";
|
||||||
import {getAllModels} from "../layout/getAll";
|
import {getAllModels} from "../layout/getAll";
|
||||||
import {pasteText} from "../protyle/util/paste";
|
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
|
||||||
|
|
@ -338,16 +338,13 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER && !MOBILE
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
label: window.siyuan.languages.pasteAsPlainText,
|
label: window.siyuan.languages.pasteAsPlainText,
|
||||||
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));
|
||||||
writeText(clipboard.readText());
|
pasteAsPlainText(protyle)
|
||||||
setTimeout(() => {
|
|
||||||
getCurrentWindow().webContents.pasteAndMatchStyle();
|
|
||||||
}, 100);
|
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
/// #endif
|
/// #endif
|
||||||
|
|
|
||||||
|
|
@ -871,7 +871,7 @@ export class Toolbar {
|
||||||
} else {
|
} else {
|
||||||
renderElement.setAttribute("data-inline-memo-content", Lute.EscapeHTMLStr(target.value));
|
renderElement.setAttribute("data-inline-memo-content", Lute.EscapeHTMLStr(target.value));
|
||||||
}
|
}
|
||||||
}else if (type === "NodeBlockQueryEmbed") {
|
} else if (type === "NodeBlockQueryEmbed") {
|
||||||
blockRender(protyle, renderElement);
|
blockRender(protyle, renderElement);
|
||||||
}
|
}
|
||||||
if (this.range) {
|
if (this.range) {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import {focusBlock, getEditorRange, focusByWbr} from "./selection";
|
||||||
import {mathRender} from "../markdown/mathRender";
|
import {mathRender} from "../markdown/mathRender";
|
||||||
import {Constants} from "../../constants";
|
import {Constants} from "../../constants";
|
||||||
|
|
||||||
export const insertHTML = (html: string, protyle: IProtyle, isBlock = false) => {
|
export const insertHTML = (html: string, protyle: IProtyle, isBlock = false, splitSpan = true) => {
|
||||||
if (html === "") {
|
if (html === "") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -89,7 +89,7 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false) =>
|
||||||
}
|
}
|
||||||
// 粘贴带样式的行内元素到另一个行内元素中需进行切割
|
// 粘贴带样式的行内元素到另一个行内元素中需进行切割
|
||||||
const spanElement = range.startContainer.nodeType === 3 ? range.startContainer.parentElement: range.startContainer as HTMLElement;
|
const spanElement = range.startContainer.nodeType === 3 ? range.startContainer.parentElement: range.startContainer as HTMLElement;
|
||||||
if (spanElement.tagName === "SPAN" && spanElement.isSameNode( range.endContainer.nodeType === 3 ? range.endContainer.parentElement: range.endContainer)) {
|
if (splitSpan && spanElement.tagName === "SPAN" && spanElement.isSameNode( range.endContainer.nodeType === 3 ? range.endContainer.parentElement: range.endContainer)) {
|
||||||
const afterElement = document.createElement("span");
|
const afterElement = document.createElement("span");
|
||||||
const attributes = spanElement.attributes;
|
const attributes = spanElement.attributes;
|
||||||
for (let i = 0; i < attributes.length; i++) {
|
for (let i = 0; i < attributes.length; i++) {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import {processPasteCode, processRender} from "./processCode";
|
||||||
import {writeText} from "./compatibility";
|
import {writeText} from "./compatibility";
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
import {clipboard} from "electron";
|
import {clipboard} from "electron";
|
||||||
|
import * as path from "path";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {hasClosestBlock} from "./hasClosest";
|
import {hasClosestBlock} from "./hasClosest";
|
||||||
import {focusByWbr, getEditorRange} from "./selection";
|
import {focusByWbr, getEditorRange} from "./selection";
|
||||||
|
|
@ -30,6 +31,34 @@ const filterClipboardHint = (protyle: IProtyle, textPlain: string) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const pasteAsPlainText = async (protyle:IProtyle) => {
|
||||||
|
/// #if !BROWSER && !MOBILE
|
||||||
|
let localFiles: string[] = [];
|
||||||
|
if ("darwin" === window.siyuan.config.system.os) {
|
||||||
|
const xmlString = clipboard.read("NSFilenamesPboardType");
|
||||||
|
const domParser = new DOMParser();
|
||||||
|
const xmlDom = domParser.parseFromString(xmlString, "application/xml");
|
||||||
|
Array.from(xmlDom.getElementsByTagName("string")).forEach(item => {
|
||||||
|
localFiles.push(item.childNodes[0].nodeValue);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const xmlString = await fetchSyncPost("/api/clipboard/readFilePaths", {});
|
||||||
|
if (xmlString.data.length > 0) {
|
||||||
|
localFiles = xmlString.data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (localFiles.length > 0) {
|
||||||
|
let fileText = "";
|
||||||
|
localFiles.forEach((item) => {
|
||||||
|
fileText += `[${path.basename(item).replace(/\]/g, "\\]").replace(/\[/g, "\\[")}](file://${item.replace(/\\/g, "\\\\").replace(/\)/g, "\\)").replace(/\(/g, "\\(")})\n`;
|
||||||
|
});
|
||||||
|
insertHTML(protyle.lute.SpinBlockDOM(fileText), protyle);
|
||||||
|
} else {
|
||||||
|
insertHTML(protyle.lute.BlockDOM2Content(protyle.lute.InlineMd2BlockDOM(clipboard.readText())), protyle, false, false);
|
||||||
|
}
|
||||||
|
/// #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);
|
||||||
const id = nodeElement.getAttribute("data-node-id");
|
const id = nodeElement.getAttribute("data-node-id");
|
||||||
|
|
|
||||||
|
|
@ -41,11 +41,6 @@ import {listIndent, listOutdent, updateListOrder} from "./list";
|
||||||
import {newFileBySelect, newFileContentBySelect, rename, replaceFileName} from "../../editor/rename";
|
import {newFileBySelect, newFileContentBySelect, rename, replaceFileName} from "../../editor/rename";
|
||||||
import {insertEmptyBlock, jumpToParentNext} from "../../block/util";
|
import {insertEmptyBlock, jumpToParentNext} from "../../block/util";
|
||||||
import {isLocalPath} from "../../util/pathName";
|
import {isLocalPath} from "../../util/pathName";
|
||||||
/// #if !BROWSER
|
|
||||||
import {clipboard} from "electron";
|
|
||||||
import {getCurrentWindow} from "@electron/remote";
|
|
||||||
import * as path from "path";
|
|
||||||
/// #endif
|
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
import {openBy, openFileById} from "../../editor/util";
|
import {openBy, openFileById} from "../../editor/util";
|
||||||
import {commonHotkey} from "./commonHotkey";
|
import {commonHotkey} from "./commonHotkey";
|
||||||
|
|
@ -56,7 +51,7 @@ import {openAttr} from "../../menus/commonMenuItem";
|
||||||
import {Constants} from "../../constants";
|
import {Constants} from "../../constants";
|
||||||
import {preventScroll} from "../scroll/preventScroll";
|
import {preventScroll} from "../scroll/preventScroll";
|
||||||
import {bindMenuKeydown} from "../../menus/Menu";
|
import {bindMenuKeydown} from "../../menus/Menu";
|
||||||
import {fetchPost, fetchSyncPost} from "../../util/fetch";
|
import {fetchPost} from "../../util/fetch";
|
||||||
import {onGet} from "../util/onGet";
|
import {onGet} from "../util/onGet";
|
||||||
import {scrollCenter} from "../../util/highlightById";
|
import {scrollCenter} from "../../util/highlightById";
|
||||||
import {BlockPanel} from "../../block/Panel";
|
import {BlockPanel} from "../../block/Panel";
|
||||||
|
|
@ -65,9 +60,10 @@ import {highlightRender} from "../markdown/highlightRender";
|
||||||
import {countBlockWord} from "../../layout/status";
|
import {countBlockWord} from "../../layout/status";
|
||||||
import {insertHTML} from "../util/insertHTML";
|
import {insertHTML} from "../util/insertHTML";
|
||||||
import {openMobileFileById} from "../../mobile/editor";
|
import {openMobileFileById} from "../../mobile/editor";
|
||||||
|
import {pasteAsPlainText} from "../util/paste";
|
||||||
|
|
||||||
export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
editorElement.addEventListener("keydown", async (event: KeyboardEvent & { target: HTMLElement }) => {
|
editorElement.addEventListener("keydown", (event: KeyboardEvent & { target: HTMLElement }) => {
|
||||||
if (event.target.localName === "protyle-html") {
|
if (event.target.localName === "protyle-html") {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
return;
|
return;
|
||||||
|
|
@ -1667,32 +1663,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
event.returnValue = false;
|
event.returnValue = false;
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
let localFiles: string[] = [];
|
pasteAsPlainText(protyle);
|
||||||
if ("darwin" === window.siyuan.config.system.os) {
|
|
||||||
const xmlString = clipboard.read("NSFilenamesPboardType");
|
|
||||||
const domParser = new DOMParser();
|
|
||||||
const xmlDom = domParser.parseFromString(xmlString, "application/xml");
|
|
||||||
Array.from(xmlDom.getElementsByTagName("string")).forEach(item => {
|
|
||||||
localFiles.push(item.childNodes[0].nodeValue);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
const xmlString = await fetchSyncPost("/api/clipboard/readFilePaths", {});
|
|
||||||
if (xmlString.data.length > 0) {
|
|
||||||
localFiles = xmlString.data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (localFiles.length > 0) {
|
|
||||||
let fileText = "";
|
|
||||||
localFiles.forEach((item) => {
|
|
||||||
fileText += `[${path.basename(item).replace(/\]/g, "\\]").replace(/\[/g, "\\[")}](file://${item.replace(/\\/g, "\\\\").replace(/\)/g, "\\)").replace(/\(/g, "\\(")})\n`;
|
|
||||||
});
|
|
||||||
insertHTML(protyle.lute.SpinBlockDOM(fileText), protyle);
|
|
||||||
} else {
|
|
||||||
writeText(clipboard.readText());
|
|
||||||
setTimeout(() => {
|
|
||||||
getCurrentWindow().webContents.pasteAndMatchStyle();
|
|
||||||
}, 100);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
4
app/src/types/protyle.d.ts
vendored
4
app/src/types/protyle.d.ts
vendored
|
|
@ -137,6 +137,10 @@ declare class Lute {
|
||||||
|
|
||||||
private constructor();
|
private constructor();
|
||||||
|
|
||||||
|
public BlockDOM2Content(text: string): string;
|
||||||
|
|
||||||
|
public InlineMd2BlockDOM(text: string): string;
|
||||||
|
|
||||||
public SetTextMark(enable: boolean): void;
|
public SetTextMark(enable: boolean): void;
|
||||||
|
|
||||||
public SetHeadingID(enable: boolean): void;
|
public SetHeadingID(enable: boolean): void;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue