Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"eslint-plugin-prettier": "^2.0.1",
"expect.js": "^0.3.1",
"firefox-profile": "^0.4.8",
"flow-bin": "^0.40.0",
"flow-bin": "^0.41.0",
"fuzzaldrin-plus": "^0.4.1",
"glob": "^7.0.3",
"husky": "^0.13.1",
Expand Down
53 changes: 33 additions & 20 deletions src/components/Editor/SearchBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const SearchBar = React.createClass({
componentDidMount() {
// overwrite searchContents with a debounced version to reduce the
// frequency of queries which improves perf on large files
// $FlowIgnore
this.searchContents = debounce(this.searchContents, 100);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @jasonLaster

Here I disable flow to suppress the error. Are we okay with this approach?
screen shot 2017-03-27 at 3 16 43 pm


const shortcuts = this.context.shortcuts;
Expand Down Expand Up @@ -136,9 +137,10 @@ const SearchBar = React.createClass({

componentDidUpdate(prevProps: any, prevState: any) {
const { sourceText, selectedSource, query, modifiers } = this.props;
const searchInput = this.searchInput();

if (this.searchInput()) {
this.searchInput().focus();
if (searchInput) {
searchInput.focus();
}

if (this.refs.resultList && this.refs.resultList.refs) {
Expand All @@ -152,7 +154,8 @@ const SearchBar = React.createClass({
const doneLoading = wasLoading && hasLoaded;
const changedFiles = selectedSource != prevProps.selectedSource &&
hasLoaded;
const modifiersUpdated = !modifiers.equals(prevProps.modifiers);
const modifiersUpdated = modifiers &&
!modifiers.equals(prevProps.modifiers);

const isOpen = this.props.searchOn || this.state.symbolSearchEnabled;
const { selectedSymbolType, symbolSearchEnabled } = this.state;
Expand All @@ -174,7 +177,7 @@ const SearchBar = React.createClass({

clearSearch() {
const { editor: ed, query, modifiers } = this.props;
if (ed) {
if (ed && modifiers) {
const ctx = { ed, cm: ed.codeMirror };
removeOverlay(ctx, query, modifiers.toJS());
}
Expand Down Expand Up @@ -260,22 +263,30 @@ const SearchBar = React.createClass({
},

setSearchValue(value: string) {
if (value == "") {
const searchInput = this.searchInput();
if (value == "" || !searchInput) {
return;
}

this.searchInput().value = value;
searchInput.value = value;
},

selectSearchInput() {
const node = this.searchInput();
if (node) {
node.setSelectionRange(0, node.value.length);
const searchInput = this.searchInput();
if (searchInput) {
searchInput.setSelectionRange(0, searchInput.value.length);
}
},

searchInput() {
return findDOMNode(this).querySelector("input");
searchInput(): ?HTMLInputElement {
const node = findDOMNode(this);
if (node instanceof HTMLElement) {
const input = node.querySelector("input");
if (input instanceof HTMLInputElement) {
return input;
}
}
return null;
},

async updateSymbolSearchResults(query: string) {
Expand Down Expand Up @@ -327,7 +338,7 @@ const SearchBar = React.createClass({
searchResults: { index },
} = this.props;

if (!ed || !sourceText || !sourceText.get("text")) {
if (!ed || !sourceText || !sourceText.get("text") || !modifiers) {
return;
}

Expand Down Expand Up @@ -373,16 +384,18 @@ const SearchBar = React.createClass({
this.props.toggleFileSearch(true);
}

if (index == -1) {
if (index == -1 && modifiers) {
clearIndex(ctx, query, modifiers.toJS());
}

const findFnc = rev ? findPrev : findNext;
const newIndex = findFnc(ctx, query, true, modifiers.toJS());
updateSearchResults({
index: newIndex,
count,
});
if (modifiers) {
const findFnc = rev ? findPrev : findNext;
const newIndex = findFnc(ctx, query, true, modifiers.toJS());
updateSearchResults({
index: newIndex,
count,
});
}
},

// Handlers
Expand Down Expand Up @@ -503,7 +516,7 @@ const SearchBar = React.createClass({
return dom.button(
{
className: classnames(className, {
active: !symbolSearchEnabled && modifiers.get(modVal),
active: !symbolSearchEnabled && modifiers && modifiers.get(modVal),
disabled: symbolSearchEnabled,
}),
onClick: () =>
Expand Down
19 changes: 11 additions & 8 deletions src/components/Editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@ const Editor = React.createClass({
// disables the default search shortcuts
this.editor._initShortcuts = () => {};

this.editor.appendToLocalElement(
ReactDOM.findDOMNode(this).querySelector(".editor-mount")
);
const node = ReactDOM.findDOMNode(this);
if (node instanceof HTMLElement) {
this.editor.appendToLocalElement(node.querySelector(".editor-mount"));
}

const codeMirror = this.editor.codeMirror;
const codeMirrorWrapper = codeMirror.getWrapperElement();
Expand Down Expand Up @@ -189,10 +190,12 @@ const Editor = React.createClass({
});

const searchAgainKey = L10N.getStr("sourceSearch.search.again.key");
shortcuts.on(`CmdOrCtrl+Shift+${searchAgainKey}`, (_, e) =>
traverseResults(e, ctx, query, "prev", searchModifiers.toJS()));
shortcuts.on(`CmdOrCtrl+${searchAgainKey}`, (_, e) =>
traverseResults(e, ctx, query, "next", searchModifiers.toJS()));
if (searchModifiers) {
shortcuts.on(`CmdOrCtrl+Shift+${searchAgainKey}`, (_, e) =>
traverseResults(e, ctx, query, "prev", searchModifiers.toJS()));
shortcuts.on(`CmdOrCtrl+${searchAgainKey}`, (_, e) =>
traverseResults(e, ctx, query, "next", searchModifiers.toJS()));
}

resizeBreakpointGutter(codeMirror);
debugGlobal("cm", codeMirror);
Expand Down Expand Up @@ -540,7 +543,7 @@ const Editor = React.createClass({
const { breakpoints, sourceText } = this.props;
const isLoading = sourceText && sourceText.get("loading");

if (isLoading) {
if (isLoading || !breakpoints) {
return;
}

Expand Down
12 changes: 8 additions & 4 deletions src/components/SecondaryPanes/CommandBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ function handlePressAnimation(button) {
button.style.transform = "scale(1.3)";
setTimeout(
() => {
button.style.opacity = "1";
button.style.transform = "none";
if (button) {
button.style.opacity = "1";
button.style.transform = "none";
}
},
200
);
Expand Down Expand Up @@ -126,8 +128,10 @@ class CommandBar extends Component {
e.stopPropagation();

this.props[action]();
const button = findDOMNode(this).querySelector(`.${action}`);
handlePressAnimation(button);
const node = findDOMNode(this);
if (node instanceof HTMLElement) {
handlePressAnimation(node.querySelector(`.${action}`));
}
}

renderStepButtons() {
Expand Down
11 changes: 8 additions & 3 deletions src/components/shared/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ const Autocomplete = React.createClass({

componentDidMount() {
const endOfInput = this.state.inputValue.length;
const searchInput = findDOMNode(this).querySelector("input");
searchInput.focus();
searchInput.setSelectionRange(endOfInput, endOfInput);
const node = findDOMNode(this);
if (node instanceof HTMLElement) {
const searchInput = node.querySelector("input");
if (searchInput instanceof HTMLInputElement) {
searchInput.focus();
searchInput.setSelectionRange(endOfInput, endOfInput);
}
}
},

componentDidUpdate() {
Expand Down
Loading