This commit is contained in:
Vanessa 2022-06-29 09:10:03 +08:00
parent 0b5e7af12e
commit 743b559351
2 changed files with 34 additions and 34 deletions

View file

@ -1123,7 +1123,7 @@ export class WYSIWYG {
} }
const ids: string[] = []; const ids: string[] = [];
const selectElement = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select") const selectElement = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select");
selectElement.forEach(item => { selectElement.forEach(item => {
ids.push(item.getAttribute("data-node-id")); ids.push(item.getAttribute("data-node-id"));
}); });

View file

@ -158,41 +158,41 @@ export const globalShortcut = () => {
} }
}); });
let switchDialog: Dialog let switchDialog: Dialog;
window.addEventListener("keyup", (event) => { window.addEventListener("keyup", (event) => {
window.siyuan.ctrlIsPressed = false; window.siyuan.ctrlIsPressed = false;
window.siyuan.shiftIsPressed = false; window.siyuan.shiftIsPressed = false;
window.siyuan.altIsPressed = false; window.siyuan.altIsPressed = false;
if (switchDialog && switchDialog.element.parentElement) { if (switchDialog && switchDialog.element.parentElement) {
if (event.key === "Tab") { if (event.key === "Tab") {
const currentLiElement = switchDialog.element.querySelector(".b3-list-item--focus") const currentLiElement = switchDialog.element.querySelector(".b3-list-item--focus");
currentLiElement.classList.remove("b3-list-item--focus") currentLiElement.classList.remove("b3-list-item--focus");
if (event.shiftKey) { if (event.shiftKey) {
if (currentLiElement.previousElementSibling) { if (currentLiElement.previousElementSibling) {
currentLiElement.previousElementSibling.classList.add("b3-list-item--focus") currentLiElement.previousElementSibling.classList.add("b3-list-item--focus");
} else if (currentLiElement.getAttribute("data-original")) { } else if (currentLiElement.getAttribute("data-original")) {
currentLiElement.parentElement.lastElementChild.classList.add("b3-list-item--focus") currentLiElement.parentElement.lastElementChild.classList.add("b3-list-item--focus");
currentLiElement.removeAttribute("data-original") currentLiElement.removeAttribute("data-original");
} else if (currentLiElement.parentElement.nextElementSibling) { } else if (currentLiElement.parentElement.nextElementSibling) {
currentLiElement.parentElement.nextElementSibling.lastElementChild.classList.add("b3-list-item--focus") currentLiElement.parentElement.nextElementSibling.lastElementChild.classList.add("b3-list-item--focus");
} else if (currentLiElement.parentElement.previousElementSibling) { } else if (currentLiElement.parentElement.previousElementSibling) {
currentLiElement.parentElement.previousElementSibling.lastElementChild.classList.add("b3-list-item--focus") currentLiElement.parentElement.previousElementSibling.lastElementChild.classList.add("b3-list-item--focus");
} }
} else { } else {
if (currentLiElement.nextElementSibling) { if (currentLiElement.nextElementSibling) {
currentLiElement.nextElementSibling.classList.add("b3-list-item--focus") currentLiElement.nextElementSibling.classList.add("b3-list-item--focus");
} else if (currentLiElement.getAttribute("data-original")) { } else if (currentLiElement.getAttribute("data-original")) {
currentLiElement.parentElement.firstElementChild.classList.add("b3-list-item--focus") currentLiElement.parentElement.firstElementChild.classList.add("b3-list-item--focus");
currentLiElement.removeAttribute("data-original") currentLiElement.removeAttribute("data-original");
} else if (currentLiElement.parentElement.nextElementSibling) { } else if (currentLiElement.parentElement.nextElementSibling) {
currentLiElement.parentElement.nextElementSibling.firstElementChild.classList.add("b3-list-item--focus") currentLiElement.parentElement.nextElementSibling.firstElementChild.classList.add("b3-list-item--focus");
} else if (currentLiElement.parentElement.previousElementSibling) { } else if (currentLiElement.parentElement.previousElementSibling) {
currentLiElement.parentElement.previousElementSibling.firstElementChild.classList.add("b3-list-item--focus") currentLiElement.parentElement.previousElementSibling.firstElementChild.classList.add("b3-list-item--focus");
} }
} }
} else if (event.key === "Control") { } else if (event.key === "Control") {
const currentLiElement = switchDialog.element.querySelector(".b3-list-item--focus") const currentLiElement = switchDialog.element.querySelector(".b3-list-item--focus");
const currentType = currentLiElement.getAttribute("data-type") as TDockType const currentType = currentLiElement.getAttribute("data-type") as TDockType;
if (currentType) { if (currentType) {
getDockByType(currentType).toggleModel(currentType, true); getDockByType(currentType).toggleModel(currentType, true);
const target = event.target as HTMLElement; const target = event.target as HTMLElement;
@ -202,14 +202,14 @@ export const globalShortcut = () => {
target.blur(); target.blur();
} }
} else { } else {
const currentId = currentLiElement.getAttribute("data-id") const currentId = currentLiElement.getAttribute("data-id");
getAllTabs().find(item => { getAllTabs().find(item => {
if (item.id === currentId) { if (item.id === currentId) {
item.parent.switchTab(item.headElement); item.parent.switchTab(item.headElement);
setPanelFocus(item.headElement.parentElement.parentElement); setPanelFocus(item.headElement.parentElement.parentElement);
return true; return true;
} }
}) });
} }
switchDialog.destroy(); switchDialog.destroy();
switchDialog = undefined; switchDialog = undefined;
@ -254,29 +254,29 @@ export const globalShortcut = () => {
if (switchDialog && switchDialog.element.parentElement) { if (switchDialog && switchDialog.element.parentElement) {
return; return;
} }
let dockHtml = '' let dockHtml = "";
let tabHtml = '' let tabHtml = "";
getAllDocks().forEach(item => { getAllDocks().forEach(item => {
dockHtml += `<li data-type="${item.type}" class="b3-list-item"> dockHtml += `<li data-type="${item.type}" class="b3-list-item">
<svg class="b3-list-item__graphic"><use xlink:href="#${item.icon}"></use></svg> <svg class="b3-list-item__graphic"><use xlink:href="#${item.icon}"></use></svg>
<span class="b3-list-item__text">${window.siyuan.languages[item.hotkeyLangId]}</span> <span class="b3-list-item__text">${window.siyuan.languages[item.hotkeyLangId]}</span>
<span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general[item.hotkeyLangId].custom)}</span> <span class="b3-list-item__meta">${updateHotkeyTip(window.siyuan.config.keymap.general[item.hotkeyLangId].custom)}</span>
</li>` </li>`;
}) });
let currentTabElement = document.querySelector(".layout__wnd--active .layout-tab-bar > .item--focus") let currentTabElement = document.querySelector(".layout__wnd--active .layout-tab-bar > .item--focus");
if (!currentTabElement) { if (!currentTabElement) {
currentTabElement = document.querySelector(".layout-tab-bar > .item--focus") currentTabElement = document.querySelector(".layout-tab-bar > .item--focus");
} }
if (currentTabElement) { if (currentTabElement) {
const currentId = currentTabElement.getAttribute("data-id") const currentId = currentTabElement.getAttribute("data-id");
getAllTabs().sort((itemA, itemB) => { getAllTabs().sort((itemA, itemB) => {
return itemA.headElement.getAttribute("data-activetime") > itemB.headElement.getAttribute("data-activetime") ? -1 : 1 return itemA.headElement.getAttribute("data-activetime") > itemB.headElement.getAttribute("data-activetime") ? -1 : 1;
}).forEach(item => { }).forEach(item => {
let icon = `<svg class="b3-list-item__graphic"><use xlink:href="#${item.icon}"></use></svg>` let icon = `<svg class="b3-list-item__graphic"><use xlink:href="#${item.icon}"></use></svg>`;
if (item.model instanceof Editor) { if (item.model instanceof Editor) {
icon = `<span class="b3-list-item__graphic">${unicode2Emoji(item.docIcon || Constants.SIYUAN_IMAGE_FILE)}</span>` icon = `<span class="b3-list-item__graphic">${unicode2Emoji(item.docIcon || Constants.SIYUAN_IMAGE_FILE)}</span>`;
} }
tabHtml += `<li data-id="${item.id}" class="b3-list-item${currentId === item.id ? " b3-list-item--focus" : ""}"${currentId === item.id ? ' data-original="true"' : ""}>${icon}<span class="b3-list-item__text">${item.title}</span></li>` tabHtml += `<li data-id="${item.id}" class="b3-list-item${currentId === item.id ? " b3-list-item--focus" : ""}"${currentId === item.id ? ' data-original="true"' : ""}>${icon}<span class="b3-list-item__text">${item.title}</span></li>`;
}); });
} }
switchDialog = new Dialog({ switchDialog = new Dialog({
@ -295,26 +295,26 @@ export const globalShortcut = () => {
let target = event.target as HTMLElement; let target = event.target as HTMLElement;
while (!target.isSameNode(switchDialog.element)) { while (!target.isSameNode(switchDialog.element)) {
if (target.classList.contains("b3-list-item")) { if (target.classList.contains("b3-list-item")) {
const currentType = target.getAttribute("data-type") as TDockType const currentType = target.getAttribute("data-type") as TDockType;
if (currentType) { if (currentType) {
getDockByType(currentType).toggleModel(currentType, true); getDockByType(currentType).toggleModel(currentType, true);
} else { } else {
const currentId = target.getAttribute("data-id") const currentId = target.getAttribute("data-id");
getAllTabs().find(item => { getAllTabs().find(item => {
if (item.id === currentId) { if (item.id === currentId) {
item.parent.switchTab(item.headElement); item.parent.switchTab(item.headElement);
setPanelFocus(item.headElement.parentElement.parentElement); setPanelFocus(item.headElement.parentElement.parentElement);
return true; return true;
} }
}) });
} }
switchDialog.destroy(); switchDialog.destroy();
switchDialog = undefined; switchDialog = undefined;
break break;
} }
target = target.parentElement; target = target.parentElement;
} }
}) });
return; return;
} }