一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
64 行
2.1 KiB
TypeScript
64 行
2.1 KiB
TypeScript
import { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
|
|
import { _ } from '@joplin/lib/locale';
|
|
import { GotoAnythingUserData, Mode, UserDataCallbackReject, UserDataCallbackResolve } from '../../../plugins/GotoAnything';
|
|
import PluginManager from '@joplin/lib/services/PluginManager';
|
|
|
|
export enum UiType {
|
|
GotoAnything = 'gotoAnything',
|
|
CommandPalette = 'commandPalette',
|
|
ControlledApi = 'controlledApi',
|
|
}
|
|
|
|
export interface GotoAnythingOptions {
|
|
mode?: Mode;
|
|
alwaysShowHelp?: boolean;
|
|
}
|
|
|
|
export const declaration: CommandDeclaration = {
|
|
name: 'gotoAnything',
|
|
label: () => _('Goto Anything...'),
|
|
};
|
|
|
|
interface PluginMenuItem {
|
|
id: string;
|
|
click: ()=> void;
|
|
userData?: GotoAnythingUserData;
|
|
}
|
|
|
|
function menuItemById(id: string): PluginMenuItem {
|
|
return PluginManager.instance().menuItems().find((i: PluginMenuItem) => i.id === id);
|
|
}
|
|
|
|
// The way this command is implemented is a bit hacky due to the PluginManager
|
|
// layer. This manager is no longer needed but hasn't been refactored yet, so in
|
|
// the meantime we access the GotoAnything actions by grabbing the menu item
|
|
// calling the click() handler.
|
|
export const runtime = (): CommandRuntime => {
|
|
return {
|
|
execute: async (_context: CommandContext, uiType: UiType = UiType.GotoAnything, options: GotoAnythingOptions = null) => {
|
|
options = {
|
|
mode: Mode.Default,
|
|
...options,
|
|
};
|
|
|
|
if (uiType === UiType.GotoAnything) {
|
|
menuItemById('gotoAnything').click();
|
|
} else if (uiType === UiType.CommandPalette) {
|
|
menuItemById('commandPalette').click();
|
|
} else if (uiType === UiType.ControlledApi) {
|
|
return new Promise((resolve: UserDataCallbackResolve, reject: UserDataCallbackReject) => {
|
|
const menuItem: PluginMenuItem = PluginManager.instance().menuItems().find((i: PluginMenuItem) => i.id === 'controlledApi');
|
|
const userData: GotoAnythingUserData = {
|
|
callback: { resolve, reject },
|
|
mode: options.mode,
|
|
alwaysShowHelp: options.alwaysShowHelp,
|
|
};
|
|
menuItem.userData = userData;
|
|
menuItem.click();
|
|
});
|
|
}
|
|
return null;
|
|
},
|
|
};
|
|
};
|