Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/12989

Vanessaab147598e130
diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.ts
index a9977db8ae..e4fc1a9a3b 100644
--- a/app/src/boot/globalEvent/keydown.ts
+++ b/app/src/boot/globalEvent/keydown.ts
@@ -1404,17 +1404,17 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {
return;
}
+ // 闪卡长按 Esc 光标定位到闪卡按钮上 https://github.com/siyuan-note/siyuan/issues/12989
+ if (document.activeElement && hasClosestByClassName(document.activeElement, "card__action")) {
+ return;
+ }
// 光标在文档树等面板中,按 Esc 回到编辑器中 https://github.com/siyuan-note/siyuan/issues/4289
- let range;
if (getSelection().rangeCount > 0) {
- range = getSelection().getRangeAt(0);
- const protypleElement = hasClosestByClassName(range.startContainer, "protyle-content", true);
- if (protypleElement) {
+ const range = getSelection().getRangeAt(0);
+ if (hasClosestByClassName(range.startContainer, "protyle-content", true)) {
focusByRange(range);
return;
}
- } else {
- range = document.createRange();
}
const lastBackStack = window.siyuan.backStack[window.siyuan.backStack.length - 1];
if (lastBackStack && lastBackStack.protyle.toolbar.range) {
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index 3740c1b638..e28357db1a 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -14,6 +14,7 @@ import {
import {
hasClosestBlock,
hasClosestByAttribute,
+ hasClosestByClassName,
hasClosestByMatchTag,
hasTopClosestByAttribute,
isInEmbedBlock
@@ -1175,23 +1176,33 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
// esc
if (event.key === "Escape") {
- if (!protyle.toolbar.element.classList.contains("fn__none") ||
- !protyle.hint.element.classList.contains("fn__none") ||
- !protyle.toolbar.subElement.classList.contains("fn__none")) {
- hideElements(["toolbar", "hint", "util"], protyle);
- protyle.hint.enableExtend = false;
- } else if (nodeElement.classList.contains("protyle-wysiwyg--select")) {
- hideElements(["select"], protyle);
- countBlockWord([], protyle.block.rootID);
- } else if (!window.siyuan.menus.menu.element.classList.contains("fn__none")) {
- // 防止 ESC 时选中当前块
- window.siyuan.menus.menu.remove();
+ if (event.repeat) {
+ // https://github.com/siyuan-note/siyuan/issues/12989
+ const cardElement = hasClosestByClassName(range.startContainer, "card__main", true);
+ if (cardElement && document.activeElement && document.activeElement.classList.contains("protyle-wysiwyg")) {
+ (cardElement.querySelector(".card__action button") as HTMLElement).focus()
+ hideElements(["select"], protyle);
+ }
} else {
- hideElements(["select"], protyle);
- range.collapse(false);
- nodeElement.classList.add("protyle-wysiwyg--select");
- countBlockWord([nodeElement.getAttribute("data-node-id")], protyle.block.rootID);
+ if (!protyle.toolbar.element.classList.contains("fn__none") ||
+ !protyle.hint.element.classList.contains("fn__none") ||
+ !protyle.toolbar.subElement.classList.contains("fn__none")) {
+ hideElements(["toolbar", "hint", "util"], protyle);
+ protyle.hint.enableExtend = false;
+ } else if (nodeElement.classList.contains("protyle-wysiwyg--select")) {
+ hideElements(["select"], protyle);
+ countBlockWord([], protyle.block.rootID);
+ } else if (!window.siyuan.menus.menu.element.classList.contains("fn__none")) {
+ // 防止 ESC 时选中当前块
+ window.siyuan.menus.menu.remove();
+ } else {
+ hideElements(["select"], protyle);
+ range.collapse(false);
+ nodeElement.classList.add("protyle-wysiwyg--select");
+ countBlockWord([nodeElement.getAttribute("data-node-id")], protyle.block.rootID);
+ }
}
+ event.stopPropagation();
event.preventDefault();
return;
}