Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Sep 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/public/app/widgets/type_widgets/editable_text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}
Expand Down
6 changes: 6 additions & 0 deletions src/services/keyboard_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
1 change: 1 addition & 0 deletions src/views/dialogs/help.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down