Feat: User can change the node shortcuts
This commit is contained in:
parent
edb2ff4034
commit
86fe906626
5 changed files with 48 additions and 9 deletions
|
|
@ -791,11 +791,11 @@ export const defaultShortcuts = [
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Minimize",
|
name: "Minimize",
|
||||||
shortcut: "Ctrl + Shift + q"
|
shortcut: "Ctrl + q"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Code",
|
name: "Code",
|
||||||
shortcut: "Ctrl + Shift + c"
|
shortcut: "Ctrl + Shift + u"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Copy",
|
name: "Copy",
|
||||||
|
|
@ -823,4 +823,4 @@ export const defaultShortcuts = [
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export const unavailableShortcutss = ["Ctrl + Shift + a", "Ctrl + Shift + q", "Ctrl + Shift + c", "Ctrl + c", "Ctrl + d", "Ctrl + Shift + s", "Ctrl + Shift + d", "Ctrl + s", "Backspace"];
|
export const unavailableShortcutss = ["Ctrl + Shift + a", "Ctrl + q", "Ctrl + Shift + u", "Ctrl + c", "Ctrl + d", "Ctrl + Shift + s", "Ctrl + Shift + d", "Ctrl + s", "Backspace"];
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ import {
|
||||||
} from "../../../../utils/reactflowUtils";
|
} from "../../../../utils/reactflowUtils";
|
||||||
import { classNames } from "../../../../utils/utils";
|
import { classNames } from "../../../../utils/utils";
|
||||||
import ToolbarSelectItem from "./toolbarSelectItem";
|
import ToolbarSelectItem from "./toolbarSelectItem";
|
||||||
|
import { useShortcutsStore } from "../../../../stores/shortcuts";
|
||||||
|
|
||||||
export default function NodeToolbarComponent({
|
export default function NodeToolbarComponent({
|
||||||
data,
|
data,
|
||||||
|
|
@ -144,14 +145,21 @@ export default function NodeToolbarComponent({
|
||||||
downloadNode(flowComponent!);
|
downloadNode(flowComponent!);
|
||||||
}
|
}
|
||||||
|
|
||||||
useHotkeys("mod+q", handleMinimizeWShortcut);
|
const advanced = useShortcutsStore(state => state.advanced);
|
||||||
|
const minimize = useShortcutsStore(state => state.minimize);
|
||||||
|
const share = useShortcutsStore(state => state.share);
|
||||||
|
const save = useShortcutsStore(state => state.save);
|
||||||
|
const docs = useShortcutsStore(state => state.docs);
|
||||||
|
const code = useShortcutsStore(state => state.code);
|
||||||
|
|
||||||
|
useHotkeys(minimize, handleMinimizeWShortcut);
|
||||||
useHotkeys("mod+u", handleUpdateWShortcut);
|
useHotkeys("mod+u", handleUpdateWShortcut);
|
||||||
useHotkeys("mod+g", handleGroupWShortcut);
|
useHotkeys("mod+g", handleGroupWShortcut);
|
||||||
useHotkeys("mod+shift+s", handleShareWShortcut);
|
useHotkeys(share, handleShareWShortcut);
|
||||||
useHotkeys("mod+shift+u", handleCodeWShortcut);
|
useHotkeys(code, handleCodeWShortcut);
|
||||||
useHotkeys("mod+shift+a", handleAdvancedWShortcut);
|
useHotkeys(advanced, handleAdvancedWShortcut);
|
||||||
useHotkeys("mod+s", handleSaveWShortcut);
|
useHotkeys(save, handleSaveWShortcut);
|
||||||
useHotkeys("mod+shift+d", handleDocsWShortcut);
|
useHotkeys(docs, handleDocsWShortcut);
|
||||||
useHotkeys("mod+j", handleDownloadWShortcut);
|
useHotkeys("mod+j", handleDownloadWShortcut);
|
||||||
useHotkeys("space", handleCodeWShortcut);
|
useHotkeys("space", handleCodeWShortcut);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,8 @@ export default function EditShortcutButton({ children, shortcut, defaultShortcut
|
||||||
return !unavaliableShortcuts.includes(newCombination);
|
return !unavaliableShortcuts.includes(newCombination);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const setUniqueShortcut = useShortcutsStore(state => state.updateUniqueShortcut);
|
||||||
|
|
||||||
function editCombination(): void {
|
function editCombination(): void {
|
||||||
if (canEditCombination(key)) {
|
if (canEditCombination(key)) {
|
||||||
const newCombination = defaultShortcuts.map((s) => {
|
const newCombination = defaultShortcuts.map((s) => {
|
||||||
|
|
@ -55,6 +57,11 @@ export default function EditShortcutButton({ children, shortcut, defaultShortcut
|
||||||
if (s === defaultCombination) return s = key;
|
if (s === defaultCombination) return s = key;
|
||||||
return s;
|
return s;
|
||||||
})
|
})
|
||||||
|
const fixCombination = key.split(" ")
|
||||||
|
fixCombination[0] = "mod"
|
||||||
|
const shortcutName = shortcut[0].split(" ")[0].toLowerCase();
|
||||||
|
console.log(shortcutName)
|
||||||
|
setUniqueShortcut(shortcutName, fixCombination.join("").toLowerCase())
|
||||||
setShortcuts(newCombination, unavailable)
|
setShortcuts(newCombination, unavailable)
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
setSuccessData({title: `${shortcut[0]} shortcut successfully changed`})
|
setSuccessData({title: `${shortcut[0]} shortcut successfully changed`})
|
||||||
|
|
|
||||||
|
|
@ -8,4 +8,18 @@ export const useShortcutsStore = create<shortcutsStoreType>((set, get) => ({
|
||||||
setShortcuts: (newShortcuts, unavailable) => {
|
setShortcuts: (newShortcuts, unavailable) => {
|
||||||
set({shortcuts: newShortcuts, unavailableShortcuts: unavailable} );
|
set({shortcuts: newShortcuts, unavailableShortcuts: unavailable} );
|
||||||
},
|
},
|
||||||
|
advanced: "mod+shift+a",
|
||||||
|
minimize: "mod+shift+q",
|
||||||
|
code: "mod+shift+u",
|
||||||
|
copy: "mod+c",
|
||||||
|
duplicate: "mod+d",
|
||||||
|
share: "mod+shift+s",
|
||||||
|
docs: "mod+shift+d",
|
||||||
|
save: "mod+s",
|
||||||
|
delete: "backspace",
|
||||||
|
updateUniqueShortcut: (name, combination) => {
|
||||||
|
set({
|
||||||
|
[name]: combination
|
||||||
|
})
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,16 @@ export type StoreComponentResponse = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export type shortcutsStoreType = {
|
export type shortcutsStoreType = {
|
||||||
|
updateUniqueShortcut: (name: string, combination: string) => void;
|
||||||
|
advanced: string;
|
||||||
|
minimize: string;
|
||||||
|
code: string;
|
||||||
|
copy: string;
|
||||||
|
duplicate: string;
|
||||||
|
share: string;
|
||||||
|
docs:string;
|
||||||
|
save:string;
|
||||||
|
delete: string;
|
||||||
shortcuts: Array<{
|
shortcuts: Array<{
|
||||||
name: string;
|
name: string;
|
||||||
shortcut: string;
|
shortcut: string;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue