mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 09:30:14 +01:00
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;
|
return;
|
||||||
}
|
}
|
||||||
// https://github.com/siyuan-note/siyuan/issues/8913#issuecomment-1679720605
|
// https://github.com/siyuan-note/siyuan/issues/8913#issuecomment-1679720605
|
||||||
const confirmElement = document.querySelector("#confirmDialogConfirmBtn");
|
const confirmDialogElement = document.querySelector('.b3-dialog--open[data-key="dialog-confirm"]');
|
||||||
if (confirmElement) {
|
if (confirmDialogElement) {
|
||||||
if (event.key === "Enter") {
|
if (event.key === "Enter") {
|
||||||
confirmElement.dispatchEvent(new CustomEvent("click"));
|
confirmDialogElement.dispatchEvent(new CustomEvent("click", {detail: event.key}));
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
} else if (event.key === "Escape") {
|
} else if (event.key === "Escape") {
|
||||||
confirmElement.previousElementSibling.previousElementSibling.dispatchEvent(new CustomEvent("click"));
|
confirmDialogElement.dispatchEvent(new CustomEvent("click", {detail: event.key}));
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,23 +16,31 @@ export const confirmDialog = (title: string, text: string,
|
||||||
<div class="ft__breakword">${text}</div>
|
<div class="ft__breakword">${text}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="b3-dialog__action">
|
<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>
|
<button class="b3-button ${isDelete ? "b3-button--remove" : "b3-button--text"}" id="confirmDialogConfirmBtn">${window.siyuan.languages[isDelete ? "delete" : "confirm"]}</button>
|
||||||
</div>`,
|
</div>`,
|
||||||
width: isMobile() ? "92vw" : "520px",
|
width: isMobile() ? "92vw" : "520px",
|
||||||
});
|
});
|
||||||
const btnsElement = dialog.element.querySelectorAll(".b3-button");
|
|
||||||
btnsElement[0].addEventListener("click", () => {
|
dialog.element.addEventListener("click", (event) => {
|
||||||
if (cancel) {
|
let target = event.target as HTMLElement;
|
||||||
cancel(dialog);
|
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);
|
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) => {
|
dialog.element.addEventListener("click", (event) => {
|
||||||
let target = event.target as HTMLElement;
|
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");
|
const action = target.getAttribute("data-action");
|
||||||
if (action === "delete") {
|
if (action === "delete" || (isDispatch && event.detail === "Enter")) {
|
||||||
removeColByMenu({
|
removeColByMenu({
|
||||||
protyle,
|
protyle,
|
||||||
colId,
|
colId,
|
||||||
|
|
@ -998,13 +999,15 @@ export const showColMenu = (protyle: IProtyle, blockElement: Element, cellElemen
|
||||||
});
|
});
|
||||||
dialog.destroy();
|
dialog.destroy();
|
||||||
break;
|
break;
|
||||||
} else if (target.classList.contains("b3-button--cancel")) {
|
} else if (target.classList.contains("b3-button--cancel") || (isDispatch && event.detail === "Escape")) {
|
||||||
dialog.destroy();
|
dialog.destroy();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
target = target.parentElement;
|
target = target.parentElement;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
dialog.element.querySelector("button").focus()
|
||||||
|
dialog.element.setAttribute("data-key", Constants.DIALOG_CONFIRM);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1106,11 +1106,12 @@ export const openMenuPanel = (options: {
|
||||||
<button class="fn__block b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button>
|
<button class="fn__block b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button>
|
||||||
</div>`,
|
</div>`,
|
||||||
});
|
});
|
||||||
dialog.element.addEventListener("click", (event) => {
|
dialog.element.addEventListener("click", (dialogEvent) => {
|
||||||
let target = event.target as HTMLElement;
|
let target = dialogEvent.target as HTMLElement;
|
||||||
while (target && !target.isSameNode(dialog.element)) {
|
const isDispatch = typeof dialogEvent.detail === "string";
|
||||||
|
while (target && !target.isSameNode(dialog.element) || isDispatch) {
|
||||||
const action = target.getAttribute("data-action");
|
const action = target.getAttribute("data-action");
|
||||||
if (action === "delete") {
|
if (action === "delete" || (isDispatch && dialogEvent.detail === "Enter")) {
|
||||||
removeCol({
|
removeCol({
|
||||||
protyle: options.protyle,
|
protyle: options.protyle,
|
||||||
data,
|
data,
|
||||||
|
|
@ -1140,13 +1141,14 @@ export const openMenuPanel = (options: {
|
||||||
});
|
});
|
||||||
dialog.destroy();
|
dialog.destroy();
|
||||||
break;
|
break;
|
||||||
} else if (target.classList.contains("b3-button--cancel")) {
|
} else if (target.classList.contains("b3-button--cancel") || (isDispatch && dialogEvent.detail === "Escape")) {
|
||||||
dialog.destroy();
|
dialog.destroy();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
target = target.parentElement;
|
target = target.parentElement;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
dialog.element.setAttribute("data-key", Constants.DIALOG_CONFIRM);
|
||||||
} else {
|
} else {
|
||||||
removeCol({
|
removeCol({
|
||||||
protyle: options.protyle,
|
protyle: options.protyle,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue