Menu

#2949 Weird indices

obsolete: 8.5.10
closed-fixed
7
2012-02-28
2012-02-13
No

text .t
pack .t
for {set i 1} {$i < 10} {incr i} {
.t insert end "Line $i\n"
}
.t mark set insert 1.0
.t configure -start 5 -end 5
.t index insert

This returns:
* -3.0 in Tk 8.5.9
* 0.6 in core-8-5-branch
* "bad text index" error in bug-1630262 branch

The question is what the correct output should be for this text widget showing ZERO lines (since -startline == -endline).

Indices should be clamped to the -startline/-endline range of the text widget, so that no negative (or larger than the number of lines) index is ever returned. The two first answers are therefore both wrong.

Also in core-8-5-branch is the fix for bug 1630271 (commit 61a3685ac2), which makes the "bad text index" error in branch bug-1630262: marks located outside the -startline/-endline range being not reachable from the considered peer, an error is thrown.

I think "bad text index" is the right answer in this "corner" case.

The problem then is consistency, since:

.t mark names ;# --> insert current
.t index current ;# --> 1.0

Discussion

  • Francois VOGEL

    Francois VOGEL - 2012-02-18

    Pushed a fix for this bug in branch bug-1630262.

    This branch now has fixes for the following bugs, which are more or less linked: 1630262, 1615425, and the present 3487407

    After carefully thinking at this, I decided to allow for the insert and current marks to be present in an empty peer, but their index is always 1.0. This does not harm and allows for better support of existing code since the text widget in fact is always supposed to contain these two special marks.

    Please review and comment as needed.

     
  • Francois VOGEL

    Francois VOGEL - 2012-02-19
    • priority: 5 --> 7
    • summary: Weird indexes --> Weird indices
     
  • Francois VOGEL

    Francois VOGEL - 2012-02-28
    • status: open --> closed-fixed
     
  • Francois VOGEL

    Francois VOGEL - 2012-02-28

    Merged in core-8-5-branch and trunk. Closing now.