Tk Source Code

View Ticket
Login
Ticket UUID: 3487407
Title: Weird indices
Type: Bug Version: obsolete: 8.5.10
Submitter: fvogel Created on: 2012-02-13 22:16:35
Subsystem: 18. [text] Assigned To: fvogel
Priority: 7 High Severity: Minor
Status: Closed Last Modified: 2014-02-19 21:42:31
Resolution: Fixed Closed By: fvogel
    Closed on: 2013-09-23 21:41:31
Description:
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
User Comments: fvogelnew1 added on 2012-02-29 03:50:10:

allow_comments - 1

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

fvogelnew1 added on 2012-02-19 05:04:20:
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.