mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-02-20 15:43:58 -05:00
* Fixing copy, cut and paste * Bug on duplicating files without extensions * Fix paste only ignoring the location origin when validating relative paths - Add Error handling to all context menu actions - Hide FS actions in Overview and MediaView - Remove redundant useExplorerSearchParams - Add default schema to the Zod param hooks * Hide FS actions in all Explorers but location ones - Fix react warnings in RenameTextBox - Fix ReactTextBox not selecting the whole file name, instead of just up to file extension - Fix react warning due to inputing missing onChange * basic show jobs for cut, copy and delete in job manager * tweaks * Fixing some warnings and minor tweaks * Rust fmt * Fix cut between locations on Linux * Change how routes retrieve route params - Replace useZodRouteParams with useLoader - Define all schemas in the router file instead of in the route Component - Parse schema in loader to avoid requiring the route Components having to import the schema from the router file * Remove default argument from useZodRouteParams --------- Co-authored-by: Vítor Vasconcellos <vasconcellos.dev@gmail.com> Co-authored-by: Jamie Pine <32987599+jamiepine@users.noreply.github.com> Co-authored-by: James Pine <ijamespine@me.com>
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { ModifierKeys, keySymbols, modifierSymbols } from '@sd/ui';
|
|
import { OperatingSystem } from '../util/Platform';
|
|
|
|
function capitalize<T extends string>(string: T): Capitalize<T> {
|
|
return (string.charAt(0).toUpperCase() + string.slice(1)) as Capitalize<T>;
|
|
}
|
|
|
|
export function keybind<T extends string>(
|
|
modifers: ModifierKeys[],
|
|
keys: T[],
|
|
tauriOs: OperatingSystem
|
|
) {
|
|
if (keys.length === 0) return '';
|
|
|
|
const os = tauriOs === 'macOS' ? 'macOS' : tauriOs === 'windows' ? 'Windows' : 'Other';
|
|
|
|
const keySymbol = keys.map(capitalize).map((key) => {
|
|
const symbol = keySymbols[key];
|
|
return symbol ? symbol[os] ?? symbol.Other : key;
|
|
});
|
|
|
|
if (os === 'macOS' && !modifers.includes(ModifierKeys.Meta)) {
|
|
const index = modifers.findIndex((modifier) => modifier === ModifierKeys.Control);
|
|
if (index !== -1) modifers[index] = ModifierKeys.Meta;
|
|
}
|
|
|
|
const modifierSymbol = modifers.map((modifier) => {
|
|
const symbol = modifierSymbols[modifier];
|
|
return symbol[os] ?? symbol.Other;
|
|
});
|
|
|
|
return [...modifierSymbol, ...keySymbol].join(os === 'macOS' ? '' : '+');
|
|
}
|
|
|
|
export function keybindForOs(
|
|
os: OperatingSystem
|
|
): (modifers: ModifierKeys[], keys: string[]) => string {
|
|
return (modifers: ModifierKeys[], keys: string[]) => keybind(modifers, keys, os);
|
|
}
|