Skip to content

Commit 46d7ca9

Browse files
feature: Add keyboard shortcuts for goto def & find all refs (#329)
1 parent 9227b3c commit 46d7ca9

File tree

2 files changed

+80
-20
lines changed

2 files changed

+80
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111
- Added copy button for filenames. [#328](https://github.com/sourcebot-dev/sourcebot/pull/328)
1212
- Added development docker compose file. [#328](https://github.com/sourcebot-dev/sourcebot/pull/328)
13+
- Added keyboard shortcuts for find all refs / go to def. [#329](https://github.com/sourcebot-dev/sourcebot/pull/329)
1314
- Added GCP IAP JIT provisioning. [#330](https://github.com/sourcebot-dev/sourcebot/pull/330)
1415

1516
### Fixed

packages/web/src/ee/features/codeNav/components/symbolHoverPopup/index.tsx

Lines changed: 79 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import { useCallback, useEffect, useRef, useState } from "react";
88
import { SymbolDefinition, useHoveredOverSymbolInfo } from "./useHoveredOverSymbolInfo";
99
import { SymbolDefinitionPreview } from "./symbolDefinitionPreview";
1010
import { createPortal } from "react-dom";
11+
import { useHotkeys } from "react-hotkeys-hook";
12+
import { useToast } from "@/components/hooks/use-toast";
13+
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
14+
import { KeyboardShortcutHint } from "@/app/components/keyboardShortcutHint";
1115

1216
interface SymbolHoverPopupProps {
1317
editorRef: ReactCodeMirrorRef;
@@ -26,6 +30,7 @@ export const SymbolHoverPopup: React.FC<SymbolHoverPopupProps> = ({
2630
}) => {
2731
const ref = useRef<HTMLDivElement>(null);
2832
const [isSticky, setIsSticky] = useState(false);
33+
const { toast } = useToast();
2934

3035
const symbolInfo = useHoveredOverSymbolInfo({
3136
editorRef,
@@ -94,6 +99,36 @@ export const SymbolHoverPopup: React.FC<SymbolHoverPopupProps> = ({
9499
}
95100
}, [symbolInfo, onGotoDefinition]);
96101

102+
useHotkeys('alt+shift+f12', () => {
103+
if (symbolInfo?.symbolName) {
104+
console.log('here!');
105+
onFindReferences(symbolInfo.symbolName);
106+
}
107+
}, {
108+
enableOnFormTags: true,
109+
enableOnContentEditable: true,
110+
description: "Open Explore Panel",
111+
});
112+
113+
useHotkeys('alt+f12', () => {
114+
if (!symbolInfo) {
115+
return;
116+
}
117+
118+
if (!symbolInfo.symbolDefinitions || symbolInfo.symbolDefinitions.length === 0) {
119+
toast({
120+
description: "No definition found for this symbol",
121+
});
122+
return;
123+
}
124+
125+
onGotoDefinition();
126+
}, {
127+
enableOnFormTags: true,
128+
enableOnContentEditable: true,
129+
description: "Go to definition",
130+
})
131+
97132
if (!symbolInfo) {
98133
return null;
99134
}
@@ -122,26 +157,50 @@ export const SymbolHoverPopup: React.FC<SymbolHoverPopupProps> = ({
122157
)}
123158
<Separator />
124159
<div className="flex flex-row gap-2 mt-2">
125-
<LoadingButton
126-
loading={symbolInfo.isSymbolDefinitionsLoading}
127-
disabled={!symbolInfo.symbolDefinitions || symbolInfo.symbolDefinitions.length === 0}
128-
variant="outline"
129-
size="sm"
130-
onClick={onGotoDefinition}
131-
>
132-
{
133-
!symbolInfo.isSymbolDefinitionsLoading && (!symbolInfo.symbolDefinitions || symbolInfo.symbolDefinitions.length === 0) ?
134-
"No definition found" :
135-
`Go to ${symbolInfo.symbolDefinitions && symbolInfo.symbolDefinitions.length > 1 ? "definitions" : "definition"}`
136-
}
137-
</LoadingButton>
138-
<Button
139-
variant="outline"
140-
size="sm"
141-
onClick={() => onFindReferences(symbolInfo.symbolName)}
142-
>
143-
Find references
144-
</Button>
160+
<Tooltip delayDuration={500}>
161+
<TooltipTrigger asChild>
162+
<LoadingButton
163+
loading={symbolInfo.isSymbolDefinitionsLoading}
164+
disabled={!symbolInfo.symbolDefinitions || symbolInfo.symbolDefinitions.length === 0}
165+
variant="outline"
166+
size="sm"
167+
onClick={onGotoDefinition}
168+
>
169+
{
170+
!symbolInfo.isSymbolDefinitionsLoading && (!symbolInfo.symbolDefinitions || symbolInfo.symbolDefinitions.length === 0) ?
171+
"No definition found" :
172+
`Go to ${symbolInfo.symbolDefinitions && symbolInfo.symbolDefinitions.length > 1 ? "definitions" : "definition"}`
173+
}
174+
</LoadingButton>
175+
</TooltipTrigger>
176+
<TooltipContent
177+
side="bottom"
178+
className="flex flex-row items-center gap-2"
179+
>
180+
<KeyboardShortcutHint shortcut="⌥ F12" />
181+
<Separator orientation="vertical" className="h-4" />
182+
<span>{`Go to ${symbolInfo.symbolDefinitions && symbolInfo.symbolDefinitions.length > 1 ? "definitions" : "definition"}`}</span>
183+
</TooltipContent>
184+
</Tooltip>
185+
<Tooltip delayDuration={500}>
186+
<TooltipTrigger asChild>
187+
<Button
188+
variant="outline"
189+
size="sm"
190+
onClick={() => onFindReferences(symbolInfo.symbolName)}
191+
>
192+
Find references
193+
</Button>
194+
</TooltipTrigger>
195+
<TooltipContent
196+
side="bottom"
197+
className="flex flex-row items-center gap-2"
198+
>
199+
<KeyboardShortcutHint shortcut="⌥ ⇧ F12" />
200+
<Separator orientation="vertical" className="h-4" />
201+
<span>Find references</span>
202+
</TooltipContent>
203+
</Tooltip>
145204
</div>
146205
</div>,
147206
document.body

0 commit comments

Comments
 (0)