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 ctrl+k shortcut for go-to-line #9715

Merged
merged 1 commit into from
Sep 11, 2023
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
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
Loading