1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-12 08:54:00 +02:00
joplin/packages/app-desktop/gui/SideBar/commands/focusElementSideBar.ts

30 lines
811 B
TypeScript
Raw Normal View History

2020-11-05 18:58:23 +02:00
import { CommandRuntime, CommandDeclaration } from '@joplinapp/lib/services/CommandService';
import { _ } from '@joplinapp/lib/locale';
export const declaration:CommandDeclaration = {
name: 'focusElementSideBar',
label: () => _('Sidebar'),
parentLabel: () => _('Focus'),
};
export const runtime = (comp:any):CommandRuntime => {
return {
2020-11-05 18:58:23 +02:00
execute: async (context:any) => {
const sideBarVisible = !!context.state.sidebarVisibility;
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',
};
};