mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-15 09:04:04 +02:00
32 lines
993 B
TypeScript
32 lines
993 B
TypeScript
import { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
|
|
import { _ } from '@joplin/lib/locale';
|
|
import layoutItemProp from '../../ResizableLayout/utils/layoutItemProp';
|
|
import { AppState } from '../../../app';
|
|
|
|
export const declaration: CommandDeclaration = {
|
|
name: 'focusElementSideBar',
|
|
label: () => _('Sidebar'),
|
|
parentLabel: () => _('Focus'),
|
|
};
|
|
|
|
export const runtime = (comp: any): CommandRuntime => {
|
|
return {
|
|
execute: async (context: CommandContext) => {
|
|
const sidebarVisible = layoutItemProp((context.state as AppState).mainLayout, 'sideBar', 'visible');
|
|
|
|
if (sidebarVisible) {
|
|
const item = comp.selectedItem();
|
|
if (item) {
|
|
const anchorRef = comp.anchorItemRefs[item.type][item.id];
|
|
if (anchorRef) anchorRef.current.focus();
|
|
} else {
|
|
const anchorRef = comp.firstAnchorItemRef('folder');
|
|
if (anchorRef) anchorRef.current.focus();
|
|
}
|
|
}
|
|
},
|
|
|
|
enabledCondition: 'sideBarVisible',
|
|
};
|
|
};
|