-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Desktop: Add dialog to select a note and link to it (#11891)
- Loading branch information
Showing
10 changed files
with
129 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/app-desktop/gui/WindowCommandsAndDialogs/commands/linkToNote.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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...'), | ||
}; | ||
|
||
export const runtime = (): CommandRuntime => { | ||
return { | ||
execute: async (_context: CommandContext) => { | ||
const options: GotoAnythingOptions = { | ||
mode: Mode.TitleOnly, | ||
}; | ||
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: 'markdownEditorPaneVisible || richTextEditorVisible', | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Link to note | ||
|
||
To create a link to a note, you have two options: | ||
|
||
## Create a Markdown link | ||
|
||
Simply create the link in Markdown, as described in the [Markdown guide](https://joplinapp.org/help/apps/markdown/#links-to-other-notes). | ||
|
||
## Use the "Link to note" dialog | ||
|
||
An easier way is to use the "Link to note" dialog - to do so open the dialog from **Tools => Link to note...**. Then type the note you would like to link to and press <kbd>Enter</kbd> when done. | ||
|
||
This will create a new link and insert it into your current note. |