iOS: Native Text Field Incorrectly Inserting Characters If Cursor Is Moved

I’ve worked around the problem so that I can release using build 1259. Here’s my workaround. Self in this case is an object that contains a created nativeTextField in self.nativeTextField, and self.text holds the correct value of the text across editing events:

            -- Workaround for bug in build 1259.             -- There is a special case of backspacing a secure field that wipes all the chars out.             -- Don't do the bug fix for secure fields.             local fixedText = event.text             if (not self.isSecure) and event.oldText and ( type( event.oldText ) == "string" )             and ( event.startPosition \> 0 ) and event.newCharacters and ( type( event.newCharacters ) == "string" ) then                 if event.newCharacters:len() == 0 then                     -- This was a delete action. The start position will be -- the location of the cursor AFTER the deleted characters were deleted.                     -- Delete characters at the start position + 1 -- based on the difference in length of                     -- the new (probably wrong) text and the old text.                     local charCount = event.oldText:len() - event.text:len()                     if charCount \> 0 then                         fixedText = self.text:sub( 1, event.startPosition - 1 ) .. self.text:sub( event.startPosition + charCount )                     end                 else                     -- Characters were typed, so add them in the right place.                     -- Here, start position is the position BEFORE the characters were added.                     fixedText = self.text:sub( 1, event.startPosition - 1 ) .. event.newCharacters .. self.text:sub( event.startPosition )                 end print( "fixing the bug, forcing " .. fixedText )             end                 self:setText( fixedText )  

This problem is bad. In build 1259, not only does it update the end of the text instead of the middle, but it also considers a select/cut action to be the deletion of the last character of the text. User selects and cuts characters 3-8 of the text, and character 12 disappears instead.

It also seems like autocomplete doesn’t work anymore.

As far as migration to G2 being “easy”, I use a lot of widgets. Widgets have their centers as origin in G2 instead of top left. Center origin causes fuzzy text, as we know from many other posts/discussions (fractional x/y values cause fuzziness due to aliasing, and the solution is to use non-center origins to avoid fractional x/y values for left and right edges of text objects).

So, I don’t see G2 as an easy solution. I see retrofitting the G2 fix for a bad bug into a Corona G1 build as an easy solution, or a having the compatibility mode include all the G2 fixes and not have widget incompatibilities as an easy solution.

I’ve worked around the problem so that I can release using build 1259. Here’s my workaround. Self in this case is an object that contains a created nativeTextField in self.nativeTextField, and self.text holds the correct value of the text across editing events:

            -- Workaround for bug in build 1259.             -- There is a special case of backspacing a secure field that wipes all the chars out.             -- Don't do the bug fix for secure fields.             local fixedText = event.text             if (not self.isSecure) and event.oldText and ( type( event.oldText ) == "string" )             and ( event.startPosition \> 0 ) and event.newCharacters and ( type( event.newCharacters ) == "string" ) then                 if event.newCharacters:len() == 0 then                     -- This was a delete action. The start position will be -- the location of the cursor AFTER the deleted characters were deleted.                     -- Delete characters at the start position + 1 -- based on the difference in length of                     -- the new (probably wrong) text and the old text.                     local charCount = event.oldText:len() - event.text:len()                     if charCount \> 0 then                         fixedText = self.text:sub( 1, event.startPosition - 1 ) .. self.text:sub( event.startPosition + charCount )                     end                 else                     -- Characters were typed, so add them in the right place.                     -- Here, start position is the position BEFORE the characters were added.                     fixedText = self.text:sub( 1, event.startPosition - 1 ) .. event.newCharacters .. self.text:sub( event.startPosition )                 end print( "fixing the bug, forcing " .. fixedText )             end                 self:setText( fixedText )