From 3673a01ac5f9830230786757f3166c4edf3f4122 Mon Sep 17 00:00:00 2001 From: Menghuan1918 Date: Sat, 7 Dec 2024 21:07:50 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=90=9B=20Fix=20Linux=20key=20paste=20?= =?UTF-8?q?issue=20in=20tab?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/layout/Wnd.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.ts index 8f451af8e8f..081ea99c424 100644 --- a/app/src/layout/Wnd.ts +++ b/app/src/layout/Wnd.ts @@ -101,6 +101,10 @@ export class Wnd { window.siyuan.menus.menu.remove(); event.stopPropagation(); event.preventDefault(); + // 阻止 Linux 中键粘贴 + setTimeout(() => { + window.getSelection().removeAllRanges(); + }); break; } target = target.parentElement; From 47ecf6ab8651aeb4d775cbc633eb029f05e5cf55 Mon Sep 17 00:00:00 2001 From: Menghuan1918 Date: Sat, 7 Dec 2024 21:30:56 +0800 Subject: [PATCH 2/4] Better way to fix Linux key paste issue in tab --- app/src/layout/Wnd.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.ts index 081ea99c424..f2edb6cc0e4 100644 --- a/app/src/layout/Wnd.ts +++ b/app/src/layout/Wnd.ts @@ -102,14 +102,22 @@ export class Wnd { event.stopPropagation(); event.preventDefault(); // 阻止 Linux 中键粘贴 - setTimeout(() => { - window.getSelection().removeAllRanges(); + const activeElement = document.activeElement; + window.addEventListener("paste", (e) => { + e.preventDefault(); + e.stopPropagation(); + }, { + capture: true, + once: true }); + // 保持原有焦点 + if (activeElement instanceof HTMLElement) { + activeElement.focus(); + } break; } target = target.parentElement; } - }); this.headersElement.addEventListener("mousewheel", (event: WheelEvent) => { this.headersElement.scrollLeft = this.headersElement.scrollLeft + event.deltaY; From 4b89022d0cb018aee49aec2bb2d2f769d19e9646 Mon Sep 17 00:00:00 2001 From: Menghuan1918 Date: Sun, 8 Dec 2024 11:25:08 +0800 Subject: [PATCH 3/4] Only work on linux --- app/src/layout/Wnd.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.ts index f2edb6cc0e4..f8d0e60ede2 100644 --- a/app/src/layout/Wnd.ts +++ b/app/src/layout/Wnd.ts @@ -102,17 +102,19 @@ export class Wnd { event.stopPropagation(); event.preventDefault(); // 阻止 Linux 中键粘贴 - const activeElement = document.activeElement; - window.addEventListener("paste", (e) => { - e.preventDefault(); - e.stopPropagation(); - }, { - capture: true, - once: true - }); - // 保持原有焦点 - if (activeElement instanceof HTMLElement) { - activeElement.focus(); + if ("linux" === window.siyuan.config.system.os) { + const activeElement = document.activeElement; + window.addEventListener("paste", (e) => { + e.preventDefault(); + e.stopPropagation(); + }, { + capture: true, + once: true + }); + // 保持原有焦点 + if (activeElement instanceof HTMLElement) { + activeElement.focus(); + } } break; } From b87f3b9342845f574377f3122067a23e7c6741e2 Mon Sep 17 00:00:00 2001 From: Menghuan1918 Date: Mon, 9 Dec 2024 22:52:34 +0800 Subject: [PATCH 4/4] Fix Linux key paste issue in tab --- app/src/layout/Wnd.ts | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.ts index f8d0e60ede2..79cf83fc0af 100644 --- a/app/src/layout/Wnd.ts +++ b/app/src/layout/Wnd.ts @@ -101,20 +101,26 @@ export class Wnd { window.siyuan.menus.menu.remove(); event.stopPropagation(); event.preventDefault(); - // 阻止 Linux 中键粘贴 - if ("linux" === window.siyuan.config.system.os) { - const activeElement = document.activeElement; - window.addEventListener("paste", (e) => { - e.preventDefault(); - e.stopPropagation(); - }, { - capture: true, - once: true + const activeElement = document.activeElement; + const pasteHandler = (e: ClipboardEvent) => { + e.preventDefault(); + e.stopPropagation(); + }; + window.addEventListener("paste", pasteHandler, { + capture: true, + once: true + }); + + // 如果在短时间内没有 paste 事件发生,移除监听 + setTimeout(() => { + window.removeEventListener("paste", pasteHandler, { + capture: true }); - // 保持原有焦点 - if (activeElement instanceof HTMLElement) { - activeElement.focus(); - } + }, 250); + + // 保持原有焦点 + if (activeElement instanceof HTMLElement) { + activeElement.focus(); } break; }