fix(shortcut): focusInput
This commit is contained in:
@@ -55,7 +55,7 @@ import {
|
|||||||
useTimerStore,
|
useTimerStore,
|
||||||
} from "./useTimerStore"
|
} from "./useTimerStore"
|
||||||
import { useTopToolsStore } from "./useTopToolsStore"
|
import { useTopToolsStore } from "./useTopToolsStore"
|
||||||
import { findGroupKey } from "./util"
|
import { findGroupKey, isEditableKeyboardTarget } from "./util"
|
||||||
import { safeClone } from "./utils/clone"
|
import { safeClone } from "./utils/clone"
|
||||||
import { labelTypeMap } from "./utils/constants"
|
import { labelTypeMap } from "./utils/constants"
|
||||||
import { toggleObjectHideByShortcut } from "./utils/objectVisibility"
|
import { toggleObjectHideByShortcut } from "./utils/objectVisibility"
|
||||||
@@ -2164,7 +2164,7 @@ const LabelPage = ({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const down = (e: KeyboardEvent) => {
|
const down = (e: KeyboardEvent) => {
|
||||||
// console.log(e, e.key);
|
// console.log(e, e.key);
|
||||||
if (focusInput) return
|
if (focusInput || isEditableKeyboardTarget(e.target)) return
|
||||||
|
|
||||||
console.log(e.key)
|
console.log(e.key)
|
||||||
const mode = usePaperStore.getState().mode
|
const mode = usePaperStore.getState().mode
|
||||||
|
|||||||
@@ -1,5 +1,71 @@
|
|||||||
import { Project } from "./api/project/typing"
|
import { Project } from "./api/project/typing"
|
||||||
|
|
||||||
|
const nonEditableInputTypes = new Set([
|
||||||
|
"button",
|
||||||
|
"checkbox",
|
||||||
|
"color",
|
||||||
|
"file",
|
||||||
|
"hidden",
|
||||||
|
"image",
|
||||||
|
"radio",
|
||||||
|
"range",
|
||||||
|
"reset",
|
||||||
|
"submit",
|
||||||
|
])
|
||||||
|
|
||||||
|
const editableRoles = new Set([
|
||||||
|
"textbox",
|
||||||
|
"searchbox",
|
||||||
|
"combobox",
|
||||||
|
"spinbutton",
|
||||||
|
])
|
||||||
|
|
||||||
|
const resolveTargetElement = (target: EventTarget | null) => {
|
||||||
|
if (target instanceof Element) return target
|
||||||
|
if (target instanceof Node) return target.parentElement
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export const isEditableKeyboardTarget = (target: EventTarget | null) => {
|
||||||
|
const element = resolveTargetElement(target)
|
||||||
|
if (!element) return false
|
||||||
|
|
||||||
|
const editableElement = element.closest(
|
||||||
|
[
|
||||||
|
"input",
|
||||||
|
"textarea",
|
||||||
|
"select",
|
||||||
|
"[contenteditable='']",
|
||||||
|
"[contenteditable='true']",
|
||||||
|
"[role='textbox']",
|
||||||
|
"[role='searchbox']",
|
||||||
|
"[role='combobox']",
|
||||||
|
"[role='spinbutton']",
|
||||||
|
].join(",")
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!editableElement) return false
|
||||||
|
|
||||||
|
if (editableElement instanceof HTMLInputElement) {
|
||||||
|
return !nonEditableInputTypes.has(editableElement.type.toLowerCase())
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
editableElement instanceof HTMLTextAreaElement ||
|
||||||
|
editableElement instanceof HTMLSelectElement
|
||||||
|
) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (editableElement instanceof HTMLElement) {
|
||||||
|
if (editableElement.isContentEditable) return true
|
||||||
|
const role = editableElement.getAttribute("role")
|
||||||
|
return role ? editableRoles.has(role) : false
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// 是否存在不符合要求的子属性
|
// 是否存在不符合要求的子属性
|
||||||
export const getSubAttrStatus = (
|
export const getSubAttrStatus = (
|
||||||
operationSchema: Project.LabelSchemaList | null,
|
operationSchema: Project.LabelSchemaList | null,
|
||||||
|
|||||||
Reference in New Issue
Block a user