Comments (8)
I see there is a bunch of swizzling code for focus in MarkupWKWebView that was commented out on Sep 5. If I restore that code and call showKeyboard() from makeUIView in the UI representable class, the editor gets focus and the keyboard appears.
I expect there was a good reason for commenting out this code and losing the functionality, but I'd love to know why or what the risks are of restoring this code.
from markupeditor.
I did a lot of work on this issue that is still in main
right now. Basically you can tell the MarkupEditor which view should be the firstResponder by its id:
MarkupEditor.firstResponder = <The String id of the MarkupWKWebView>
In the demos, the id is set to "Document" when the MarkupEditorView is created:
MarkupEditorView(markupDelegate: self, html: $demoHtml, resourcesUrl: resourcesUrl, id: "Document")
In the app I'm using MarkupEditor with, I have a unique id for the model-type object that holds onto the HTML I feed to the MarkupEditor.
Behind the scenes, the MarkupWKWebView observes the ObservedFirstResponder and responds:
/// Monitor the setting for MarkupEditor.observedFirstResponder, and set this MarkupWKWebView to be the first responder
/// when the id matches.
///
/// Becoming the first reponder also means that focus and selection state are set properly.
private func observeFirstResponder() {
firstResponder = MarkupEditor.observedFirstResponder.$id.sink { [weak self] selectedId in
guard let selectedId, let self, self.id == selectedId else {
return
}
self.becomeFirstResponderIfReady()
}
}
Main should be stable and I hope (but tbh not absolutely certain) compatible with the Beta release.
from markupeditor.
Awesome -- I'll point my package ref to main and give this a go. Thank you for such a prompt and detailed reply!
from markupeditor.
Sorry, I think I sent you on a wild goose chase with main as opposed to the swizzling methods you found earlier. The work I did on firstResponder was useful and dealt with the case of it not working right because a view was not yet ready. In my usage, I have a List of MarkupWebViews, and I need to scroll to a particular one and make sure the insertion-point caret is showing properly, which is not the issue you're having. I even removed the swizzling methods for keyboard interaction from main because I figured they were not needed!!!
I think the reason I commented that code out was because, as you said, Apple mostly doesn't want you to be bringing up the keyboard without the user selecting something. Plus, in my own case, I want the view to open without the keyboard when on iOS, because I want it to be readable and scrollable without the keyboard covering the screen. I still think that will be the default case, but I can see adding a setting to make it optional, and then calling showKeyboard() at the right place when the option is set. That work would amount to adding a new static to MarkupEditor (so, for example, it could be set in your AppDelegate or someplace handy), and then gating the call to showKeyboard with a test on that setting. I'm not completely certain that makeUIView is the right place, but maybe. I might prefer it on a MarkupDelegate callback.
If you want to do that as a PR, I'd love to put it in. (FWIW, it would be easiest for me on main.) Otherwise, we can leave this open and I will try to deal with it at some point relatively soon.
I appreciate your raising the issue and can see how this can be very important. If you don't file a PR, please add any additional info about how you dealt with it if you think it will be useful to me and others.
Also, please note #89, which you will need to work around for now.
from markupeditor.
Thank you for all this info, and apologies for my delay in responding. I've been heads-down for the last little while.
Over the next week I'll focus on implementing this and reach out for feedback and/or submit a PR.
from markupeditor.
Has this been resolved? @gmckenzi @stevengharris
from markupeditor.
I haven't been able to spend any time on it. Have you tried what @gmckenzi suggested in #88 (comment)?
from markupeditor.
Hi @stevengharris, not sure if this is related.
In my use case, I have other UITextFields above the MarkupEditor. The MarkupEditor is the entire space below. When I try to tap on the space except the topmost line, it does not respond to being a first responder. However when I tap on the top most line, it becomes the first responder. This only happens for the first time, and after that it works properly.
RPReplay_Final1692860986.mov
from markupeditor.
Related Issues (20)
- Unable to build in Swift Playgrounds HOT 5
- What do I do when I'm done with the editor? HOT 5
- Sharing the screen with other WKWebViews
- Adding a photo picker HOT 4
- MarkupWKWebView initRootFiles triggering twice HOT 13
- Customizing Buttons HOT 1
- Toolbar justification HOT 4
- Possible strange interaction with other WKWebViews HOT 3
- Pasting trouble HOT 37
- Can't track changes in text editor HOT 3
- Two toolbars...but only once HOT 11
- Pasting html text sometimes gets truncated HOT 3
- Weird HTML tags not removing properly HOT 1
- Toolbar on iPhone that is set to keyboard location but also to persist at the bottom / top when keyboard dismisses HOT 3
- Pasting URLs doesn't work
- Support Custom CSS and File-Base User Scripts
- Support strict concurrency in anticipation of Swift 6
- The styling('Bold', 'cursive') is reset with each new line.(After enter is pressed) HOT 1
- Trouble placing an image at the top of the editor HOT 14
- Add parameter in getHtml function to remove css classes HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from markupeditor.