Add shortcut to follow link under text cursor (#1842) (#2148)

This commit is contained in:
Egor Dubenetskiy 2021-09-05 13:24:38 +03:00 committed by GitHub
parent 5cfd1c030d
commit 061f8acf11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 0 deletions

View File

@ -7,6 +7,8 @@ import froca from "../../services/froca.js";
import treeService from "../../services/tree.js";
import noteCreateService from "../../services/note_create.js";
import AbstractTextTypeWidget from "./abstract_text_type_widget.js";
import link from "../../services/link.js";
import appContext from "../../services/app_context.js";
const ENABLE_INSPECTOR = false;
@ -254,6 +256,21 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
return text;
}
async followLinkUnderCursorCommand() {
await this.initialized;
const selection = this.textEditor.model.document.selection;
if (!selection.hasAttribute('linkHref')) return;
const selectedLinkUrl = selection.getAttribute('linkHref');
const notePath = link.getNotePathFromUrl(selectedLinkUrl);
if (notePath) {
await appContext.tabManager.getActiveContext().setNote(notePath);
} else {
window.open(selectedLinkUrl, '_blank');
}
}
addIncludeNoteToTextCommand() {
import("../../dialogs/include_note.js").then(d => d.showDialog(this));
}

View File

@ -284,6 +284,12 @@ const DEFAULT_KEYBOARD_ACTIONS = [
description: "Open dialog to add link to the text",
scope: "text-detail"
},
{
actionName: "followLinkUnderCursor",
defaultShortcuts: ["CommandOrControl+Enter"],
description: "Follow link within which the caret is placed",
scope: "text-detail"
},
{
actionName: "insertDateTimeToText",
defaultShortcuts: ["Alt+T"],

View File

@ -93,6 +93,7 @@
<kbd data-command="scrollToActiveNote">not set</kbd> will switch back from editor to tree pane.</li>
<li><kbd>Ctrl+K</kbd> - create / edit external link</li>
<li><kbd data-command="addLinkToText">not set</kbd> - create internal link</li>
<li><kbd data-command="followLinkUnderCursor">not set</kbd> - follow link under cursor</li>
<li><kbd data-command="insertDateTimeToText">not set</kbd> - insert current date and time at caret position</li>
<li><kbd data-command="scrollToActiveNote">not set</kbd> - jump away to the tree pane and scroll to active note</li>
</ul>