一些检查失败了
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
42 行
1.8 KiB
TypeScript
42 行
1.8 KiB
TypeScript
import CommandService, { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService';
|
|
import { _ } from '@joplin/lib/locale';
|
|
import Folder from '@joplin/lib/models/Folder';
|
|
import Note from '@joplin/lib/models/Note';
|
|
import { defaultWindowId, stateUtils } from '@joplin/lib/reducer';
|
|
import { getDisplayParentId } from '@joplin/lib/services/trash';
|
|
import bridge from '../../../services/bridge';
|
|
|
|
export const declaration: CommandDeclaration = {
|
|
name: 'revealInNotebook',
|
|
label: () => _('Reveal in notebook'),
|
|
};
|
|
|
|
export const runtime = (): CommandRuntime => {
|
|
return {
|
|
execute: async (context: CommandContext, noteId: string = null) => {
|
|
noteId = noteId || stateUtils.selectedNoteId(context.state);
|
|
const note = await Note.load(noteId);
|
|
if (!note) throw new Error(`No such note: ${noteId}`);
|
|
const parentFolder = await Folder.load(note.parent_id);
|
|
const folderId = note.is_conflict && !note.deleted_time ? Folder.conflictFolderId() : getDisplayParentId(note, parentFolder);
|
|
const mainWindowState = stateUtils.windowStateById(context.state, defaultWindowId);
|
|
const folderAlreadySelected = mainWindowState.selectedFolderId === folderId;
|
|
const noteAlreadySelected = stateUtils.selectedNoteId(mainWindowState) === note.id;
|
|
|
|
context.dispatch({
|
|
type: 'WINDOW_FOCUS',
|
|
windowId: defaultWindowId,
|
|
});
|
|
context.dispatch({
|
|
type: 'FOLDER_AND_NOTE_SELECT',
|
|
folderId,
|
|
noteId: note.id,
|
|
});
|
|
bridge().switchToMainWindow();
|
|
if (folderAlreadySelected) await CommandService.instance().execute('focusElementSideBar');
|
|
if (folderAlreadySelected && noteAlreadySelected) await CommandService.instance().execute('focusElementNoteList', note.id);
|
|
},
|
|
enabledCondition: 'someNotesSelected && !multipleNotesSelected',
|
|
};
|
|
};
|