Tk Source Code

View Ticket
Login
Ticket UUID: df89872c942b683b917652dd5b699f39862540d1
Title: revised_text: indices incremented by line are not preserving the column correctly.
Type: Bug Version: revised_text
Submitter: bll Created on: 2017-05-27 21:44:23
Subsystem: -- New Widgets Assigned To: fvogel
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2021-05-28 08:34:28
Resolution: Fixed Closed By: fvogel
    Closed on: 2021-05-28 08:34:28
Description:
When incrementing an index by line, the manual states:
"..., retaining the same character position within the line."
When using unicode, the character position is not preserved.

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]"

Output is: 2.2 3.2, 2.6 1.8
Output should be 2.4 3.4, 2.4 1.4.

Reference: https://stackoverflow.com/questions/44078060/tk-text-widget-index-expressions-and-unicode
User Comments: fvogel added on 2021-05-28 08:34:28:
GitHub Actions shows that this test does no longer fail on Linux and macOS. Closing.

fvogel added on 2021-05-27 19:35:11:

Not a timing issue. It's just that the requested font does not have the same characteristics on all platforms (plus some glyphs are replaced by a dotted square on the mac).

I have pushed a fix, see [e8c0d6ee]. Works for me on Windows and macOS (Catalina), with different fonts subsituted to the requested {Courier -24}.

Let's see what GitHub actions thinks about it.


bll added on 2021-05-08 16:26:07:
Yes, a typo.

No more ideas on the textIndex issue.  I would expect some sort of timing
issues (like many of the other tests), but we can't duplicate it.

The notification message is not a bug, once known that it is a message to
the daemon and not an X11 message display.

fvogel added on 2021-05-08 14:02:37:

What was (d)? I think there is a typo in your report, (d) must be xvfb-run.

Anyway. So you cannot reproduce the failure of textIndex-19.14 from GitHub Actions either since no textIndex failure happens for you either, with or without xvfb.

Regarding the notification sent by the test suite I had noticed it as well. I'm wondering if the answer here, despite the question was not the same, could give some light on this: notify_send is sending an actual message to the notification daemon. If you think the current behavior is a problem could you please open a separate ticket for it in order to not confuse this one. Thanks!


bll added on 2021-05-04 21:02:28:
Well, it's fairly consistent...

bll@ubuntu2004:~/tcl-work/tk/unix$ for f in ubuntu*; do egrep FAILED $f | wc -l; done
132 (a)
134 (b)
132 (c)
118 (d)

Tcl : core-8-6-branch
Tk : revised_text 

a,b,c : default gnome desktop
a,b : busy system
c : xvfb-run

No textIndex failures.

With xvfb, An alert window popped up on the main display (Alert, This is an alert).   This is rather bizarre, as the alert should pop up in the virtual
frame buffer.  How could it even have access to a different display?
May be a very strange bug there.

bll@ubuntu2004:~/tcl-work/tk/unix$ xvfb-run bash -c 'echo $DISPLAY'
:99
bll@ubuntu2004:~/tcl-work/tk/unix$ echo $DISPLAY
:0

bll added on 2021-05-04 20:11:13:
Ubuntu 20.04 has 66 failures, without using xvfb, and the VM is quite busy
doing a 'apt full-upgrade'.
None of the failures are in textIndex.

After the upgrade finishes, I will test again with and without xvfb.

bll added on 2021-05-04 19:19:19:
- Does Ubuntu 20.04 use the same font as Debian when running this test?
- Is there a way to get a window capture during the test so that the
  testers can see what the test window looks like?  I don't recall if
  this is possible in Tk without the Img package.  But there are x11
  tools that can do a screen capture.

I believe I have a Ubuntu 20.04 vm, I can try running the test.

fvogel added on 2021-05-04 16:53:05:

Good idea! I have tried the same incantation as run at GitHub Actions, but I still couldn't reproduce unfortunately.


bll added on 2021-05-03 22:07:26:
Well, the one thing I would try on Debian would be to run the xvfb with the 
same arguments as the git platform uses, set the DISPLAY variable to point to 
the vfb and run the tests.  

Also can try setting up an ubuntu 20.04 vm and do the same thing.

fvogel added on 2021-05-03 15:27:44:

Test textIndex-19.14 fails at GitHub Actions, exactly the way it failed previously (see below) on Windows before [12dcee81e3]:

---- Result was:
2.4 3.4 2.4 3.4 2.4 1.4 2.4 1.4
---- Result should have been (exact matching):
2.4 3.4 2.4 3.2 2.4 1.4 2.6 1.6
==== textIndex-19.14 FAILED

I cannot reproduce this failure, on either Windows (with MSVC) or Linux Debian 10 (with gcc), when the revised_text branch is built against either core-8-branch or core-8-6-branch.

Suspecting missing support of UTF-8 at some place (at GitHub?). Ideas, anyone?


gcramer added on 2017-05-28 15:59:31:
Many thanks for the fix, I didn't expect that the test suite will not be loaded with encoding UTF-8.

> BTW, what does this sequence of Unicode characters mean?

I don't know.

fvogel added on 2017-05-28 15:41:50:

[12dcee81e3] fixes the new test textIndex-19.14 introduced in [d0a7426b10].

BTW, what does this sequence of Unicode characters mean?


fvogel added on 2017-05-28 15:14:03:

This commit [d0a7426b10] adds textIndex-19.14 but this test does not work for me on Windows:

==== textIndex-19.14 Display lines + lines with Unicode text FAILED
==== Contents of test case:

    destroy .t
    pack [text .t -font {Courier -24}]
    update
    .t insert end "abcdefgh\nð░ð▒ð▓ð│Êæð┤ðÁÐö\nõ©Çõ╝èõ¥ØÕî╗ÕÆ┐ÕÖ½µ¼╣µ│å"
    .t sync
    set res {}
    lappend res [.t index "1.4 +1lines"] [.t index "1.4 +2lines"]
    lappend res [.t index "1.4 +1displaylines"] [.t index "1.4 +2displaylines"]
    lappend res [.t index "3.4 -1lines"] [.t index "3.4 -2lines"]
    lappend res [.t index "3.4 -1displaylines"] [.t index "3.4 -2displaylines"]
    set res

---- Result was:
2.4 3.4 2.4 3.4 2.4 1.4 2.4 1.4
---- Result should have been (exact matching):
2.4 3.4 2.4 3.2 2.4 1.4 2.6 1.6
==== textIndex-19.14 FAILED
The above is a copy/paste of the output I see.

I would rather have expected to see:

[...]
    .t insert end "abcdefgh\nабвгґдеє\n一伊依医咿噫欹泆"
[...]
but I'm unsure the problem is in that output.


gcramer added on 2017-05-28 12:30:08:

At first: the documentation is insufficient, I replaced it with a refined description:

+ count ?submodifier? lines

Adjust the index forward by "count" lines, retaining the same position within the line. If there are fewer than "count" lines after the line containing the current index, then set the index to refer to the same position on the last line of the text. Then, if the line is not long enough to contain a character at the indicated position, adjust the character position to refer to the last character of the line (the newline). Spaces on either side of "count" are optional.

If the "display" submodifier is given, then each visual display line is counted separately, and in this case the position is determined by the current pixel position.

Otherwise, if "any" (or no modifier) is given, then each logical line (no matter how many times it is visually wrapped) counts just once, and the position is determined by the character position.

The implementation of the legacy text widget (the revised text widget has inherited the legacy implementation at this place) did the right implementation for the case with sub-modifier "display". But the implementation for the other case is mysterious. Although the author has written this comment:

/*
 * This doesn't work quite right if using a proportional font or
 * UTF-8 characters with varying numbers of bytes, or if there are
 * embedded windows, images, etc. The cursor will bop around,
 * keeping a constant number of bytes (not characters) from the
 * left edge (but making sure not to split any UTF-8 characters),
 * regardless of the x-position the index corresponds to. The
 * proper way to do this is to get the x-position of the index and
 * then pick the character at the same x-position in the new line.
 */

he implemented indeed a version based on byte count, and this makes no sense at all. The alternative, described in the comment, to use the same x-position also don't makes sense (in this context). So I decided to replace this with a version based on the character position (index), conform to the revised description in manual (see above).

In this way the revised version is nearly compatible to the legacy version, the old implementation based on byte count is erroneous anyway.

I've committed [d0a7426b10], and the following test script

pack [text .t -font {Courier -24}
update
.t insert end "abcdefgh\nабвгґдеє\n一伊依医咿噫欹泆"
.t sync
puts -nonewline "[.t index 1.4+1lines] [.t index 1.4+2lines] "
puts -nonewline "[.t index 1.4+1displaylines] [.t index 1.4+2displaylines] "
puts -nonewline "[.t index 3.4-1lines] [.t index 3.4-2lines] "
puts -nonewline "[.t index 3.4-1displaylines] [.t index 3.4-2displaylines]"
puts ""

gives the correct output: 2.4 3.4 2.4 3.2 2.4 1.4 2.6 1.6

This test script has been added to the test suite as textIndex-19.14.