rajdeep / proton

Purely native and extensible rich text editor for iOS and macOS Catalyst apps
Other
1.25k stars 81 forks source link

Editor shouldHandleKey not being called (again) #285

Open easiwriter opened 5 months ago

easiwriter commented 5 months ago

I've done more digging and discovered that Proton calls

func editor(_ editor: EditorView, shouldHandle key: EditorKey, modifierFlags: UIKeyModifierFlags, at range: NSRange, handled: inout Bool) { }

This does nothing, because it has not been overridden.

Whereas the documentation has this, which is what my code calls:

func editor(_ editor: EditorView, shouldHandle key: EditorKey, at range: NSRange, handled: inout Bool)

This possibly explains why Proton doesn't call it.

I added the modifierFlags to my call and it works, so it looks like there could either be a documentation error, or I didn't see it in the documentation.

easiwriter commented 5 months ago

Also shouldHandle is called twice in:

    static func editor(_ editor: EditorView, shouldHandle key: EditorKey, modifierFlags: UIKeyModifierFlags, at range: NSRange, handled: inout Bool) {
        editor.delegate?.editor(editor, shouldHandle: key, modifierFlags: modifierFlags, at: range, handled: &handled)
        editor.editorContextDelegate?.editor(editor, shouldHandle: key, modifierFlags: modifierFlags, at: range, handled: &handled)
    }

What is editorContextDelegate? Also handled isn't changed.

rajdeep commented 4 months ago

@easiwriter, unfortunately the ReadMe is not updated for all the samples. I'd recommend using API Reference found here which I try to keep uptodate: https://rajdeep.github.io/proton/

in regards to EditorViewContext: basically you can create Attachments that contains EditorView in itself. Checkout Panel/Expand in CommandsExampleViewController to see an example. You can also read more about EditorViewContext here: https://rajdeep.github.io/proton/Classes/EditorViewContext.html

editorContextDelegate is the delegate that you can set on the context of the editor. If the delegate is set on Editor, the callbacks are received only for that editor. If the delegate is set on EditorViewContext instead, then the same callback will be received for all the Editors sharing the same context.

easiwriter commented 4 months ago

Thanks for this.

The Editor is injected into a UIViewRepresentable. This creates a class called Coordinator that does all the work. I’ve set this to inherit from EditorViewDelegate to handle all the events. I tried inheriting from EditorViewContext but it won’t compile because the class is not marked as Open as opposed to Public (it says: Cannot inherit from non-open class 'EditorViewContext' outside of its defining module).

Best Keith

On 29 Feb 2024, at 06:15, Rajdeep Kwatra @.***> wrote:

@easiwriter https://github.com/easiwriter, unfortunately the ReadMe is not updated for all the samples. I'd recommend using API Reference found here which I try to keep uptodate: https://rajdeep.github.io/proton/

in regards to EditorViewContext: basically you can create Attachments that contains EditorView in itself. Checkout Panel/Expand in CommandsExampleViewController to see an example. You can also read more about EditorViewContext here: https://rajdeep.github.io/proton/Classes/EditorViewContext.html

editorContextDelegate is the delegate that you can set on the context of the editor. If the delegate is set on Editor, the callbacks are received only for that editor. If the delegate is set on EditorViewContext instead, then the same callback will be received for all the Editors sharing the same context.

— Reply to this email directly, view it on GitHub https://github.com/rajdeep/proton/issues/285#issuecomment-1970478988, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEUXIA43C6B57MV7S4KVPNLYV3DQ7AVCNFSM6AAAAABDYWLXP2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNZQGQ3TQOJYHA. You are receiving this because you were mentioned.