Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1433475 — Keyboard — enable up and down arrows in location bar. #3706

Merged
merged 13 commits into from Mar 13, 2018

Conversation

jhugman
Copy link
Contributor

@jhugman jhugman commented Mar 5, 2018

This PR allows the user to select URL completions (from bookmarks and history) to be selected via the keyboard.

Desktop leaves the cursor in the location field, which means than horizontal cursor movement is possible.

We aren't able to do this, given that the search suggestions for the query appear horizontally.

Please file follow up usability bugs.

r? for @farhan.

https://bugzilla.mozilla.org/show_bug.cgi?id=1433475

@mozillamobilebot
Copy link

mozillamobilebot commented Mar 5, 2018

SwiftLint found issues

Warnings

File Line Reason
BrowserViewController.swift 842 Force casts should be avoided.
SearchViewController.swift 608 Force casts should be avoided.
SearchViewController.swift 634 Force casts should be avoided.
SearchViewController.swift 455 if,for,while,do statements shouldn't wrap their conditionals in parentheses.
SearchViewController.swift 426 Explicitly calling .init() should be avoided.

Generated by 🚫 Danger

@@ -1753,6 +1753,7 @@ extension BrowserViewController: SearchViewControllerDelegate {
}

func searchViewControllerDidFinishHighlighting(_ searchViewController: SearchViewController) {
searchViewController.resignFirstResponder()
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is called when the user has typed DOWN, then UP — i.e. focus should move back to the location bar.

}

func handleKeyCommands(sender: UIKeyCommand) {
let initialSection = SearchListSection.bookmarksAndHistory.rawValue
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We might change this value when we get we get to Bug 1433476.

return
}

tableView(tableView, didSelectRowAtIndexPath: current)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Calling this delegate here feels weird. How do we perform the same action a tap performs?

}
}
let next = IndexPath(item: nextItem, section: nextSection)
self.tableView(tableView, didHighlightRowAt: next)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Calling this delegate here feels weird. tableView.selectRow does the highlighting.

}

func searchViewControllerDidFinishHighlighting(_ searchViewController: SearchViewController) {
searchViewController.resignFirstResponder()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is called when the user has typed DOWN, then UP — i.e. focus should move back to the location bar.

Also tried: explicitly setting BVC or the location bar as first responder.

@farhanpatel
Copy link
Contributor

I think to simplify this. It might be easier to never change the focus from the AutocompleteTextField. Instead just pass the up/down keypress from the textfield down to the SearchViewController. That way you dont have to worry about show/hiding the keyboard.

Where this gets tricky is handling the search suggestions. Because they are shown horizontally, tapping left/right to switch between them wouldnt work because on the textfield that would move your cursor. I think this is why safari/chrome/firefox desktop show autocomplete suggestions as a list instead of the way we do.

@jhugman
Copy link
Contributor Author

jhugman commented Mar 6, 2018

It might be easier to never change the focus from the AutocompleteTextField.
Because they are shown horizontally, tapping left/right to switch between them wouldnt work because on the textfield that would move your cursor.

Yeah, I think you've answered your own question about why we can't do this.

That way you dont have to worry about show/hiding the keyboard.

Ug. I wasn't considering the soft keyboard for UIKeyCodes.

@jhugman jhugman force-pushed the jhugman/Bug1433475—keyboard—up-and-down-in-urlbar branch from 55112c0 to 2271022 Compare March 7, 2018 12:35
@jhugman
Copy link
Contributor Author

jhugman commented Mar 7, 2018

Ok, I think I've cracked it.

Looking at desktop, they seem to be leaving the cursor with the text view, and you can move it around with the cursor.

I'm not altogether happy with what we've got here — but we're limited by the design of the search auto-complete. I'm leaving the horizontal keys for the next follow up bug.

@farhanpatel
Copy link
Contributor

farhanpatel commented Mar 8, 2018

I'm getting a pretty bad crash that happens when there are no urls in the searchsuggestions tableview.

  1. Type until there are no url suggestions
  2. press up/down on the keyboard
  3. crashes 😢

I think in the optimal case I dont think we should move focus away from the keyboard. I think this should work exactly like Desktop. For example. if you want to go to reddit.com/r/ios and you already have reddit.com in your history.
you should be able to type re, arrow down to reddit.com and then press right array to get to the end of the url where you can continue typing /r/ios

right now. if you want to continue typing for any reason you have to arrow up all the way to the urlbar.

@jhugman jhugman force-pushed the jhugman/Bug1433475—keyboard—up-and-down-in-urlbar branch from 2271022 to d56f583 Compare March 12, 2018 19:45
Copy link
Contributor

@farhanpatel farhanpatel left a comment

Choose a reason for hiding this comment

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

Besides that one unused var. looks awesome! Can't wait for this to land.

@@ -69,6 +71,10 @@ class SearchViewController: SiteTableViewController, KeyboardHelperDelegate, Loa

static var userAgent: String?

var isCellHighlighted: Bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

I dont think this is used anywhere.

@jhugman jhugman merged commit 4fa18a3 into master Mar 13, 2018
@jhugman jhugman deleted the jhugman/Bug1433475—keyboard—up-and-down-in-urlbar branch March 13, 2018 12:23
jhugman added a commit that referenced this pull request Mar 13, 2018
…3706) r=farhan

This bug allows the user to select URL completions (from bookmarks and history) to be selected via the keyboard.

Desktop leaves the cursor in the location field, which means than horizontal cursor movement is possible.

We try to replicate that.

There do seem to be some difficulty supporting search suggestions, so this is rolled into another bug.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants