| Ticket UUID: | 4f309446ea26e55d819364e3699bf804ec20cdfa | |||
| Title: | revised_text: wrong answer for "index displaylines", and failed assertion | |||
| Type: | Bug | Version: | revised_text | |
| Submitter: | fvogel | Created on: | 2019-04-19 13:36:38 | |
| Subsystem: | 18. [text] | Assigned To: | fvogel | |
| Priority: | 5 Medium | Severity: | Minor | |
| Status: | Closed | Last Modified: | 2019-08-21 18:54:14 | |
| Resolution: | Fixed | Closed By: | fvogel | |
| Closed on: | 2019-08-21 18:54:14 | |||
| Description: |
Copy and paste this in tclsh linking to the revised_text Tk branch:
package require Tk
text .t -width 15
.t insert end "This is a random text that is just\
here for the purpose of this test.\n"
.t insert end "This is a random text that is just\
here for the purpose of this test.\n"
.t index "2.50 - 100 displaylines" ; # returns 1.19
pack .t
.t index "2.50 - 100 displaylines" ; # returns 1.65 or 1.5 (depending on whether the lines are up-to-date or not)
Both answers should be equal, and both are wrong: 1.0 should be returned in both cases. As another approach to the same issue, in [5fc8506e] I have added two new tests textIndex-19.12.1 and textIndex-19.12.2 triggering 'assertion failed' in tkTextDisp.c:7818: assert(info.displayLineNo == 0) triggers. These tests do the same as the above snippet, i.e. requesting calculation of an index that would be far before the start of the displayed text. Cross-ref: I stumbled on this while analyzing [c8ccd1899c] for the revised_text case. | |||
| User Comments: |
fvogel added on 2019-08-21 18:54:14:
Merged to revised_text branch. I didn't find a better way to fix this issue, and Gregor did not answer my (private) request for review. fvogel added on 2019-05-10 15:53:59: I have now dealt with this ticket in [7d60f42757], sitting in bugfix branch bug-4f309446ea off the revised_text branch. The two new tests textIndex-19.12.1 and textIndex-19.12.2 added in [5fc8506e] to demonstrate the problems now pass. No test is newly failing. Moreover the following script now produces the expected results:
package require Tk
text .t -width 15
set str "This is a random text that is just\
here for the purpose of this test.\n"
.t insert end "$str$str"
.t index "2.50 - 100 displaylines" ; # returns: 1.19 (expected: 1.19)
.t index "2.50 - 119 displaylines" ; # returns: 1.0 (expected: 1.0)
.t index "2.50 - 120 displaylines" ; # returns: 1.68 for anything greater
; # than -120 displaylines (expected: 1.0)
pack .t ; update
.t index "2.50 - 100 displaylines" ; # returns: 1.65 or 1.5 (depending on whether
; # the lines are up-to-date or not) (expected: 1.0)
A review of this fix would be a good idea I think. fvogel added on 2019-05-09 16:26:26: A start of an analysis: 1. When the text widget is not mapped it has a small width and only one character will fit on each display line. Therefore saying "+/- 100 displaylines" may not result in crossing the start or end of the text as we may think at first. 2. Test textIndex-19.12.2 in [5fc8506e] looks for .t index "2.50 + 100 displaylines" but since the text widget is not mapped this does in fact not intend to go further than the end of the text. Instead it will find an index before the end of the text. However it triggers the assertion in tkTextDisp.c:7818: assert(info.displayLineNo == 0). I think this assertion is simply wrong and that info.displayLineNo can be different from zero since we're not yet at end of the text. So this assertion should be removed IMO. Then, to make textIndex-19.12.2 test what we want it to test we must request much more than "2.50 + 100 displaylines", rather say "2.50 + 1000 displaylines". Then textIndex-19.12.2 succeeds. Suggested patch to fix point 2. is therefore:
Index: generic/tkTextDisp.c
==================================================================
--- generic/tkTextDisp.c
+++ generic/tkTextDisp.c
@@ -7813,11 +7813,10 @@
break;
}
FreeDLines(textPtr, info.dLinePtr, NULL, DLINE_FREE_TEMP);
ComputeDisplayLineInfo(textPtr, indexPtr, &info);
ComputeMissingMetric(textPtr, &info, THRESHOLD_LINE_OFFSET, displayLineOffset);
- assert(info.displayLineNo == 0);
}
} else if (displayLineOffset < 0) {
info.numDispLines = info.displayLineNo + 1;
while (true) {
Index: tests/textIndex.test
==================================================================
--- tests/textIndex.test
+++ tests/textIndex.test
@@ -830,11 +830,11 @@
test textIndex-19.12.1 {Display lines} {
.t index "2.50 - 100 displaylines"
} {1.0}
test textIndex-19.12.2 {Display lines} {
- .t compare [.t index "2.50 + 100 displaylines"] == end
+ .t compare [.t index "2.50 + 1000 displaylines"] == end
} {1}
test textIndex-19.13 {Display lines} {
destroy {*}[pack slaves .]
text .txt -height 1 -wrap word -yscroll ".sbar set" -width 400
3. Test textIndex-19.12.1 in [5fc8506e] looks for .t index "2.50 - 100 displaylines". Again, since the text widget is not mapped this does in fact not intend to go before the start of the text. Asking for "2.50 + 1000 displaylines" however should go to the start of the text, but instead returns 1.68, that is the end of the first logical line (remember there is only one character per display line because the widget is not mapped). This bug remains to be analyzed. | |||
Home
Timeline
Branches
Tags
Forum
Tickets
Download
Wiki