shortcut set blank
This commit is contained in:
@@ -5,6 +5,7 @@ import { useSetting } from "./Setting";
|
|||||||
export function useShortcut(action) {
|
export function useShortcut(action) {
|
||||||
const { setting, updateSetting } = useSetting();
|
const { setting, updateSetting } = useSetting();
|
||||||
const shortcuts = setting?.shortcuts || DEFAULT_SHORTCUTS;
|
const shortcuts = setting?.shortcuts || DEFAULT_SHORTCUTS;
|
||||||
|
const shortcut = shortcuts[action] || [];
|
||||||
|
|
||||||
const setShortcut = useCallback(
|
const setShortcut = useCallback(
|
||||||
async (val) => {
|
async (val) => {
|
||||||
@@ -14,5 +15,5 @@ export function useShortcut(action) {
|
|||||||
[action, shortcuts, updateSetting]
|
[action, shortcuts, updateSetting]
|
||||||
);
|
);
|
||||||
|
|
||||||
return { shortcut: shortcuts[action] || [], setShortcut };
|
return { shortcut, setShortcut };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,29 +33,26 @@ function ShortcutItem({ action, label }) {
|
|||||||
const { shortcut, setShortcut } = useShortcut(action);
|
const { shortcut, setShortcut } = useShortcut(action);
|
||||||
const [disabled, setDisabled] = useState(true);
|
const [disabled, setDisabled] = useState(true);
|
||||||
const inputRef = useRef(null);
|
const inputRef = useRef(null);
|
||||||
const [formval, setFormval] = useState(shortcut);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
setFormval(shortcut);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
inputRef.current.focus();
|
inputRef.current.focus();
|
||||||
setFormval([]);
|
setShortcut([]);
|
||||||
|
|
||||||
const clearShortcut = shortcutListener((curkeys, allkeys) => {
|
const clearShortcut = shortcutListener((curkeys, allkeys) => {
|
||||||
setFormval(allkeys);
|
setShortcut(allkeys);
|
||||||
if (curkeys.length === 0) {
|
if (curkeys.length === 0) {
|
||||||
setDisabled(true);
|
setDisabled(true);
|
||||||
setShortcut(allkeys);
|
|
||||||
}
|
}
|
||||||
}, inputRef.current);
|
}, inputRef.current);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
clearShortcut();
|
clearShortcut();
|
||||||
};
|
};
|
||||||
}, [disabled, setShortcut, shortcut]);
|
}, [disabled, setShortcut]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack direction="row">
|
<Stack direction="row">
|
||||||
@@ -63,7 +60,7 @@ function ShortcutItem({ action, label }) {
|
|||||||
size="small"
|
size="small"
|
||||||
label={label}
|
label={label}
|
||||||
name={label}
|
name={label}
|
||||||
value={formval.join(" + ")}
|
value={shortcut.join(" + ")}
|
||||||
fullWidth
|
fullWidth
|
||||||
inputRef={inputRef}
|
inputRef={inputRef}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
|||||||
Reference in New Issue
Block a user