一些检查失败了
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
40 行
1.4 KiB
TypeScript
40 行
1.4 KiB
TypeScript
import CommandService, { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
|
|
import { _ } from '@joplin/lib/locale';
|
|
import { Mode } from '../../../plugins/GotoAnything';
|
|
import { GotoAnythingOptions, UiType } from './gotoAnything';
|
|
import { ModelType } from '@joplin/lib/BaseModel';
|
|
import Logger from '@joplin/utils/Logger';
|
|
import markdownUtils from '@joplin/lib/markdownUtils';
|
|
|
|
const logger = Logger.create('linkToNote');
|
|
|
|
export const declaration: CommandDeclaration = {
|
|
name: 'linkToNote',
|
|
label: () => _('Link to note...'),
|
|
iconName: 'fas fa-file-export',
|
|
};
|
|
|
|
export const runtime = (): CommandRuntime => {
|
|
return {
|
|
execute: async (_context: CommandContext) => {
|
|
const options: GotoAnythingOptions = {
|
|
mode: Mode.TitleOnly,
|
|
alwaysShowHelp: true,
|
|
};
|
|
const result = await CommandService.instance().execute('gotoAnything', UiType.ControlledApi, options);
|
|
if (!result) return result;
|
|
|
|
if (result.type !== ModelType.Note) {
|
|
logger.warn('Retrieved item is not a note:', result);
|
|
return null;
|
|
}
|
|
|
|
const link = `[${markdownUtils.escapeTitleText(result.item.title)}](:/${markdownUtils.escapeLinkUrl(result.item.id)})`;
|
|
await CommandService.instance().execute('insertText', link);
|
|
return result;
|
|
},
|
|
|
|
enabledCondition: 'oneNoteSelected && (markdownEditorPaneVisible || richTextEditorVisible) && !noteIsReadOnly && !noteIsDeleted',
|
|
};
|
|
};
|