Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

CTRL+L should not render suggestions #5026

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ WindowStore
type: string // The type of suggestion (one of js/constants/suggestionTypes.js)
},
urlSuffix: string, // autocomplete suffix
shouldRender: boolean, // if the suggestions should render
autocompleteEnabled: boolean // used to enable or disable autocomplete
},
focused: boolean, // whether the urlbar is focused
Expand Down
12 changes: 12 additions & 0 deletions js/actions/windowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,18 @@ const windowActions = {
})
},

/*
* Sets if we should render URL bar suggestions.
*
* @param enabled If false URL bar suggestions will not be rendered.
*/
setRenderUrlBarSuggestions: function (enabled) {
dispatch({
actionType: WindowConstants.WINDOW_SET_RENDER_URL_BAR_SUGGESTIONS,
enabled
})
},

/*
* Sets the URL bar preview value.
* TODO: name this something better.
Expand Down
17 changes: 11 additions & 6 deletions js/components/urlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,13 @@ class UrlBar extends ImmutableComponent {
case KeyCodes.BACKSPACE:
this.hideAutoComplete()
break
// Do not trigger rendering of suggestions if you are pressing alt or shift
case KeyCodes.ALT:
case KeyCodes.SHIFT:
break
default:
this.keyPressed = true
windowActions.setRenderUrlBarSuggestions(true)
// Any other keydown is fair game for autocomplete to be enabled.
if (!this.autocompleteEnabled) {
windowActions.setUrlBarAutocompleteEnabled(true)
Expand Down Expand Up @@ -270,6 +275,9 @@ class UrlBar extends ImmutableComponent {
this.clearSearchEngine()
this.detectSearchEngine(e.target.value)
this.keyPressed = false
if (e.target.value.length === 0) {
windowActions.setRenderUrlBarSuggestions(false)
}
}

onFocus (e) {
Expand All @@ -293,8 +301,7 @@ class UrlBar extends ImmutableComponent {

componentWillMount () {
ipc.on(messages.SHORTCUT_FOCUS_URL, (e) => {
// If the user hits Command+L while in the URL bar they want everything suggested as the new potential URL to laod.
this.updateLocationToSuggestion()
windowActions.setRenderUrlBarSuggestions(false)
windowActions.setUrlBarSelected(true)
windowActions.setUrlBarActive(true)
// The urlbar "selected" might already be set in the window state, so subsequent Command+L won't trigger component updates, so this needs another DOM refresh for selection.
Expand Down Expand Up @@ -390,11 +397,9 @@ class UrlBar extends ImmutableComponent {
windowActions.setSiteInfoVisible(true)
}

// Currently even if there are no suggestions we render the URL bar suggestions because
// it needs to generate them. This needs to be refactored. See https://github.com/brave/browser-laptop/issues/3151
get shouldRenderUrlBarSuggestions () {
return (this.props.urlbar.get('location') || this.props.urlbar.get('urlPreview')) &&
this.props.urlbar.get('active')
let shouldRender = this.props.urlbar.getIn(['suggestions', 'shouldRender'])
return shouldRender === true
}

onDragStart (e) {
Expand Down
6 changes: 0 additions & 6 deletions js/components/urlBarSuggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,10 @@ class UrlBarSuggestions extends ImmutableComponent {
this.updateSuggestions(parseInt(e.target.dataset.index, 10))
}

componentDidMount () {
this.suggestionList = this.getNewSuggestionList()
this.searchXHR()
}

componentWillUpdate (nextProps) {
if (this.selectedElement) {
this.selectedElement.scrollIntoView()
}

// If both the URL is the same and the number of sites to consider is
// the same then we don't need to regenerate the suggestions list.
if (this.props.urlLocation === nextProps.urlLocation &&
Expand Down
1 change: 1 addition & 0 deletions js/constants/windowConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const windowConstants = {
WINDOW_SET_NAVBAR_FOCUSED: _,
WINDOW_SET_LINK_HOVER_PREVIEW: _,
WINDOW_SET_URL_BAR_SUGGESTIONS: _,
WINDOW_SET_RENDER_URL_BAR_SUGGESTIONS: _,
WINDOW_SET_URL_BAR_AUTCOMPLETE_ENABLED: _,
WINDOW_SET_URL_BAR_PREVIEW: _,
WINDOW_SET_URL_BAR_SUGGESTION_SEARCH_RESULTS: _,
Expand Down
3 changes: 3 additions & 0 deletions js/stores/windowStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,9 @@ const doAction = (action) => {
})
}
break
case WindowConstants.WINDOW_SET_RENDER_URL_BAR_SUGGESTIONS:
windowState = windowState.setIn(activeFrameStatePath().concat(['navbar', 'urlbar', 'suggestions', 'shouldRender']), action.enabled)
break
case WindowConstants.WINDOW_SET_URL_BAR_AUTCOMPLETE_ENABLED:
windowState = windowState.setIn(activeFrameStatePath().concat(['navbar', 'urlbar', 'suggestions', 'autocompleteEnabled']), action.enabled)
break
Expand Down