Skip to content

Commit

Permalink
Add ctrl+k shortcut for go-to-line (#9715)
Browse files Browse the repository at this point in the history
  • Loading branch information
bvaughn authored Sep 11, 2023
1 parent 9e5a36f commit 52331f0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { KeyboardModifiersContextRoot } from "replay-next/src/contexts/KeyboardM
import { SourcesContext } from "replay-next/src/contexts/SourcesContext";
import { getSourceSuspends } from "replay-next/src/suspense/SourcesCache";
import { ReplayClientContext } from "shared/client/ReplayClientContext";
import { useGraphQLUserData } from "shared/user-data/GraphQL/useGraphQLUserData";
import { isMacOS } from "shared/utils/os";
import { getSelectedLocation, getSelectedLocationHasScrolled } from "ui/reducers/sources";
import { useAppDispatch, useAppSelector } from "ui/setup/hooks";

Expand Down Expand Up @@ -122,7 +122,9 @@ function NewSourceAdapter() {
break;
}
case "g": {
if (event.ctrlKey || event.metaKey) {
// CMD+G should continue an in-progress search
// CTRL+G is for go-to-line though
if (isMacOS() ? event.metaKey : event.ctrlKey) {
// Unlike Enter / Shift+Enter, this event handler is external to the Search input
// so that we can mirror UIs like Chrome and Code and re-open the search UI if it's been closed
sourceSearchActions.enable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ export function InspectorSearch() {
startFullTextSearch(searchText, e.shiftKey);
}

// Honestly I have no idea why this was in the original search logic.
// Apparently search if you hit CTRL+G? Weird combo.
// CMD+G should continue an in-progress search
// CTRL+G is for go-to-line though
const modifierKey = isMacOS() ? e.metaKey : e.ctrlKey;
if (e.key === "g" && modifierKey) {
startFullTextSearch(searchText, e.shiftKey);
Expand Down
16 changes: 15 additions & 1 deletion src/ui/components/KeyboardShortcuts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { userData } from "shared/user-data/GraphQL/UserData";
import { UIThunkAction, actions } from "ui/actions";
import { useGetRecordingId } from "ui/hooks/recordings";
import { selectors } from "ui/reducers";
import { getSelectedSource } from "ui/reducers/sources";
import { useAppSelector } from "ui/setup/hooks";
import { UIState } from "ui/state";
import { addGlobalShortcut, isEditableElement, removeGlobalShortcut } from "ui/utils/key-shortcuts";
import { trackEvent } from "ui/utils/telemetry";
Expand Down Expand Up @@ -61,6 +63,8 @@ function KeyboardShortcuts({
const { isAuthenticated } = useAuth0();
const [, dismissFindFileNag] = useNag(Nag.FIND_FILE);

const selectedSource = useAppSelector(getSelectedSource);

const [protocolTimeline] = useGraphQLUserData("feature_protocolTimeline");
const globalKeyboardShortcuts = useMemo(() => {
const openFullTextSearch = (e: KeyboardEvent) => {
Expand All @@ -86,6 +90,12 @@ function KeyboardShortcuts({
toggleQuickOpenModal(e, "@");
};

const toggleGoToLine = (e: KeyboardEvent) => {
if (selectedSource) {
toggleQuickOpenModal(e, ":");
}
};

const toggleQuickOpenModal = (e: KeyboardEvent, query = "", project = false) => {
dismissFindFileNag();

Expand Down Expand Up @@ -172,8 +182,11 @@ function KeyboardShortcuts({

// Quick Open-related toggles
"CmdOrCtrl+Shift+P": toggleQuickOpenModal,
// We apparently accept this with or without a Shift key currently
"CmdOrCtrl+P": toggleQuickOpenModal,

// Go to line
"Ctrl+K": toggleGoToLine,

// Can pre-fill the dialog with specific filter prefixes
"CmdOrCtrl+Shift+O": toggleFunctionQuickOpenModal,
"CmdOrCtrl+O": toggleProjectFunctionQuickOpenModal,
Expand Down Expand Up @@ -201,6 +214,7 @@ function KeyboardShortcuts({
jumpToPreviousPause,
jumpToNextPause,
dismissFindFileNag,
selectedSource,
]);

useEffect(() => {
Expand Down

1 comment on commit 52331f0

@vercel
Copy link

@vercel vercel bot commented on 52331f0 Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

devtools – ./

devtools-recordreplay.vercel.app
devtools-git-main-recordreplay.vercel.app
app.replay.io

Please sign in to comment.