Skip to content

Commit

Permalink
解决Linux中使用中键关闭标签页时会触发粘贴的问题(#13309) (#13395)
Browse files Browse the repository at this point in the history
* 🐛 Fix Linux key paste issue in tab

* Better way to fix Linux key paste issue in tab

* Only work on linux

* Fix Linux key paste issue in tab
  • Loading branch information
Menghuan1918 authored Dec 10, 2024
1 parent b9f3c1c commit 6d66c80
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion app/src/layout/Wnd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,31 @@ export class Wnd {
window.siyuan.menus.menu.remove();
event.stopPropagation();
event.preventDefault();
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
});
}, 250);

// 保持原有焦点
if (activeElement instanceof HTMLElement) {
activeElement.focus();
}
break;
}
target = target.parentElement;
}

});
this.headersElement.addEventListener("mousewheel", (event: WheelEvent) => {
this.headersElement.scrollLeft = this.headersElement.scrollLeft + event.deltaY;
Expand Down

0 comments on commit 6d66c80

Please sign in to comment.