See the screenshot, put caret before \xE5, then press Delete, three bytes been deleted; put caret after \xE5, then press Backspace, only \xE5 been deleted.
Also, double-click on \xE5, the next two characters been selected too.
While it would be better to treat invalid bytes more consistently, this doesn't seem too important. The user can fix the invalid area in the text although it might be a little more work.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Copy some code from Document::CharacterAfter() to Document::LenChar() would fix deleting and caret (not block caret, text been drawn U+00E5 LATIN SMALL LETTER A WITH RING ABOVE).
Double-click selecting bug is because 0xFFFD been treated as punctuation.
LenChar is from the original Unicode support change set which expected valid UTF-8. Returning 1 for out-of-bounds instead of 0 will be defending against hanging with a loop that goes (or starts) out of bounds.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
\xE5 been drawn as U+00E5 LATIN SMALL LETTER A WITH RING ABOVE is because DrawTextClipped at the end of DrawBlockCaret().
When using block caret, in UTF-8 mode, all invalid single byte will been drawn as Latin-1.
Maybe some invalid bytes will be passed to underlying platforms in DBCS/SBCS encodings, which may cause some failures as that happened before on Cocoa.
Last edit: Zufu Liu 2019-06-28
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
We could know (e.g. add a optional bool pointer parameter to LenChar) that the byte at caret position is invalid, so don't draw block caret, instead draw line or bar caret depends on inOverstrike to preserve hex representation for the invalid byte.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
While it would be better to treat invalid bytes more consistently, this doesn't seem too important. The user can fix the invalid area in the text although it might be a little more work.
The bug is in Document::LenChar(), it cause caret bug, and maybe others.
Copy some code from Document::CharacterAfter() to Document::LenChar() would fix deleting and caret (not block caret, text been drawn U+00E5 LATIN SMALL LETTER A WITH RING ABOVE).
Double-click selecting bug is because 0xFFFD been treated as punctuation.
Last edit: Zufu Liu 2019-06-26
Read the old code again, don't understand why it returns 1 for pos < 0?
It it returns 1 for pos < 0, it's likely the added line for pos >= Length() will break something?
Changed to return 1 for invalid pos.
Last edit: Zufu Liu 2019-06-27
LenChar is from the original Unicode support change set which expected valid UTF-8. Returning 1 for out-of-bounds instead of 0 will be defending against hanging with a loop that goes (or starts) out of bounds.
Added the explanation in the comment.
\xE5 been drawn as U+00E5 LATIN SMALL LETTER A WITH RING ABOVE is because DrawTextClipped at the end of DrawBlockCaret().
When using block caret, in UTF-8 mode, all invalid single byte will been drawn as Latin-1.
Maybe some invalid bytes will be passed to underlying platforms in DBCS/SBCS encodings, which may cause some failures as that happened before on Cocoa.
Last edit: Zufu Liu 2019-06-28
Possible after the call (in EditView::DrawCarets)
We could know (e.g. add a optional bool pointer parameter to LenChar) that the byte at caret position is invalid, so don't draw block caret, instead draw line or bar caret depends on inOverstrike to preserve hex representation for the invalid byte.
This should be approached directly with a check inside DrawBlockCaret instead of a change that avoids the problem far from its occurrence.
LenChar doesn't know about representations and adding a partial check there is just going to lead to more issues on other cases.
Do you means check the text, to see whether is has representation?
The problem is that DrawBlockCaret is not implementing the same text drawing logic as DrawForeground.
Patch for fix the block caret.
I think the whole block for widthOverstrikeCaret calculation can be avoid for line caret.
Committed lenChar-3.cxx as [1031c1].
Related
Commit: [1031c1]
Committed lenChar-3.cxx as [1031c1].
Related
Commit: [1031c1]