wordpress-mobile / AztecEditor-Android

A reusable native Android rich text editor component.
Mozilla Public License 2.0
675 stars 112 forks source link

Issue/184 add keyboard shortcuts #240

Closed theck13 closed 7 years ago

theck13 commented 7 years ago

Fix

Add keyboard shortcuts as described in https://github.com/wordpress-mobile/WordPress-Aztec-Android/issues/184. The shortcuts available are displayed in a dialog shown by pressing Alt+Ctrl+H. The dialog can not be shown by holding the meta key (i.e. Search or Windows or Command) since the operating system overrides that key to launch search. Android also overrides the meta key and / combination to show system-level shortcuts. The Alt+Ctrl+H combination was chosen to match Calypso. On the bright side, the standard editor shortcuts (i.e. copy, cut, paste, and select all) were included for free since AztecText extends EditText.

Test

  1. Connect external keyboard.
  2. Open demonstration app.
  3. Press Alt+Ctrl+H.
  4. Notice keyboard shortcuts legend.
  5. Try keyboard shortcuts.
khaykov commented 7 years ago

Look's like I cant really test this one with Genymotion/Emulator, so will have to pass on it, as I don't have a HW keyboard.

0nko commented 7 years ago

Yeah, neither do I.. :/

0nko commented 7 years ago

But @astralbodies has Pixel C ;).

theck13 commented 7 years ago

@astralbodies and @hypest, do either of you have an external keyboard?

hypest commented 7 years ago

I have a tablet+keyboard so I can give this a try. Will report back.

hypest commented 7 years ago

OK, gave it a go with a BT tablet case keyboard and works OK, good job!

Not sure if this has been code reviewed already but, any particular reason the keyboard mapping is handled by the demo app instead of the Aztec lib? I mean, the toolbar itself is part of Aztec so, i'd expect the shortcuts to be handled by Aztec as well. Any insight? Thanks!

theck13 commented 7 years ago

any particular reason the keyboard mapping is handled by the demo app instead of the Aztec lib?

I considered handling the keyboard shortcuts within the library rather than the app. If they are in the library, they would be handled in the textbox or the toolbar. That means if the user has focus on the textbox, the toolbar wouldn't recognize the keyboard. Similarly, if the user has focus on the toolbar, the textbox wouldn't recognize the keyboard. In other words, it's possible the library wouldn't recognize the keyboard depending on the view in focus. If the keyboard shortcuts are handled in the app, they are recognized regardless of focus.

That being said, I'm up for trying a different implementation if you have another idea.

hypest commented 7 years ago

Ah, thanks for the insight @theck13! Haven't tested it but I think the toolbar can implement the mapping and the editor can ask the toolbar to consume the key before trying to consume it itself. So, both will implement the inteception but the editor will just delegate the key. Does that make sense?

astralbodies commented 7 years ago

Let me know if you'd still like me to test out this PR!