Skip to content

Commit

Permalink
feat: open link in adjacent/new editor column (#81)
Browse files Browse the repository at this point in the history
- open link in the next column of active editor.
- bind to hotkey <kbd>ctrl</kbd> + <kbd>shift</kbd> + <kbd>enter</kbd>.
  • Loading branch information
ez4gis committed Jan 10, 2021
1 parent 7cfad0f commit 8c9c260
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"onCommand:memo.openRandomNote",
"onCommand:memo.openDailyNote",
"onCommand:memo.openReferenceInDefaultApp",
"onCommand:memo.openLinkInNextColumn",
"onCommand:_memo.openReference",
"onCommand:_memo.cacheWorkspace",
"onCommand:_memo.cleanWorkspaceCache",
Expand All @@ -59,6 +60,11 @@
"command": "memo.openReferenceInDefaultApp",
"title": "Open link in the default app",
"category": "Memo"
},
{
"command": "memo.openLinkInNextColumn",
"title": "Open link in the next column of this editor",
"category": "Memo"
}
],
"configuration": {
Expand Down Expand Up @@ -146,6 +152,12 @@
"key": "ctrl+enter",
"mac": "cmd+enter",
"when": "editorTextFocus && editorLangId == markdown"
},
{
"command": "memo.openLinkInNextColumn",
"key": "ctrl+shift+enter",
"mac": "cmd+shift+enter",
"when": "editorTextFocus && editorLangId == markdown"
}
],
"menus": {
Expand All @@ -160,6 +172,10 @@
{
"command": "memo.openReferenceInDefaultApp",
"when": "editorLangId == markdown && memo:refUnderCursorExists"
},
{
"command": "memo.openLinkInNextColumn",
"when": "editorLangId == markdown "
}
]
},
Expand Down
2 changes: 2 additions & 0 deletions src/commands/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import vscode from 'vscode';
import openDocumentByReference from './openDocumentByReference';
import openRandomNote from './openRandomNote';
import openReferenceInDefaultApp from './openReferenceInDefaultApp';
import openLinkInNextColumn from './openLinkInNextColumn';
import openDailyNote from './openDailyNote';
import { cacheWorkspace, cleanWorkspaceCache, getWorkspaceCache } from '../utils';

Expand All @@ -14,6 +15,7 @@ const commands = [
vscode.commands.registerCommand('memo.openRandomNote', openRandomNote),
vscode.commands.registerCommand('memo.openDailyNote', openDailyNote),
vscode.commands.registerCommand('memo.openReferenceInDefaultApp', openReferenceInDefaultApp),
vscode.commands.registerCommand('memo.openLinkInNextColumn', openLinkInNextColumn),
];

export default commands;
10 changes: 8 additions & 2 deletions src/commands/openDocumentByReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ import {
getWorkspaceFolder,
} from '../utils';

const openDocumentByReference = async ({ reference }: { reference: string }) => {
const openDocumentByReference = async ({
reference,
showOption = vscode.ViewColumn.Active,
}: {
reference: string;
showOption?: vscode.ViewColumn | { preserveFocus: boolean; viewColumn: vscode.ViewColumn };
}) => {
const { ref } = parseRef(reference);

const uri = findUriByRef(getWorkspaceCache().allUris, ref);

if (uri) {
await vscode.commands.executeCommand('vscode.open', uri);
await vscode.commands.executeCommand('vscode.open', uri, showOption);
} else {
const workspaceFolder = getWorkspaceFolder()!;
if (workspaceFolder) {
Expand Down
24 changes: 24 additions & 0 deletions src/commands/openLinkInNextColumn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import vscode, { commands } from 'vscode';

import { getReferenceAtPosition } from '../utils';

const openLinkInNextColumn = async () => {
const activeTextEditor = vscode.window.activeTextEditor;
if (!activeTextEditor) {
return;
}

const refObj = getReferenceAtPosition(
activeTextEditor.document,
activeTextEditor.selection.start,
);

if (refObj && refObj.ref) {
commands.executeCommand('_memo.openDocumentByReference', {
reference: refObj.ref,
showOption: vscode.ViewColumn.Beside,
});
}
};

export default openLinkInNextColumn;

0 comments on commit 8c9c260

Please sign in to comment.