Skip to content

Commit

Permalink
feat: Add memo:refFocusedOrHovered
Browse files Browse the repository at this point in the history
  • Loading branch information
ez4gis committed Jan 18, 2021
1 parent 30036d5 commit 9ce62a6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
"command": "memo.openReferenceBeside",
"key": "ctrl+shift+enter",
"mac": "cmd+shift+enter",
"when": "editorTextFocus && editorLangId == markdown"
"when": "editorTextFocus && editorLangId == markdown && memo:refFocusedOrHovered"
}
],
"menus": {
Expand All @@ -175,7 +175,7 @@
},
{
"command": "memo.openReferenceBeside",
"when": "editorLangId == markdown"
"when": "editorLangId == markdown && memo:refFocusedOrHovered"
}
]
},
Expand Down
6 changes: 4 additions & 2 deletions src/features/referenceContextWatcher.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { window, workspace, commands, ExtensionContext } from 'vscode';

import { getRefUriUnderCursor } from '../utils';
import { getRefUriUnderCursor, getRefUnderCursor, getReferenceAtPosition } from '../utils';

const updateRefExistsContext = () =>
const updateRefExistsContext = () => {
commands.executeCommand('setContext', 'memo:refUnderCursorExists', !!getRefUriUnderCursor());
commands.executeCommand('setContext', 'memo:refFocusedOrHovered', !!getRefUnderCursor());
};

export const activate = (context: ExtensionContext) => {
context.subscriptions.push(
Expand Down
11 changes: 10 additions & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,22 @@ export const ensureDirectoryExists = (filePath: string) => {
}
};

export const getRefUriUnderCursor = (): vscode.Uri | null | undefined => {
export const getRefUnderCursor = ():
| { range: vscode.Range; ref: string; label: string }
| null
| undefined => {
const activeTextEditor = vscode.window.activeTextEditor;

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

return refAtPos;
};

export const getRefUriUnderCursor = (): vscode.Uri | null | undefined => {
const refAtPos = getRefUnderCursor();

return refAtPos && findUriByRef(getWorkspaceCache().allUris, refAtPos.ref);
};

Expand Down

0 comments on commit 9ce62a6

Please sign in to comment.