Tk and Unicode text widget indexes

(this question is based on which )

Consider the following code:

package require Tk 8.6

pack [text .t]
.t insert end "abcdefgh\nґє\n一伊依医咿噫欹泆"

puts "[.t index 1.4+1l] [.t index 1.4+2l]"
puts "[.t index 3.4-1l] [.t index 3.4-2l]"

exit 0

      

Output:

2.2 3.2
2.6 1.8

      

I would rather expect +1l

and -1l

save the column if the string is long enough, i.e. print 2.4 3.4

and 2.4 1.4

. It looks like the result depends on the number of bytes needed to encode each character.

Should it be so? Is it documented somewhere?

+1


source to share


1 answer


What font are you using? What exact Tk version are you using? (This should be reported by doing puts [package require Tk]

.)

I think the text widget is currently using the character width when working out the actual movements when traversing the index line by line. This has changed between past versions. The problem is that different bits of code require different things: sometimes you need visible movements (for example, when handling user engine movements, especially with tabs installed), and sometimes you need character space movements (which is what you expect).



Tk should never do anything (you can see) with the byte width of Unicode characters. He really should handle this transparently (at least for any character on the Basic Multilingual Plane, you can find bugs outside of that).

0


source







All Articles