Skip to content

Commit

Permalink
[DevTools] Add column number to viewSourceLineFunction (#24814)
Browse files Browse the repository at this point in the history
Add column number for `viewSourceLineFunction` and renamed the function to `viewUrlSourceFunction` to match the other source function naming conventions
  • Loading branch information
lunaruan authored Jun 29, 2022
1 parent f01e119 commit cd80d32
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions packages/react-devtools-extensions/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ function createPanelIfReactLoaded() {
}
};

const viewSourceLineFunction = (url, line) => {
chrome.devtools.panels.openResource(url, line);
const viewUrlSourceFunction = (url, line, col) => {
chrome.devtools.panels.openResource(url, line, col);
};

let debugIDCounter = 0;
Expand Down Expand Up @@ -395,7 +395,7 @@ function createPanelIfReactLoaded() {
warnIfUnsupportedVersionDetected: true,
viewAttributeSourceFunction,
viewElementSourceFunction,
viewSourceLineFunction,
viewUrlSourceFunction,
}),
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

import {createContext} from 'react';

import type {ViewSourceLine} from 'react-devtools-shared/src/devtools/views/DevTools';
import type {ViewUrlSource} from 'react-devtools-shared/src/devtools/views/DevTools';

export type Context = {|
viewSourceLineFunction: ViewSourceLine | null,
viewUrlSourceFunction: ViewUrlSource | null,
|};

const ViewSourceContext = createContext<Context>(((null: any): Context));
Expand Down
10 changes: 5 additions & 5 deletions packages/react-devtools-shared/src/devtools/views/DevTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export type ViewElementSource = (
id: number,
inspectedElement: InspectedElement,
) => void;
export type ViewSourceLine = (url: string, row: number, column: number) => void;
export type ViewUrlSource = (url: string, row: number, column: number) => void;
export type ViewAttributeSource = (
id: number,
path: Array<string | number>,
Expand All @@ -79,7 +79,7 @@ export type Props = {|
warnIfUnsupportedVersionDetected?: boolean,
viewAttributeSourceFunction?: ?ViewAttributeSource,
viewElementSourceFunction?: ?ViewElementSource,
viewSourceLineFunction?: ?ViewSourceLine,
viewUrlSourceFunction?: ?ViewUrlSource,
readOnly?: boolean,
hideSettings?: boolean,
hideToggleErrorAction?: boolean,
Expand Down Expand Up @@ -139,7 +139,7 @@ export default function DevTools({
warnIfUnsupportedVersionDetected = false,
viewAttributeSourceFunction,
viewElementSourceFunction,
viewSourceLineFunction,
viewUrlSourceFunction,
readOnly,
hideSettings,
hideToggleErrorAction,
Expand Down Expand Up @@ -205,11 +205,11 @@ export default function DevTools({

const viewSource = useMemo(
() => ({
viewSourceLineFunction: viewSourceLineFunction || null,
viewUrlSourceFunction: viewUrlSourceFunction || null,
// todo(blakef): Add inspect(...) method here and remove viewElementSource
// to consolidate source code inspection.
}),
[viewSourceLineFunction],
[viewUrlSourceFunction],
);

const contextMenu = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type Props = {||};

export default function SidebarEventInfo(_: Props) {
const {profilingData, selectedCommitIndex} = useContext(ProfilerContext);
const {viewSourceLineFunction} = useContext(ViewSourceContext);
const {viewUrlSourceFunction} = useContext(ViewSourceContext);

const {stack} = useMemo(() => {
if (
Expand Down Expand Up @@ -55,8 +55,8 @@ export default function SidebarEventInfo(_: Props) {
const hasSource = source != null;

const onClick = () => {
if (viewSourceLineFunction != null && source != null) {
viewSourceLineFunction(...source);
if (viewUrlSourceFunction != null && source != null) {
viewUrlSourceFunction(...source);
}
};

Expand Down

0 comments on commit cd80d32

Please sign in to comment.