Vanessa 2023-08-02 20:19:04 +08:00
parent 3312d0de09
commit 81ae9a22cd
2 changed files with 16 additions and 3 deletions

View file

@ -135,7 +135,7 @@ ${html}
export const bindEditEvent = (options: { protyle: IProtyle, data: IAV, menuElement: HTMLElement }) => {
const avID = options.data.id;
const colId = options.menuElement.firstElementChild.getAttribute("data-col-id");
const colId = options.menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id");
const colData = options.data.view.columns.find((item: IAVColumn) => item.id === colId);
const nameElement = options.menuElement.querySelector('[data-type="name"]') as HTMLInputElement;
nameElement.addEventListener("blur", () => {
@ -164,6 +164,9 @@ export const bindEditEvent = (options: { protyle: IProtyle, data: IAV, menuEleme
}
if (event.key === "Escape") {
options.menuElement.parentElement.remove();
} else if (event.key === "Enter") {
nameElement.dispatchEvent(new CustomEvent("blur"));
options.menuElement.parentElement.remove();
}
});
const addOptionElement = options.menuElement.querySelector('[data-type="addOption"]') as HTMLInputElement;

View file

@ -101,7 +101,7 @@ export const setColOption = (protyle: IProtyle, data: IAV, target: HTMLElement,
if (!menuElement) {
return;
}
const colId = cellElements ? cellElements[0].dataset.colId : menuElement.firstElementChild.getAttribute("data-col-id");
const colId = cellElements ? cellElements[0].dataset.colId : menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id");
let name = target.parentElement.dataset.name;
let color = target.parentElement.dataset.color;
const menu = new Menu("av-col-option", () => {
@ -169,7 +169,17 @@ export const setColOption = (protyle: IProtyle, data: IAV, target: HTMLElement,
}
menu.addItem({
iconHTML: "",
label: `<input class="b3-text-field" style="margin: 4px 0" value="${name}">`
label: `<input class="b3-text-field" style="margin: 4px 0" value="${name}">`,
bind(element) {
element.querySelector("input").addEventListener("keydown", (event: KeyboardEvent) => {
if (event.isComposing) {
return;
}
if (event.key === "Enter") {
menu.close();
}
});
}
});
menu.addItem({
label: window.siyuan.languages.delete,