Page MenuHomePhabricator

[M]: Add keyboard shortcuts to Native Editor
Closed, ResolvedPublic

Description

It would be nice to for certain expected keyboard shortcuts to work on the editor with a bluetooth-connected keyboard. For example: Cmd + b = Bold and Cmd + i = Italic.

QA Notes

Connect Bluetooth keyboard to device. Open editor and highlight word. Check that keyboard shortcut Cmd + b toggles wikitext bolding, and Cmd + i toggles wikitext italics.

Event Timeline

Estimation notes: There is some prototyping done by Toni.

Seddon renamed this task from [Sub task]: Add keyboard shortcuts to Native Editor to [M]: Add keyboard shortcuts to Native Editor.Jan 25 2024, 6:29 PM

Hi @Adityakumar0545,

I don't think I saved my prototype code anywhere but it wasn't much to get keyboard shortcuts working from what I recall.

The location of our editor code is here in WKSourceEditorViewController.

My advice would be to reference something like this https://www.hackingwithswift.com/example-code/uikit/how-to-use-uikeycommand-to-add-keyboard-shortcuts to allow the view controller to respond to keyboard shortcuts. In order to automatically add or remove bold wikitext, you should be able to call something like this from your UIKeyCommand selector action :

@objc func toggleBoldFromKeyboardShortcut() {
    let selectionState = selectionState() //here we are leaning on a helper method that tells us if the currently selected code is already bold or not
    let action: WKSourceEditorFormatterButtonAction = selectionState.isBold ? .remove : .add
    textFrameworkMediator.boldItalicsFormatter?.toggleBoldFormatting(action: action, in: textView)
}

Thanks!

Hello! I created a PR for this. Please note that it was only tested on Simulator, I ran into some issues trying to run on a real device even when changing the bundle ID. Also, I tried to write a UI test for the change but ran into some issues with the software keyboard and the test was too flaky, so I put the idea aside.

Thanks for creating the PR. @ChristianBilodeau just want to check, do you consider the PR being in a finished state? Or are you just looking for some initial feedback?

Hello @Seddon, to me it's in a finished state with regard to what I can achieve as an outside contributor.

Trying to test on a real device, even changing all the entitlements, team and bundle IDs, I ran into the following issue with MWKDataStore: [NSURL initFileURLWithPath:isDirectory:]: nil string parameter.

This is my first time contributing, and without documentation on this sadly I cannot go further efficiently. But I still think it'd be best if someone could test this feature with a real phone and bluetooth keyboard.

Thanks!

Tsevener updated the task description. (Show Details)
Tsevener added a subscriber: ChristianBilodeau.
ABorbaWMF subscribed.

This is partially working for me on 7.5.9 (4078)

It is working well for normal article editing, but it is not working for talk page messages or replies.

@ABorbaWMF I think that's expected - this won't work for talk page "new topic" or "add reply" flows because those textviews are not built with our native editor.

It should work for the "talk page > overflow menu > edit source" flow. Can you let me know if that works?

@Tsevener works for me. The user can add bold and italics within the talk page message body. Perhaps that should not be the case?

@ABorbaWMF Ah I see, yeah, the text views on talk pages (new topic and add reply) are older and were built before we created the "native editor" - i.e. the full source editor with all the keyboard buttons and syntax highlighting. Article's native editor was incorporated into the Talk Page > Edit Source flow, but not into the "new topic" and "new reply" textviews. The work to do that is in this task - T348292.

Only the full source and article section editor flows received the keyboard shortcuts. The talk page "add reply" and "new topic" textviews won't get this functionality until we do T348292.