Text.current_character wrong value for certain characters #65843

Closed
opened 2019-06-15 23:29:18 +02:00 by Kai Jægersen · 7 comments

text_current_caracter.gif

System Information
Operating system: Windows-10-10.0.17763 64 Bits
Graphics card: GeForce GTX 1080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 419.17

Blender Version
Broken: version: 2.80 (sub 74), branch: blender2.7, commit date: 2019-06-14 23:24, hash: blender/blender@0fd96b4128
Worked: Never. 2.79 has the same issue.

Short description of error
Property current_character and select_end_character on bpy.types.Text objects both report wrong values for some unicode characters. Some characters have a size of 2 and some have 3.

Exact steps for others to reproduce the error

  1. Open blend-file
  2. Set caret position at the end of line 13
  3. Run script and see console
  4. Set caret position at the end of line 14
  5. Run script and see console
  6. Take note of the caret position difference

[Based on the default startup or an attached .blend file (as simple as possible)]

text_current_character.blend

![text_current_caracter.gif](https://archive.blender.org/developer/F7105041/text_current_caracter.gif) **System Information** Operating system: Windows-10-10.0.17763 64 Bits Graphics card: GeForce GTX 1080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 419.17 **Blender Version** Broken: version: 2.80 (sub 74), branch: blender2.7, commit date: 2019-06-14 23:24, hash: `blender/blender@0fd96b4128` Worked: Never. 2.79 has the same issue. **Short description of error** Property `current_character` and `select_end_character` on `bpy.types.Text` objects both report wrong values for some unicode characters. Some characters have a size of 2 and some have 3. **Exact steps for others to reproduce the error** 1. Open blend-file 2. Set caret position at the end of line 13 3. Run script and see console 4. Set caret position at the end of line 14 5. Run script and see console 6. Take note of the caret position difference [Based on the default startup or an attached .blend file (as simple as possible)] [text_current_character.blend](https://archive.blender.org/developer/F7105046/text_current_character.blend)
Author

Added subscriber: @KaiJaegersen

Added subscriber: @KaiJaegersen
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Philipp Oeser self-assigned this 2019-06-17 13:41:26 +02:00
Member

Can confirm.

current_character and select_end_character are directly pointing to text DNA curc, selc (and these can indeed inherit the "error" of unicode characters having a differrent length that one...)

Guess this could be resolved by making a rna property func that takes these into account using txt_utf8_offset_to_index or BLI_str_utf8_size...
Can check [might take a bit though...]

Can confirm. `current_character` and `select_end_character` are directly pointing to text DNA `curc`, `selc` (and these can indeed inherit the "error" of unicode characters having a differrent length that one...) Guess this could be resolved by making a rna property func that takes these into account using `txt_utf8_offset_to_index` or `BLI_str_utf8_size`... Can check [might take a bit though...]
Author

In #65843#702373, @lichtwerk wrote:
Can confirm.

current_character and select_end_character are directly pointing to text DNA curc, selc (and these can indeed inherit the "error" of unicode characters having a differrent length that one...)

Guess this could be resolved by making a rna property func that takes these into account using txt_utf8_offset_to_index or BLI_str_utf8_size...
Can check [might take a bit though...]

The characters are unusual to come across so this isn't exactly a pressing issue, but thanks for looking into it!

Having it report correct caret position would be helpful for extending the functionality of the text editor using python.

> In #65843#702373, @lichtwerk wrote: > Can confirm. > > `current_character` and `select_end_character` are directly pointing to text DNA `curc`, `selc` (and these can indeed inherit the "error" of unicode characters having a differrent length that one...) > > Guess this could be resolved by making a rna property func that takes these into account using `txt_utf8_offset_to_index` or `BLI_str_utf8_size`... > Can check [might take a bit though...] The characters are unusual to come across so this isn't exactly a pressing issue, but thanks for looking into it! Having it report correct caret position would be helpful for extending the functionality of the text editor using python.

Added subscriber: @ideasman42

Added subscriber: @ideasman42

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Fixed blender/blender@8096190d11
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#65843
No description provided.