Skip to content

Commit

Permalink
flash function when it is copied - feature firefox-devtools#4022 (fir…
Browse files Browse the repository at this point in the history
…efox-devtools#4634)

added flash action
  • Loading branch information
borian authored and Johnny Khalil committed Nov 12, 2017
1 parent c4f0089 commit c20f82b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/actions/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ export function highlightLineRange(location: {
};
}

export function flashLineRange(location: {
start: number,
end: number,
sourceId: number
}) {
return ({ dispatch }: ThunkArgs) => {
dispatch(highlightLineRange(location));
setTimeout(() => dispatch(clearHighlightLineRange()), 200);
};
}

/**
* @memberof actions/sources
* @static
Expand Down
23 changes: 20 additions & 3 deletions src/components/Editor/EditorMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getSourceLocationFromMouseEvent } from "../../utils/editor";
import { bindActionCreators } from "redux";
import { connect } from "react-redux";
import { findFunctionText } from "../../utils/function";
import { findClosestScope } from "../../utils/breakpoint/astBreakpointLocation";
import {
getContextMenu,
getSelectedLocation,
Expand All @@ -18,6 +19,7 @@ import {
} from "../../selectors";

import actions from "../../actions";

type Props = {
setContextMenu: Function
};
Expand All @@ -33,7 +35,9 @@ function getMenuItems(
jumpToMappedLocation,
toggleBlackBox,
addExpression,
getFunctionText
getFunctionText,
getFunctionLocation,
flashLineRange
}
) {
const copySourceLabel = L10N.getStr("copySource");
Expand Down Expand Up @@ -121,7 +125,15 @@ function getMenuItems(
label: copyFunctionLabel,
accesskey: copyFunctionKey,
disabled: !functionText,
click: () => copyToTheClipboard(functionText)
click: () => {
const { location: { start, end } } = getFunctionLocation(line);
flashLineRange({
start: start.line,
end: end.line,
sourceId: selectedLocation.sourceId
});
return copyToTheClipboard(functionText);
}
};

const menuItems = [
Expand Down Expand Up @@ -181,7 +193,12 @@ export default connect(
line,
selectedSource.toJS(),
getSymbols(state, selectedSource.toJS())
)
),
getFunctionLocation: line =>
findClosestScope(getSymbols(state, selectedSource.toJS()).functions, {
line,
column: Infinity
})
};
},
dispatch => bindActionCreators(actions, dispatch)
Expand Down

0 comments on commit c20f82b

Please sign in to comment.