This commit is contained in:
Vanessa 2023-11-16 10:39:42 +08:00
parent 87032626e2
commit 0eb4d04e2d
10 changed files with 78 additions and 16 deletions

View file

@ -6,7 +6,7 @@ import {
updateHotkeyTip,
writeText
} from "../../protyle/util/compatibility";
import {matchHotKey} from "../../protyle/util/hotKey";
import {matchAuxiliaryHotKey, matchHotKey} from "../../protyle/util/hotKey";
import {openSearch} from "../../search/spread";
import {
hasClosestBlock,
@ -1055,8 +1055,10 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {
}
}
// mac 中只能使用 ⌃
if (switchDialog && event.ctrlKey && !event.metaKey && event.key.startsWith("Arrow")) {
if (switchDialog &&
(matchAuxiliaryHotKey(window.siyuan.config.keymap.general.goToEditTabNext.custom, event) ||
matchAuxiliaryHotKey(window.siyuan.config.keymap.general.goToEditTabPrev.custom, event))
&& event.key.startsWith("Arrow")) {
dialogArrow(app, switchDialog.element, event);
return;
}
@ -1068,7 +1070,8 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {
}
const isTabWindow = isWindow();
if (event.ctrlKey && !event.metaKey && event.key === "Tab") {
if (matchHotKey(window.siyuan.config.keymap.general.goToEditTabNext.custom, event) ||
matchHotKey(window.siyuan.config.keymap.general.goToEditTabPrev.custom, event)) {
if (switchDialog && switchDialog.element.parentElement) {
return;
}
@ -1126,7 +1129,7 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {
<div class="switch-doc__path"></div>
</div>`,
});
switchDialog.element.setAttribute("data-key", "⌃⇥");
switchDialog.element.setAttribute("data-key", window.siyuan.config.keymap.general.goToEditTabNext.custom);
// 需移走光标,否则编辑器会继续监听并执行按键操作
switchDialog.element.querySelector("input").focus();
if (isMac()) {

View file

@ -4,21 +4,24 @@ import {openCard} from "../../card/openCard";
import {getDockByType} from "../../layout/tabUtil";
import {getAllTabs} from "../../layout/getAll";
import {App} from "../../index";
import {Constants} from "../../constants";
import {matchHotKey} from "../../protyle/util/hotKey";
export const windowKeyUp = (app: App,event:KeyboardEvent) => {
export const windowKeyUp = (app: App, event: KeyboardEvent) => {
window.siyuan.ctrlIsPressed = false;
window.siyuan.shiftIsPressed = false;
window.siyuan.altIsPressed = false;
const switchDialog = window.siyuan.dialogs.find(item => {
if (item.element.getAttribute("data-key") === "⌃⇥") {
if (item.element.getAttribute("data-key") === window.siyuan.config.keymap.general.goToEditTabNext.custom) {
return true;
}
});
if (switchDialog && switchDialog.element.parentElement) {
if (event.key === "Tab") {
if (window.siyuan.config.keymap.general.goToEditTabNext.custom.endsWith(Constants.KEYCODELIST[event.keyCode]) ||
window.siyuan.config.keymap.general.goToEditTabPrev.custom.endsWith(Constants.KEYCODELIST[event.keyCode])) {
let currentLiElement = switchDialog.element.querySelector(".b3-list-item--focus");
currentLiElement.classList.remove("b3-list-item--focus");
if (event.shiftKey) {
if (matchHotKey(window.siyuan.config.keymap.general.goToEditTabPrev.custom, event)) {
if (currentLiElement.previousElementSibling) {
currentLiElement.previousElementSibling.classList.add("b3-list-item--focus");
} else if (currentLiElement.getAttribute("data-original")) {
@ -73,12 +76,14 @@ export const windowKeyUp = (app: App,event:KeyboardEvent) => {
if (originalElement) {
originalElement.removeAttribute("data-original");
}
} else if (event.key === "Control") {
} else if (window.siyuan.config.keymap.general.goToEditTabNext.custom.startsWith(Constants.KEYCODELIST[event.keyCode]) ||
window.siyuan.config.keymap.general.goToEditTabPrev.custom.startsWith(Constants.KEYCODELIST[event.keyCode])) {
let currentLiElement = switchDialog.element.querySelector(".b3-list-item--focus");
// 快速切换时,不触发 Tab
if (currentLiElement.getAttribute("data-original")) {
currentLiElement.classList.remove("b3-list-item--focus");
if (event.shiftKey) {
if (matchHotKey(window.siyuan.config.keymap.general.goToEditTabPrev.custom, event)) {
// 上一个
if (currentLiElement.previousElementSibling) {
currentLiElement.previousElementSibling.classList.add("b3-list-item--focus");
} else {