[WatchExpressions] Autocomplete for editing watch expressions
Can we please add the functionality to have autocomplete, when editing a watch expression in the debugger tab?
Here is the actor endpoint
https://searchfox.org/mozilla-central/source/devtools/server/actors/webconsole.js#1068
Here is the client support for the webconsole
https://dxr.mozilla.org/mozilla-central/source/devtools/client/webconsole/components/JSTerm.js#1513-1535
It'd be fun to see if someone wants to try and prototype this feature in the debugger. Perhaps without a UI.
/claim
Thanks for claiming the issue! :wave:
Here are some links for getting setup, contributing, and developing. We're always happy to answer questions in slack! If you become busy, feel free to /unclaim it.
:fox_face: Debugger team!
So some of the things we need to do here
- [x] Add client api for autocomplete support #6177
- [x] Add UI for autocomplete functionality behind a flag #6465
- [ ] Support caching to improve perf
- [ ] Improve UI functionality (styling, UX)
@bomsy I seen your changes, good work! Can I help about the UI? Have you thought any solutions about it?
Hey @marcogallo566 , yes i've got a solution for it. Sure you can help ... i'll write out a diff for you to start off with in a bit.
@bomsy Any news about the UI?
@marcogallo566 Hey marco .. sorry being busy.. will do it today!
Hey @marcogallo566
Hey is a gif of the my idea of what this will look like

Hey @marcogallo566
Here is my start on it. This diff is quite buggy so u'll have to fix some of the issues. if you need any help! Let us know in the slack channel!
Cheers!
diff --git a/src/components/SecondaryPanes/Expressions.js b/src/components/SecondaryPanes/Expressions.js
index fe188555..e8e15693 100644
--- a/src/components/SecondaryPanes/Expressions.js
+++ b/src/components/SecondaryPanes/Expressions.js
@@ -9,10 +9,16 @@ import classnames from "classnames";
import { ObjectInspector } from "devtools-reps";
import actions from "../../actions";
-import { getExpressions, getExpressionError } from "../../selectors";
+import {
+ getExpressions,
+ getExpressionError,
+ getAutocompleteMatchset
+} from "../../selectors";
import { getValue } from "../../utils/expressions";
import { createObjectClient } from "../../client/firefox";
+import { debounce } from "lodash";
+
import CloseButton from "../shared/Button/Close";
import type { List } from "immutable";
@@ -37,7 +43,9 @@ type Props = {
deleteExpression: (expression: Expression) => void,
openLink: (url: string) => void,
showInput: boolean,
- onExpressionAdded: () => void
+ onExpressionAdded: () => void,
+ autocomplete: (input: string, cursor: number) => void,
+ autocompleteMatches: array
};
class Expressions extends Component<Props, State> {
@@ -125,9 +133,16 @@ class Expressions extends Component<Props, State> {
}
handleChange = (e: SyntheticInputEvent<HTMLInputElement>) => {
- this.setState({ inputValue: e.target.value });
+ const target = e.target;
+ this.setState({ inputValue: target.value });
+ this.findAutocompleteMatches(target);
};
+ findAutocompleteMatches = debounce(target => {
+ console.log(this.props.autocompleteMatches);
+ this.props.autocomplete(target.value, target.selectionStart);
+ }, 250);
+
handleKeyDown = (e: SyntheticKeyboardEvent<HTMLInputElement>) => {
if (e.key === "Escape") {
this.clear();
@@ -225,6 +240,22 @@ class Expressions extends Component<Props, State> {
);
};
+ renderAutoCompleteMatches() {
+ const { autocompleteMatches } = this.props;
+ if (autocompleteMatches) {
+ return (
+ <datalist id="autocomplete-matches">
+ {autocompleteMatches.map((match, index) => {
+ console.log(match, index);
+ return <option key={index} value={match} />;
+ })}
+ </datalist>
+ );
+ } else {
+ return <datalist id="autocomplete-matches" />;
+ }
+ }
+
renderNewExpressionInput() {
const { expressionError, showInput } = this.props;
const { editing, inputValue, focused } = this.state;
@@ -249,7 +280,9 @@ class Expressions extends Component<Props, State> {
autoFocus={showInput}
value={!editing ? inputValue : ""}
ref={c => (this._input = c)}
+ list="autocomplete-matches"
/>
+ {this.renderAutoCompleteMatches()}
<input type="submit" style={{ display: "none" }} />
</form>
</li>
@@ -281,7 +314,9 @@ class Expressions extends Component<Props, State> {
onFocus={this.onFocus}
value={editing ? inputValue : expression.input}
ref={c => (this._input = c)}
+ list="autocomplete-matches"
/>
+ {this.renderAutoCompleteMatches()}
<input type="submit" style={{ display: "none" }} />
</form>
</span>
@@ -301,6 +336,7 @@ class Expressions extends Component<Props, State> {
}
const mapStateToProps = state => ({
+ autocompleteMatches: getAutocompleteMatchset(state),
expressions: getExpressions(state),
expressionError: getExpressionError(state)
});
diff --git a/src/reducers/expressions.js b/src/reducers/expressions.js
index 8de35c1a..8aa798d9 100644
--- a/src/reducers/expressions.js
+++ b/src/reducers/expressions.js
@@ -23,14 +23,16 @@ import type { Record } from "../utils/makeRecord";
export type ExpressionState = {
expressions: List<Expression>,
expressionError: boolean,
- autocompleteMatches: Map<string, List<string>>
+ autocompleteMatches: Map<string, List<string>>,
+ currentAutocompleteInput: string | null
};
export const createExpressionState = makeRecord(
({
expressions: List(restoreExpressions()),
expressionError: false,
- autocompleteMatches: Map({})
+ autocompleteMatches: Map({}),
+ currentAutocompleteInput: null
}: ExpressionState)
:
+import {
+ getExpressions,
+ getExpressionError,
+ getAutocompleteMatchset
+} from "../../selectors";
import { getValue } from "../../utils/expressions";
import { createObjectClient } from "../../client/firefox";
+import { debounce } from "lodash";
+
import CloseButton from "../shared/Button/Close";
import type { List } from "immutable";
@@ -37,7 +43,9 @@ type Props = {
deleteExpression: (expression: Expression) => void,
openLink: (url: string) => void,
showInput: boolean,
- onExpressionAdded: () => void
+ onExpressionAdded: () => void,
+ autocomplete: (input: string, cursor: number) => void,
+ autocompleteMatches: array
};
class Expressions extends Component<Props, State> {
@@ -125,9 +133,16 @@ class Expressions extends Component<Props, State> {
}
handleChange = (e: SyntheticInputEvent<HTMLInputElement>) => {
- this.setState({ inputValue: e.target.value });
+ const target = e.target;
+ this.setState({ inputValue: target.value });
+ this.findAutocompleteMatches(target);
};
+ findAutocompleteMatches = debounce(target => {
+ console.log(this.props.autocompleteMatches);
+ this.props.autocomplete(target.value, target.selectionStart);
+ }, 250);
+
handleKeyDown = (e: SyntheticKeyboardEvent<HTMLInputElement>) => {
if (e.key === "Escape") {
this.clear();
@@ -225,6 +240,22 @@ class Expressions extends Component<Props, State> {
);
};
+ renderAutoCompleteMatches() {
+ const { autocompleteMatches } = this.props;
+ if (autocompleteMatches) {
+ return (
+ <datalist id="autocomplete-matches">
+ {autocompleteMatches.map((match, index) => {
+ console.log(match, index);
+ return <option key={index} value={match} />;
+ })}
+ </datalist>
+ );
+ } else {
+ return <datalist id="autocomplete-matches" />;
+ }
+ }
+
renderNewExpressionInput() {
const { expressionError, showInput } = this.props;
const { editing, inputValue, focused } = this.state;
@@ -249,7 +280,9 @@ class Expressions extends Component<Props, State> {
autoFocus={showInput}
value={!editing ? inputValue : ""}
ref={c => (this._input = c)}
+ list="autocomplete-matches"
/>
+ {this.renderAutoCompleteMatches()}
<input type="submit" style={{ display: "none" }} />
</form>
</li>
@@ -281,7 +314,9 @@ class Expressions extends Component<Props, State> {
onFocus={this.onFocus}
value={editing ? inputValue : expression.input}
ref={c => (this._input = c)}
+ list="autocomplete-matches"
/>
+ {this.renderAutoCompleteMatches()}
<input type="submit" style={{ display: "none" }} />
</form>
</span>
@@ -301,6 +336,7 @@ class Expressions extends Component<Props, State> {
}
const mapStateToProps = state => ({
+ autocompleteMatches: getAutocompleteMatchset(state),
expressions: getExpressions(state),
expressionError: getExpressionError(state)
});
diff --git a/src/reducers/expressions.js b/src/reducers/expressions.js
index 8de35c1a..8aa798d9 100644
--- a/src/reducers/expressions.js
+++ b/src/reducers/expressions.js
@@ -23,14 +23,16 @@ import type { Record } from "../utils/makeRecord";
export type ExpressionState = {
expressions: List<Expression>,
expressionError: boolean,
- autocompleteMatches: Map<string, List<string>>
:
+import {
+ getExpressions,
+ getExpressionError,
+ getAutocompleteMatchset
+} from "../../selectors";
import { getValue } from "../../utils/expressions";
import { createObjectClient } from "../../client/firefox";
+import { debounce } from "lodash";
+
import CloseButton from "../shared/Button/Close";
import type { List } from "immutable";
@@ -37,7 +43,9 @@ type Props = {
deleteExpression: (expression: Expression) => void,
openLink: (url: string) => void,
showInput: boolean,
- onExpressionAdded: () => void
+ onExpressionAdded: () => void,
+ autocomplete: (input: string, cursor: number) => void,
+ autocompleteMatches: array
};
class Expressions extends Component<Props, State> {
@@ -125,9 +133,16 @@ class Expressions extends Component<Props, State> {
}
handleChange = (e: SyntheticInputEvent<HTMLInputElement>) => {
- this.setState({ inputValue: e.target.value });
+ const target = e.target;
+ this.setState({ inputValue: target.value });
+ this.findAutocompleteMatches(target);
};
+ findAutocompleteMatches = debounce(target => {
+ console.log(this.props.autocompleteMatches);
+ this.props.autocomplete(target.value, target.selectionStart);
+ }, 250);
+
handleKeyDown = (e: SyntheticKeyboardEvent<HTMLInputElement>) => {
if (e.key === "Escape") {
this.clear();
@@ -225,6 +240,22 @@ class Expressions extends Component<Props, State> {
);
};
+ renderAutoCompleteMatches() {
+ const { autocompleteMatches } = this.props;
+ if (autocompleteMatches) {
+ return (
+ <datalist id="autocomplete-matches">
+ {autocompleteMatches.map((match, index) => {
+ console.log(match, index);
+ return <option key={index} value={match} />;
+ })}
+ </datalist>
+ );
+ } else {
+ return <datalist id="autocomplete-matches" />;
+ }
+ }
+
renderNewExpressionInput() {
const { expressionError, showInput } = this.props;
const { editing, inputValue, focused } = this.state;
@@ -249,7 +280,9 @@ class Expressions extends Component<Props, State> {
autoFocus={showInput}
value={!editing ? inputValue : ""}
ref={c => (this._input = c)}
+ list="autocomplete-matches"
/>
+ {this.renderAutoCompleteMatches()}
<input type="submit" style={{ display: "none" }} />
</form>
</li>
@@ -281,7 +314,9 @@ class Expressions extends Component<Props, State> {
onFocus={this.onFocus}
value={editing ? inputValue : expression.input}
ref={c => (this._input = c)}
+ list="autocomplete-matches"
/>
+ {this.renderAutoCompleteMatches()}
<input type="submit" style={{ display: "none" }} />
</form>
</span>
@@ -301,6 +336,7 @@ class Expressions extends Component<Props, State> {
}
const mapStateToProps = state => ({
+ autocompleteMatches: getAutocompleteMatchset(state),
expressions: getExpressions(state),
expressionError: getExpressionError(state)
});
:
+import {
+ getExpressions,
+ getExpressionError,
+ getAutocompleteMatchset
+} from "../../selectors";
import { getValue } from "../../utils/expressions";
import { createObjectClient } from "../../client/firefox";
+import { debounce } from "lodash";
+
import CloseButton from "../shared/Button/Close";
import type { List } from "immutable";
@@ -37,7 +43,9 @@ type Props = {
deleteExpression: (expression: Expression) => void,
openLink: (url: string) => void,
showInput: boolean,
- onExpressionAdded: () => void
+ onExpressionAdded: () => void,
+ autocomplete: (input: string, cursor: number) => void,
+ autocompleteMatches: array
};
class Expressions extends Component<Props, State> {
@@ -125,9 +133,16 @@ class Expressions extends Component<Props, State> {
}
handleChange = (e: SyntheticInputEvent<HTMLInputElement>) => {
- this.setState({ inputValue: e.target.value });
+ const target = e.target;
+ this.setState({ inputValue: target.value });
+ this.findAutocompleteMatches(target);
};
+ findAutocompleteMatches = debounce(target => {
+ console.log(this.props.autocompleteMatches);
+ this.props.autocomplete(target.value, target.selectionStart);
+ }, 250);
+
handleKeyDown = (e: SyntheticKeyboardEvent<HTMLInputElement>) => {
if (e.key === "Escape") {
this.clear();
@@ -225,6 +240,22 @@ class Expressions extends Component<Props, State> {
);
};
+ renderAutoCompleteMatches() {
+ const { autocompleteMatches } = this.props;
+ if (autocompleteMatches) {
+ return (
+ <datalist id="autocomplete-matches">
+ {autocompleteMatches.map((match, index) => {
+ console.log(match, index);
+ return <option key={index} value={match} />;
+ })}
+ </datalist>
+ );
+ } else {
+ return <datalist id="autocomplete-matches" />;
+ }
+ }
+
renderNewExpressionInput() {
const { expressionError, showInput } = this.props;
const { editing, inputValue, focused } = this.state;
@@ -249,7 +280,9 @@ class Expressions extends Component<Props, State> {
autoFocus={showInput}
value={!editing ? inputValue : ""}
ref={c => (this._input = c)}
+ list="autocomplete-matches"
/>
+ {this.renderAutoCompleteMatches()}
<input type="submit" style={{ display: "none" }} />
</form>
</li>
@@ -281,7 +314,9 @@ class Expressions extends Component<Props, State> {
onFocus={this.onFocus}
value={editing ? inputValue : expression.input}
:
+import {
+ getExpressions,
+ getExpressionError,
+ getAutocompleteMatchset
+} from "../../selectors";
import { getValue } from "../../utils/expressions";
import { createObjectClient } from "../../client/firefox";
+import { debounce } from "lodash";
+
import CloseButton from "../shared/Button/Close";
import type { List } from "immutable";
@@ -37,7 +43,9 @@ type Props = {
deleteExpression: (expression: Expression) => void,
openLink: (url: string) => void,
showInput: boolean,
- onExpressionAdded: () => void
+ onExpressionAdded: () => void,
+ autocomplete: (input: string, cursor: number) => void,
+ autocompleteMatches: array
};
class Expressions extends Component<Props, State> {
@@ -125,9 +133,16 @@ class Expressions extends Component<Props, State> {
}
handleChange = (e: SyntheticInputEvent<HTMLInputElement>) => {
- this.setState({ inputValue: e.target.value });
+ const target = e.target;
+ this.setState({ inputValue: target.value });
+ this.findAutocompleteMatches(target);
};
+ findAutocompleteMatches = debounce(target => {
+ console.log(this.props.autocompleteMatches);
+ this.props.autocomplete(target.value, target.selectionStart);
+ }, 250);
+
handleKeyDown = (e: SyntheticKeyboardEvent<HTMLInputElement>) => {
if (e.key === "Escape") {
this.clear();
@@ -225,6 +240,22 @@ class Expressions extends Component<Props, State> {
);
};
+ renderAutoCompleteMatches() {
+ const { autocompleteMatches } = this.props;
+ if (autocompleteMatches) {
+ return (
+ <datalist id="autocomplete-matches">
+ {autocompleteMatches.map((match, index) => {
+ console.log(match, index);
+ return <option key={index} value={match} />;
+ })}
+ </datalist>
+ );
+ } else {
+ return <datalist id="autocomplete-matches" />;
+ }
+ }
+
renderNewExpressionInput() {
const { expressionError, showInput } = this.props;
const { editing, inputValue, focused } = this.state;
@@ -249,7 +280,9 @@ class Expressions extends Component<Props, State> {
autoFocus={showInput}
value={!editing ? inputValue : ""}
ref={c => (this._input = c)}
+ list="autocomplete-matches"
/>
+ {this.renderAutoCompleteMatches()}
<input type="submit" style={{ display: "none" }} />
</form>
</li>
@@ -281,7 +314,9 @@ class Expressions extends Component<Props, State> {
onFocus={this.onFocus}
value={editing ? inputValue : expression.input}
ref={c => (this._input = c)}
+ list="autocomplete-matches"
/>
+ {this.renderAutoCompleteMatches()}
<input type="submit" style={{ display: "none" }} />
</form>
</span>
@@ -301,6 +336,7 @@ class Expressions extends Component<Props, State> {
}
const mapStateToProps = state => ({
+ autocompleteMatches: getAutocompleteMatchset(state),
expressions: getExpressions(state),
expressionError: getExpressionError(state)
});
diff --git a/src/reducers/expressions.js b/src/reducers/expressions.js
index 8de35c1a..8aa798d9 100644
--- a/src/reducers/expressions.js
+++ b/src/reducers/expressions.js
@@ -23,14 +23,16 @@ import type { Record } from "../utils/makeRecord";
export type ExpressionState = {
expressions: List<Expression>,
expressionError: boolean,
- autocompleteMatches: Map<string, List<string>>
+ autocompleteMatches: Map<string, List<string>>,
+ currentAutocompleteInput: string | null
};
export const createExpressionState = makeRecord(
({
expressions: List(restoreExpressions()),
expressionError: false,
- autocompleteMatches: Map({})
+ autocompleteMatches: Map({}),
+ currentAutocompleteInput: null
}: ExpressionState)
);
@@ -92,7 +94,7 @@ function update(
return state.updateIn(
["autocompleteMatches", matchProp],
list => matches
- );
+ ).set("currentAutocompleteInput", matchProp);
}
return state;
@@ -179,7 +181,8 @@ export function getExpression(state: OuterState, input: string) {
return getExpressions(state).find(exp => exp.input == input);
}
-export function getAutocompleteMatchset(state: OuterState, input: string) {
+export function getAutocompleteMatchset(state: OuterState) {
+ const input = state.expressions.get('currentAutocompleteInput');
return getAutocompleteMatches(state).get(input);
}
Thank you so much, tomorrow I'll start working on it!
How's it going @marcogallo566?
@marcogallo566 i got some time yesterday to start looking at the bug ur having. Will ping you an update soon.
Thank you so much! @nyrosmith I'm stucked with a bug, but @bomsy is helping me