I tried my code in MacOS 26.0 Beta (25A5279m). The problem is not there, so it seems to be a bug in 15.5.
Although this specific issue is fixed in 26.0, it is introducing new ones. The index in the string is clearly being corrupted. I suspect it still has to do between the switch of index between utf8 and utf16.
When I type 1234, then press cursor back once, so that curser is between 3 and 4, and type '' three times then I suddenly get '12×3×à 4'.
I can see from my log that the input is completely corrupted:
input: changed from '' to '1'
input: changed from '1' to '12'
Moving cursor from 2[any]
Moved to 4[utf8]
input: changed from '12' to '12×'
input: changed from '12×' to '12×3'
input: changed from '12×3' to '12×34'
Moving cursor from 4[utf16]
Moved to 7[utf8]
input: changed from '12×34' to '12×3×4'
Moving cursor from 7[utf8]
Moved to 8[utf8]
input: changed from '12×3×4' to '12×3××4'
Moving cursor from 8[utf8]
Moved to 9[utf8]
input: changed from '12×3××4' to '12×3×\303×\2274'
code-block
It seems that the text selection in TextField is not great yet.
I wanted to raise a developer support but it said that apple engineers will prioritise forums during this time. Hopefully someone can take a look at this.
I also tried changing from String to AttributedString to test the new TextField with formatting but this does not seem to be available yet.
Topic:
UI Frameworks
SubTopic:
SwiftUI