-
Notifications
You must be signed in to change notification settings - Fork 14
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
Punching through uniffi to expose the cursor API #69
Conversation
Nice! The code LGTM. We may want a little more context in the docs about when one might need a cursor etc, @heckj thoughts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A minor fiddly bit on the how the test is constructed, but otherwise the content looks good. This PR is aimed at that alpha
branch though, but anything incoming should be aimed at the main
branch, and after it's landed, I can cherry pick the relevant commit back in the alpha branch and cut a new XCFramework and pre-release 0.5.x version.
I'm not fussed about the relative lack of documentation - I'm right in the middle of a big rebuild of the documentation, so it will be easy for me to integrate this in after we land the PR.
@@ -27,6 +27,36 @@ class TextTestCase: XCTestCase { | |||
XCTAssertEqual(try! doc.textAt(obj: text, heads: heads), "hello world!") | |||
} | |||
|
|||
func testTextCursor() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know a lot of the legacy tests in this repo use the force unwrapping of try statements (try!
), but as a general pattern its far easier to diagnose test errors if the test itself is throwing, and then you don't need to wrap the try
with !
.
Question about
And a question - as much for @munhitsu as @alexjg - right now we leave the whole tracking of a UTF-8view of a Swift String to the developer to manage the positioning in and out, ignoring the Character indexes (which point to full glyphs, not UTF8 index positions). Would it make sense to have an initializer on Cursor, referencing the Character Index within the String of the .Text object, that we automagically convert to a UTF-8 position when initializing the cursor to better developer ergonomics? |
Correct on all four points. The idea of a "default" cursor is interesting, that would be the start of the sequence? As to the character index stuff, that makes a lot of sense. Can it be done efficiently? Do you not need to track the state of the "current" version of the text in order to translate to UTF-8 indexes? |
That was sort of the idea that I was starting with, and maybe exposing Cursor as an additional property on the higher-level
My biggest concern is the whole "one glyph being multiple UTF-8 code points" scenario with String and UTF-8 positions. I think it makes a HUGE amount of sense to let the cursor shift with Automerge's updates, but when initializing a cursor from a Swift string value, using the character index from the current-value of string to convert into the UTF-8 view to get that appropriate index. If I recall correctly, there's a conversion method within String that lets you convert String.Index to String.UTF8View.Index pretty easily. |
If ever you want to get back to the idea of having the default cursor then bear in mind that UITextField thinks in terms of NSRange. This means 2 cursors. Thank you for the merge! |
I think I'll snag that into a future enhancement issue, thanks @munhitsu |
exposing the Cursor API