mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 16:40:13 +01:00
🎨 tab 后会卡住
This commit is contained in:
parent
b31765d0ab
commit
c6e2f1b9cd
3 changed files with 36 additions and 41 deletions
|
|
@ -141,7 +141,7 @@ export const popTextCell = (protyle: IProtyle, cellElements: HTMLElement[], type
|
||||||
if (!type) {
|
if (!type) {
|
||||||
type = getTypeByCellElement(cellElements[0]);
|
type = getTypeByCellElement(cellElements[0]);
|
||||||
}
|
}
|
||||||
if (type === "updated" || type === "created") {
|
if (type === "updated" || type === "created" || document.querySelector(".av__mask")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (type === "block" && (cellElements.length > 1 || !cellElements[0].getAttribute("data-detached"))) {
|
if (type === "block" && (cellElements.length > 1 || !cellElements[0].getAttribute("data-detached"))) {
|
||||||
|
|
@ -210,7 +210,7 @@ export const popTextCell = (protyle: IProtyle, cellElements: HTMLElement[], type
|
||||||
}
|
}
|
||||||
if (event.key === "Escape" || event.key === "Tab" ||
|
if (event.key === "Escape" || event.key === "Tab" ||
|
||||||
(event.key === "Enter" && !event.shiftKey && isNotCtrl(event))) {
|
(event.key === "Enter" && !event.shiftKey && isNotCtrl(event))) {
|
||||||
updateCellValue(protyle, type, cellElements);
|
inputElement.blur();
|
||||||
if (event.key === "Tab") {
|
if (event.key === "Tab") {
|
||||||
protyle.wysiwyg.element.dispatchEvent(new KeyboardEvent("keydown", {
|
protyle.wysiwyg.element.dispatchEvent(new KeyboardEvent("keydown", {
|
||||||
shiftKey: event.shiftKey,
|
shiftKey: event.shiftKey,
|
||||||
|
|
@ -260,7 +260,6 @@ const updateCellValue = (protyle: IProtyle, type: TAVCol, cellElements: HTMLElem
|
||||||
if (!blockElement) {
|
if (!blockElement) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const avMaskElement = document.querySelector(".av__mask");
|
const avMaskElement = document.querySelector(".av__mask");
|
||||||
const doOperations: IOperation[] = [];
|
const doOperations: IOperation[] = [];
|
||||||
const undoOperations: IOperation[] = [];
|
const undoOperations: IOperation[] = [];
|
||||||
|
|
@ -362,7 +361,7 @@ const updateCellValue = (protyle: IProtyle, type: TAVCol, cellElements: HTMLElem
|
||||||
if (blockElement) {
|
if (blockElement) {
|
||||||
focusBlock(blockElement);
|
focusBlock(blockElement);
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
document.querySelectorAll(".av__mask").forEach((item) => {
|
||||||
avMaskElement?.remove();
|
item.remove();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,11 @@ export const avKeydown = (event: KeyboardEvent, nodeElement: HTMLElement, protyl
|
||||||
(Constants.KEYCODELIST[event.keyCode].length === 1 &&
|
(Constants.KEYCODELIST[event.keyCode].length === 1 &&
|
||||||
!event.metaKey && !event.ctrlKey &&
|
!event.metaKey && !event.ctrlKey &&
|
||||||
!["⇧", "⌃", "⌥", "⌘"].includes(Constants.KEYCODELIST[event.keyCode]))) {
|
!["⇧", "⌃", "⌥", "⌘"].includes(Constants.KEYCODELIST[event.keyCode]))) {
|
||||||
|
if (!selectCellElement.style.backgroundColor) {
|
||||||
popTextCell(protyle, [selectCellElement]);
|
popTextCell(protyle, [selectCellElement]);
|
||||||
|
} else {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -276,7 +276,6 @@ ${cell.color ? `color:${cell.color};` : ""}">${text}</div>`;
|
||||||
} else {
|
} else {
|
||||||
stickyRow(e, editRect, "bottom");
|
stickyRow(e, editRect, "bottom");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectCellId) {
|
if (selectCellId) {
|
||||||
const newCellElement = e.querySelector(`.av__row[data-id="${selectCellId.split(Constants.ZWSP)[0]}"] .av__cell[data-col-id="${selectCellId.split(Constants.ZWSP)[1]}"]`);
|
const newCellElement = e.querySelector(`.av__row[data-id="${selectCellId.split(Constants.ZWSP)[0]}"] .av__cell[data-col-id="${selectCellId.split(Constants.ZWSP)[1]}"]`);
|
||||||
if (newCellElement) {
|
if (newCellElement) {
|
||||||
|
|
@ -296,8 +295,7 @@ ${cell.color ? `color:${cell.color};` : ""}">${text}</div>`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let lastParentID: string;
|
let refreshTimeout: number;
|
||||||
let lastElement: HTMLElement;
|
|
||||||
export const refreshAV = (protyle: IProtyle, operation: IOperation, isUndo: boolean) => {
|
export const refreshAV = (protyle: IProtyle, operation: IOperation, isUndo: boolean) => {
|
||||||
if (operation.action === "setAttrViewName") {
|
if (operation.action === "setAttrViewName") {
|
||||||
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${operation.id}"]`)).forEach((item: HTMLElement) => {
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${operation.id}"]`)).forEach((item: HTMLElement) => {
|
||||||
|
|
@ -309,14 +307,11 @@ export const refreshAV = (protyle: IProtyle, operation: IOperation, isUndo: bool
|
||||||
titleElement.dataset.title = operation.data;
|
titleElement.dataset.title = operation.data;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (lastParentID === operation.parentID && protyle.contentElement.isSameNode(lastElement)) {
|
// 只能 setTimeout,以前方案快速输入后最后一次修改会被忽略
|
||||||
return;
|
clearTimeout(refreshTimeout);
|
||||||
}
|
refreshTimeout = window.setTimeout(() => {
|
||||||
lastElement = protyle.contentElement;
|
|
||||||
lastParentID = operation.parentID;
|
|
||||||
const avId = operation.avID;
|
|
||||||
if (operation.action === "setAttrViewColWidth") {
|
if (operation.action === "setAttrViewColWidth") {
|
||||||
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${avId}"]`)).forEach((item: HTMLElement) => {
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${operation.avID}"]`)).forEach((item: HTMLElement) => {
|
||||||
const cellElement = item.querySelector(`.av__cell[data-col-id="${operation.id}"]`) as HTMLElement;
|
const cellElement = item.querySelector(`.av__cell[data-col-id="${operation.id}"]`) as HTMLElement;
|
||||||
if (!cellElement || cellElement.style.width === operation.data) {
|
if (!cellElement || cellElement.style.width === operation.data) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -326,7 +321,7 @@ export const refreshAV = (protyle: IProtyle, operation: IOperation, isUndo: bool
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${avId}"]`)).forEach((item: HTMLElement) => {
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${operation.avID}"]`)).forEach((item: HTMLElement) => {
|
||||||
item.removeAttribute("data-render");
|
item.removeAttribute("data-render");
|
||||||
const isCurrent = item.querySelector(".av__pulse"); // ctrl+D 后点击添加行
|
const isCurrent = item.querySelector(".av__pulse"); // ctrl+D 后点击添加行
|
||||||
avRender(item, protyle, () => {
|
avRender(item, protyle, () => {
|
||||||
|
|
@ -338,8 +333,5 @@ export const refreshAV = (protyle: IProtyle, operation: IOperation, isUndo: bool
|
||||||
(operation.action === "removeAttrViewView" ? null : undefined));
|
(operation.action === "removeAttrViewView" ? null : undefined));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}, 100);
|
||||||
setTimeout(() => {
|
|
||||||
lastParentID = null;
|
|
||||||
}, Constants.TIMEOUT_TRANSITION);
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue