mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 15:40:12 +01:00
This commit is contained in:
parent
10690ba3f7
commit
c8a0314d74
3 changed files with 22 additions and 19 deletions
|
|
@ -91,7 +91,7 @@ export class Title {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
});
|
});
|
||||||
this.editElement.addEventListener("keydown", (event: KeyboardEvent) => {
|
this.editElement.addEventListener("keydown", async (event: KeyboardEvent) => {
|
||||||
if (event.isComposing) {
|
if (event.isComposing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -100,7 +100,10 @@ export class Title {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (matchHotKey("⇧⌘V", event)) {
|
if (matchHotKey("⇧⌘V", event)) {
|
||||||
navigator.clipboard.readText().then(textPlain => {
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
let textPlain = await readText() || "";
|
||||||
|
if (textPlain) {
|
||||||
// 对 HTML 标签进行内部转义,避免被 Lute 解析以后变为小写 https://github.com/siyuan-note/siyuan/issues/10620
|
// 对 HTML 标签进行内部转义,避免被 Lute 解析以后变为小写 https://github.com/siyuan-note/siyuan/issues/10620
|
||||||
textPlain = textPlain.replace(/</g, ";;;lt;;;").replace(/>/g, ";;;gt;;;");
|
textPlain = textPlain.replace(/</g, ";;;lt;;;").replace(/>/g, ";;;gt;;;");
|
||||||
enableLuteMarkdownSyntax(protyle);
|
enableLuteMarkdownSyntax(protyle);
|
||||||
|
|
@ -110,9 +113,8 @@ export class Title {
|
||||||
content = content.replace(/;;;lt;;;[^;]+;;;gt;;;/g, "");
|
content = content.replace(/;;;lt;;;[^;]+;;;gt;;;/g, "");
|
||||||
document.execCommand("insertText", false, replaceFileName(content));
|
document.execCommand("insertText", false, replaceFileName(content));
|
||||||
this.rename(protyle);
|
this.rename(protyle);
|
||||||
});
|
}
|
||||||
event.preventDefault();
|
return;
|
||||||
event.stopPropagation();
|
|
||||||
}
|
}
|
||||||
if (matchHotKey(window.siyuan.config.keymap.general.enterBack.custom, event)) {
|
if (matchHotKey(window.siyuan.config.keymap.general.enterBack.custom, event)) {
|
||||||
const ids = protyle.path.split("/");
|
const ids = protyle.path.split("/");
|
||||||
|
|
@ -255,7 +257,7 @@ export class Title {
|
||||||
document.execCommand("paste");
|
document.execCommand("paste");
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
const text = await readText();
|
const text = await readText() || "";
|
||||||
document.execCommand("insertText", false, replaceFileName(text));
|
document.execCommand("insertText", false, replaceFileName(text));
|
||||||
this.rename(protyle);
|
this.rename(protyle);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
@ -269,7 +271,7 @@ export class Title {
|
||||||
label: window.siyuan.languages.pasteAsPlainText,
|
label: window.siyuan.languages.pasteAsPlainText,
|
||||||
accelerator: "⇧⌘V",
|
accelerator: "⇧⌘V",
|
||||||
click: async () => {
|
click: async () => {
|
||||||
navigator.clipboard.readText().then(textPlain => {
|
let textPlain = await readText() || "";
|
||||||
textPlain = textPlain.replace(/</g, ";;;lt;;;").replace(/>/g, ";;;gt;;;");
|
textPlain = textPlain.replace(/</g, ";;;lt;;;").replace(/>/g, ";;;gt;;;");
|
||||||
enableLuteMarkdownSyntax(protyle);
|
enableLuteMarkdownSyntax(protyle);
|
||||||
let content = protyle.lute.BlockDOM2EscapeMarkerContent(protyle.lute.Md2BlockDOM(textPlain));
|
let content = protyle.lute.BlockDOM2EscapeMarkerContent(protyle.lute.Md2BlockDOM(textPlain));
|
||||||
|
|
@ -278,7 +280,6 @@ export class Title {
|
||||||
content = content.replace(/;;;lt;;;[^;]+;;;gt;;;/g, "");
|
content = content.replace(/;;;lt;;;[^;]+;;;gt;;;/g, "");
|
||||||
document.execCommand("insertText", false, replaceFileName(content));
|
document.execCommand("insertText", false, replaceFileName(content));
|
||||||
this.rename(protyle);
|
this.rename(protyle);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,9 @@ export const readText = () => {
|
||||||
} else if (isInHarmony()) {
|
} else if (isInHarmony()) {
|
||||||
return window.JSHarmony.readClipboard();
|
return window.JSHarmony.readClipboard();
|
||||||
}
|
}
|
||||||
return navigator.clipboard.readText();
|
return navigator.clipboard.readText().catch((err) => {
|
||||||
|
alert(err);
|
||||||
|
}) || "";
|
||||||
};
|
};
|
||||||
|
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ export const getPlainText = (blockElement: HTMLElement, isNested = false) => {
|
||||||
|
|
||||||
export const pasteEscaped = async (protyle: IProtyle, nodeElement: Element) => {
|
export const pasteEscaped = async (protyle: IProtyle, nodeElement: Element) => {
|
||||||
try {
|
try {
|
||||||
let clipText = await readText();
|
let clipText = await readText() || "";
|
||||||
// 删掉 <span data-type\="text".*>text</span> 标签,只保留文本
|
// 删掉 <span data-type\="text".*>text</span> 标签,只保留文本
|
||||||
clipText = clipText.replace(/<span data-type="text".*?>(.*?)<\/span>/g, "$1");
|
clipText = clipText.replace(/<span data-type="text".*?>(.*?)<\/span>/g, "$1");
|
||||||
|
|
||||||
|
|
@ -150,7 +150,7 @@ export const pasteAsPlainText = async (protyle: IProtyle) => {
|
||||||
/// #endif
|
/// #endif
|
||||||
if (localFiles.length === 0) {
|
if (localFiles.length === 0) {
|
||||||
// Inline-level elements support pasted as plain text https://github.com/siyuan-note/siyuan/issues/8010
|
// Inline-level elements support pasted as plain text https://github.com/siyuan-note/siyuan/issues/8010
|
||||||
let textPlain = await readText();
|
let textPlain = await readText() || "";
|
||||||
if (getSelection().rangeCount > 0) {
|
if (getSelection().rangeCount > 0) {
|
||||||
const range = getSelection().getRangeAt(0);
|
const range = getSelection().getRangeAt(0);
|
||||||
if (hasClosestByAttribute(range.startContainer, "data-type", "code") || hasClosestByClassName(range.startContainer, "hljs")) {
|
if (hasClosestByAttribute(range.startContainer, "data-type", "code") || hasClosestByClassName(range.startContainer, "hljs")) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue