🎨 ctrl+p database table view cell

This commit is contained in:
Vanessa 2023-12-14 12:22:18 +08:00
parent c3918a2a71
commit 9634480890
7 changed files with 20 additions and 21 deletions

View file

@ -323,7 +323,7 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
return true; return true;
} }
const target = event.target as HTMLElement; const target = event.target as HTMLElement;
if (target.tagName !== "TABLE" && (target.tagName === "INPUT" || target.tagName === "TEXTAREA")) { if (target.tagName !== "TABLE" && ["INPUT", "TEXTAREA"].includes(target.tagName)) {
return false; return false;
} }
if (matchHotKey(window.siyuan.config.keymap.editor.general.backlinks.custom, event)) { if (matchHotKey(window.siyuan.config.keymap.editor.general.backlinks.custom, event)) {
@ -653,7 +653,7 @@ const fileTreeKeydown = (app: App, event: KeyboardEvent) => {
return true; return true;
} }
const target = event.target as HTMLElement; const target = event.target as HTMLElement;
if (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || if (["INPUT", "TEXTAREA"].includes(target.tagName) ||
hasClosestByAttribute(target, "contenteditable", null) || hasClosestByAttribute(target, "contenteditable", null) ||
hasClosestByClassName(target, "protyle", true)) { hasClosestByClassName(target, "protyle", true)) {
return false; return false;
@ -834,7 +834,7 @@ const fileTreeKeydown = (app: App, event: KeyboardEvent) => {
const panelTreeKeydown = (app: App, event: KeyboardEvent) => { const panelTreeKeydown = (app: App, event: KeyboardEvent) => {
// 面板折叠展开操作 // 面板折叠展开操作
const target = event.target as HTMLElement; const target = event.target as HTMLElement;
if (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || if (["INPUT", "TEXTAREA"].includes(target.tagName) ||
hasClosestByAttribute(target, "contenteditable", null) || hasClosestByAttribute(target, "contenteditable", null) ||
hasClosestByClassName(target, "protyle", true)) { hasClosestByClassName(target, "protyle", true)) {
return false; return false;
@ -1280,7 +1280,7 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => {
event.preventDefault(); event.preventDefault();
return; return;
} }
if (matchHotKey("⌘A", event) && target.tagName !== "INPUT" && target.tagName !== "TEXTAREA") { if (matchHotKey("⌘A", event) && !["INPUT", "TEXTAREA"].includes(target.tagName)) {
event.preventDefault(); event.preventDefault();
return; return;
} }

View file

@ -213,13 +213,7 @@ export const initWindow = async (app: App) => {
ipcRenderer.on(Constants.SIYUAN_EVENT, (event, cmd) => { ipcRenderer.on(Constants.SIYUAN_EVENT, (event, cmd) => {
if (cmd === "focus") { if (cmd === "focus") {
if (getSelection().rangeCount > 0) { if (getSelection().rangeCount > 0) {
const range = getSelection().getRangeAt(0); focusByRange(getSelection().getRangeAt(0));
const startNode = range.startContainer.childNodes[range.startOffset] as HTMLElement;
if (startNode && startNode.nodeType !== 3 && (startNode.tagName === "TEXTAREA" || startNode.tagName === "INPUT")) {
startNode.focus();
} else {
focusByRange(getSelection().getRangeAt(0));
}
} }
exportLayout({ exportLayout({
reload: false, reload: false,

View file

@ -253,7 +253,7 @@ export const bindMenuKeydown = (event: KeyboardEvent) => {
return false; return false;
} }
const target = event.target as HTMLElement; const target = event.target as HTMLElement;
if (window.siyuan.menus.menu.element.contains(target) && (target.tagName === "INPUT" || target.tagName === "TEXTAREA")) { if (window.siyuan.menus.menu.element.contains(target) && ["INPUT", "TEXTAREA"].includes(target.tagName)) {
return false; return false;
} }
const eventCode = Constants.KEYCODELIST[event.keyCode]; const eventCode = Constants.KEYCODELIST[event.keyCode];

View file

@ -308,8 +308,7 @@ const renderKeyboardToolbar = () => {
window.screen.height - window.innerHeight < 160 || // reloadSync 会导致 selectionchange从而导致键盘没有弹起的情况下出现工具栏 window.screen.height - window.innerHeight < 160 || // reloadSync 会导致 selectionchange从而导致键盘没有弹起的情况下出现工具栏
!document.activeElement || ( !document.activeElement || (
document.activeElement && document.activeElement &&
document.activeElement.tagName !== "INPUT" && !["INPUT", "TEXTAREA"].includes(document.activeElement.tagName) &&
document.activeElement.tagName !== "TEXTAREA" &&
!document.activeElement.classList.contains("protyle-wysiwyg") && !document.activeElement.classList.contains("protyle-wysiwyg") &&
document.activeElement.getAttribute("contenteditable") !== "true" document.activeElement.getAttribute("contenteditable") !== "true"
)) { )) {
@ -318,8 +317,7 @@ const renderKeyboardToolbar = () => {
} }
// 编辑器设置界面点击空白或关闭,焦点不知何故会飘移到编辑器上 // 编辑器设置界面点击空白或关闭,焦点不知何故会飘移到编辑器上
if (document.activeElement && if (document.activeElement &&
document.activeElement.tagName !== "INPUT" && !["INPUT", "TEXTAREA"].includes(document.activeElement.tagName) && (
document.activeElement.tagName !== "TEXTAREA" && (
document.getElementById("menu").style.transform === "translateX(0px)" || document.getElementById("menu").style.transform === "translateX(0px)" ||
document.getElementById("model").style.transform === "translateY(0px)" document.getElementById("model").style.transform === "translateY(0px)"
)) { )) {

View file

@ -204,16 +204,13 @@ export const popTextCell = (protyle: IProtyle, cellElements: HTMLElement[], type
}); });
}); });
} }
inputElement.addEventListener("blur", () => {
updateCellValue(protyle, type, cellElements);
});
inputElement.addEventListener("keydown", (event) => { inputElement.addEventListener("keydown", (event) => {
if (event.isComposing) { if (event.isComposing) {
return; return;
} }
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))) {
inputElement.blur(); updateCellValue(protyle, type, cellElements);
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,
@ -231,6 +228,7 @@ export const popTextCell = (protyle: IProtyle, cellElements: HTMLElement[], type
} }
avMaskElement.addEventListener("click", (event) => { avMaskElement.addEventListener("click", (event) => {
if ((event.target as HTMLElement).classList.contains("av__mask")) { if ((event.target as HTMLElement).classList.contains("av__mask")) {
updateCellValue(protyle, type, cellElements);
avMaskElement?.remove(); avMaskElement?.remove();
} }
}); });

View file

@ -296,7 +296,10 @@ ${cell.color ? `color:${cell.color};` : ""}">${text}</div>`;
if (newCellElement) { if (newCellElement) {
newCellElement.classList.add("av__cell--select"); newCellElement.classList.add("av__cell--select");
} }
if (!document.querySelector(".av__panel")) { const avMaskElement = document.querySelector(".av__mask");
if (avMaskElement) {
(avMaskElement.querySelector(" textarea") as HTMLTextAreaElement).focus();
} else if (!document.querySelector(".av__panel")) {
focusBlock(e); focusBlock(e);
} }
} }

View file

@ -475,6 +475,12 @@ export const focusByRange = (range: Range) => {
if (!range) { if (!range) {
return; return;
} }
const startNode = range.startContainer.childNodes[range.startOffset] as HTMLElement;
if (startNode && startNode.nodeType !== 3 && ["INPUT", "TEXTAREA"].includes(startNode.tagName)) {
startNode.focus();
return;
}
const selection = window.getSelection(); const selection = window.getSelection();
selection.removeAllRanges(); selection.removeAllRanges();
selection.addRange(range); selection.addRange(range);