This commit is contained in:
parent
e200bc61d9
commit
bb0ddc4147
4 changed files with 37 additions and 24 deletions
|
@ -1366,14 +1366,14 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {
|
|||
return;
|
||||
}
|
||||
// https://github.com/siyuan-note/siyuan/issues/8913#issuecomment-1679720605
|
||||
const confirmElement = document.querySelector("#confirmDialogConfirmBtn");
|
||||
if (confirmElement) {
|
||||
const confirmDialogElement = document.querySelector('.b3-dialog--open[data-key="dialog-confirm"]');
|
||||
if (confirmDialogElement) {
|
||||
if (event.key === "Enter") {
|
||||
confirmElement.dispatchEvent(new CustomEvent("click"));
|
||||
confirmDialogElement.dispatchEvent(new CustomEvent("click", {detail: event.key}));
|
||||
event.preventDefault();
|
||||
return;
|
||||
} else if (event.key === "Escape") {
|
||||
confirmElement.previousElementSibling.previousElementSibling.dispatchEvent(new CustomEvent("click"));
|
||||
confirmDialogElement.dispatchEvent(new CustomEvent("click", {detail: event.key}));
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -16,23 +16,31 @@ export const confirmDialog = (title: string, text: string,
|
|||
<div class="ft__breakword">${text}</div>
|
||||
</div>
|
||||
<div class="b3-dialog__action">
|
||||
<button class="b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button><div class="fn__space"></div>
|
||||
<button class="b3-button b3-button--cancel" id="cancelDialogConfirmBtn">${window.siyuan.languages.cancel}</button><div class="fn__space"></div>
|
||||
<button class="b3-button ${isDelete ? "b3-button--remove" : "b3-button--text"}" id="confirmDialogConfirmBtn">${window.siyuan.languages[isDelete ? "delete" : "confirm"]}</button>
|
||||
</div>`,
|
||||
width: isMobile() ? "92vw" : "520px",
|
||||
});
|
||||
const btnsElement = dialog.element.querySelectorAll(".b3-button");
|
||||
btnsElement[0].addEventListener("click", () => {
|
||||
if (cancel) {
|
||||
cancel(dialog);
|
||||
|
||||
dialog.element.addEventListener("click", (event) => {
|
||||
let target = event.target as HTMLElement;
|
||||
const isDispatch = typeof event.detail === "string";
|
||||
while (target && !target.isSameNode(dialog.element) || isDispatch) {
|
||||
if (target.id === "cancelDialogConfirmBtn" || (isDispatch && event.detail=== "Escape")) {
|
||||
if (cancel) {
|
||||
cancel(dialog);
|
||||
}
|
||||
dialog.destroy();
|
||||
break;
|
||||
} else if (target.id === "confirmDialogConfirmBtn" || (isDispatch && event.detail=== "Enter")) {
|
||||
if (confirm) {
|
||||
confirm(dialog);
|
||||
}
|
||||
dialog.destroy();
|
||||
break;
|
||||
}
|
||||
target = target.parentElement;
|
||||
}
|
||||
dialog.destroy();
|
||||
});
|
||||
btnsElement[1].addEventListener("click", () => {
|
||||
if (confirm) {
|
||||
confirm(dialog);
|
||||
}
|
||||
dialog.destroy();
|
||||
});
|
||||
dialog.element.setAttribute("data-key", Constants.DIALOG_CONFIRM);
|
||||
};
|
||||
|
|
|
@ -968,9 +968,10 @@ export const showColMenu = (protyle: IProtyle, blockElement: Element, cellElemen
|
|||
});
|
||||
dialog.element.addEventListener("click", (event) => {
|
||||
let target = event.target as HTMLElement;
|
||||
while (target && !target.isSameNode(dialog.element)) {
|
||||
const isDispatch = typeof event.detail === "string";
|
||||
while (target && !target.isSameNode(dialog.element) || isDispatch) {
|
||||
const action = target.getAttribute("data-action");
|
||||
if (action === "delete") {
|
||||
if (action === "delete" || (isDispatch && event.detail === "Enter")) {
|
||||
removeColByMenu({
|
||||
protyle,
|
||||
colId,
|
||||
|
@ -998,13 +999,15 @@ export const showColMenu = (protyle: IProtyle, blockElement: Element, cellElemen
|
|||
});
|
||||
dialog.destroy();
|
||||
break;
|
||||
} else if (target.classList.contains("b3-button--cancel")) {
|
||||
} else if (target.classList.contains("b3-button--cancel") || (isDispatch && event.detail === "Escape")) {
|
||||
dialog.destroy();
|
||||
break;
|
||||
}
|
||||
target = target.parentElement;
|
||||
}
|
||||
});
|
||||
dialog.element.querySelector("button").focus()
|
||||
dialog.element.setAttribute("data-key", Constants.DIALOG_CONFIRM);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1106,11 +1106,12 @@ export const openMenuPanel = (options: {
|
|||
<button class="fn__block b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button>
|
||||
</div>`,
|
||||
});
|
||||
dialog.element.addEventListener("click", (event) => {
|
||||
let target = event.target as HTMLElement;
|
||||
while (target && !target.isSameNode(dialog.element)) {
|
||||
dialog.element.addEventListener("click", (dialogEvent) => {
|
||||
let target = dialogEvent.target as HTMLElement;
|
||||
const isDispatch = typeof dialogEvent.detail === "string";
|
||||
while (target && !target.isSameNode(dialog.element) || isDispatch) {
|
||||
const action = target.getAttribute("data-action");
|
||||
if (action === "delete") {
|
||||
if (action === "delete" || (isDispatch && dialogEvent.detail === "Enter")) {
|
||||
removeCol({
|
||||
protyle: options.protyle,
|
||||
data,
|
||||
|
@ -1140,13 +1141,14 @@ export const openMenuPanel = (options: {
|
|||
});
|
||||
dialog.destroy();
|
||||
break;
|
||||
} else if (target.classList.contains("b3-button--cancel")) {
|
||||
} else if (target.classList.contains("b3-button--cancel") || (isDispatch && dialogEvent.detail === "Escape")) {
|
||||
dialog.destroy();
|
||||
break;
|
||||
}
|
||||
target = target.parentElement;
|
||||
}
|
||||
});
|
||||
dialog.element.setAttribute("data-key", Constants.DIALOG_CONFIRM);
|
||||
} else {
|
||||
removeCol({
|
||||
protyle: options.protyle,
|
||||
|
|
Loading…
Add table
Reference in a new issue