Vanessa 2023-04-17 17:51:45 +08:00
parent 648d00e587
commit c8177c262e
4 changed files with 12 additions and 8 deletions

View file

@ -290,7 +290,7 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
export const contentMenu = (protyle: IProtyle, nodeElement: Element) => { export const contentMenu = (protyle: IProtyle, nodeElement: Element) => {
const range = getEditorRange(nodeElement); const range = getEditorRange(nodeElement);
window.siyuan.menus.menu.remove(); window.siyuan.menus.menu.remove();
if (range.toString() !== "" || (range.cloneContents().childNodes[0] as HTMLElement)?.classList.contains("emoji")) { if (range.toString() !== "" || (range.cloneContents().childNodes[0] as HTMLElement)?.classList?.contains("emoji")) {
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
icon: "iconCopy", icon: "iconCopy",
accelerator: "⌘C", accelerator: "⌘C",

View file

@ -15,14 +15,14 @@ export const openByMobile = (uri: string) => {
} }
}; };
export const readText = async () => { export const readText = () => {
if ("android" === window.siyuan.config.system.container && window.JSAndroid) { if ("android" === window.siyuan.config.system.container && window.JSAndroid) {
return window.JSAndroid.readClipboard(); return window.JSAndroid.readClipboard();
} }
return navigator.clipboard.readText(); return navigator.clipboard.readText();
}; };
export const writeText = async (text: string) => { export const writeText = (text: string) => {
let range: Range; let range: Range;
if (getSelection().rangeCount > 0) { if (getSelection().rangeCount > 0) {
range = getSelection().getRangeAt(0).cloneRange(); range = getSelection().getRangeAt(0).cloneRange();
@ -37,7 +37,6 @@ export const writeText = async (text: string) => {
window.webkit.messageHandlers.setClipboard.postMessage(text); window.webkit.messageHandlers.setClipboard.postMessage(text);
return; return;
} }
navigator.clipboard.writeText(text); navigator.clipboard.writeText(text);
} catch (e) { } catch (e) {
if (window.siyuan.config.system.container === "ios" && window.webkit?.messageHandlers) { if (window.siyuan.config.system.container === "ios" && window.webkit?.messageHandlers) {

View file

@ -32,8 +32,8 @@ const filterClipboardHint = (protyle: IProtyle, textPlain: string) => {
}; };
export const pasteAsPlainText = async (protyle: IProtyle) => { export const pasteAsPlainText = async (protyle: IProtyle) => {
/// #if !BROWSER
let localFiles: string[] = []; let localFiles: string[] = [];
/// #if !BROWSER
if ("darwin" === window.siyuan.config.system.os) { if ("darwin" === window.siyuan.config.system.os) {
const xmlString = clipboard.read("NSFilenamesPboardType"); const xmlString = clipboard.read("NSFilenamesPboardType");
const domParser = new DOMParser(); const domParser = new DOMParser();
@ -50,10 +50,15 @@ export const pasteAsPlainText = async (protyle: IProtyle) => {
if (localFiles.length > 0) { if (localFiles.length > 0) {
uploadLocalFiles(localFiles, protyle, false); uploadLocalFiles(localFiles, protyle, false);
writeText(""); writeText("");
} else {
getCurrentWindow().webContents.pasteAndMatchStyle();
} }
/// #endif /// #endif
if (localFiles.length === 0) {
getCurrentWindow().webContents.pasteAndMatchStyle();
// 下个版本再进行修改 https://github.com/siyuan-note/siyuan/issues/8010
// navigator.clipboard.readText().then(async textPlain => {
// insertHTML(protyle.lute.BlockDOM2Content(protyle.lute.Md2BlockDOM(textPlain)), protyle);
// });
}
}; };
export const pasteText = (protyle: IProtyle, textPlain: string, nodeElement: Element) => { export const pasteText = (protyle: IProtyle, textPlain: string, nodeElement: Element) => {

View file

@ -1646,7 +1646,6 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
} }
/// #endif /// #endif
/// #if !BROWSER
if (matchHotKey("⇧⌘V", event)) { if (matchHotKey("⇧⌘V", event)) {
event.returnValue = false; event.returnValue = false;
event.preventDefault(); event.preventDefault();
@ -1655,6 +1654,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
return; return;
} }
/// #if !BROWSER
if (matchHotKey(window.siyuan.config.keymap.editor.general.showInFolder.custom, event)) { if (matchHotKey(window.siyuan.config.keymap.editor.general.showInFolder.custom, event)) {
const aElement = hasClosestByAttribute(range.startContainer, "data-type", "a"); const aElement = hasClosestByAttribute(range.startContainer, "data-type", "a");
if (aElement) { if (aElement) {