From b953acd1adcee2fe7ed421057e3777dfc262d8a3 Mon Sep 17 00:00:00 2001 From: fvogel Date: Mon, 29 Jun 2015 21:57:04 +0000 Subject: Fixed bug [2886436fff] - [.txt delete] deletes before start index - This is option 2: don't change the behavior of the text widget, but document it better. --- doc/text.n | 7 +++++-- generic/tkText.c | 14 +++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/doc/text.n b/doc/text.n index b11363d..1ccadbb 100644 --- a/doc/text.n +++ b/doc/text.n @@ -1216,8 +1216,11 @@ If \fIindex2\fR does not specify a position later in the text than \fIindex1\fR then no characters are deleted. If \fIindex2\fR is not specified then the single character at \fIindex1\fR is deleted. -It is not allowable to delete characters in a way that would leave -the text without a newline as the last character. +Attempts to delete characters in a way that would leave +the text without a newline as the last character will be tweaked by the +text widget to avoid this. In particular, attempts to delete complete +lines of text up to the end of the text will result in +deletion of the newline character just preceding \fIindex1\fR. The command returns an empty string. If more indices are given, multiple ranges of text will be deleted. All indices are first checked for validity before any deletions are made. diff --git a/generic/tkText.c b/generic/tkText.c index 139e71d..5042582 100644 --- a/generic/tkText.c +++ b/generic/tkText.c @@ -3001,11 +3001,15 @@ DeleteIndexRange( * file (just before the dummy line) is being deleted, then back up index * to just before the newline. If there is a newline just before the first * character being deleted, then back up the first index too, so that an - * even number of lines gets deleted. Furthermore, remove any tags that - * are present on the newline that isn't going to be deleted after all - * (this simulates deleting the newline and then adding a "clean" one back - * again). Note that index1 and index2 might now be equal again which - * means that no text will be deleted but tags might be removed. + * even number of lines gets deleted. The idea is that a deletion + * involving a range starting at a line start and including the final \n + * (i.e. index2 is "end") is an attempt to delete complete lines, so the + * \n before the deleted block shall become the new final \n. Furthermore, + * remove any tags that are present on the newline that isn't going to be + * deleted after all (this simulates deleting the newline and then adding + * a "clean" one back again). Note that index1 and index2 might now be + * equal again which means that no text will be deleted but tags might be + * removed. */ line1 = TkBTreeLinesTo(textPtr, index1.linePtr); -- cgit v0.12 From 6b9f74b94131d093483c64f7ceabf120c0d7cafc Mon Sep 17 00:00:00 2001 From: fvogel Date: Tue, 14 Jul 2015 19:18:58 +0000 Subject: Tried to be even clearer. --- doc/text.n | 7 ++++--- generic/tkText.c | 19 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/doc/text.n b/doc/text.n index 1ccadbb..5b7804a 100644 --- a/doc/text.n +++ b/doc/text.n @@ -1218,9 +1218,10 @@ If \fIindex2\fR is not specified then the single character at \fIindex1\fR is deleted. Attempts to delete characters in a way that would leave the text without a newline as the last character will be tweaked by the -text widget to avoid this. In particular, attempts to delete complete -lines of text up to the end of the text will result in -deletion of the newline character just preceding \fIindex1\fR. +text widget to avoid this. In particular, deletion of complete lines of +text up to the end of the text will also delete the newline character just +before the deleted block so that it is replaced by the new final newline +of the text widget. The command returns an empty string. If more indices are given, multiple ranges of text will be deleted. All indices are first checked for validity before any deletions are made. diff --git a/generic/tkText.c b/generic/tkText.c index 5042582..eb2d77a 100644 --- a/generic/tkText.c +++ b/generic/tkText.c @@ -3000,16 +3000,15 @@ DeleteIndexRange( * dummy empty line at the end of the text. If the final newline of the * file (just before the dummy line) is being deleted, then back up index * to just before the newline. If there is a newline just before the first - * character being deleted, then back up the first index too, so that an - * even number of lines gets deleted. The idea is that a deletion - * involving a range starting at a line start and including the final \n - * (i.e. index2 is "end") is an attempt to delete complete lines, so the - * \n before the deleted block shall become the new final \n. Furthermore, - * remove any tags that are present on the newline that isn't going to be - * deleted after all (this simulates deleting the newline and then adding - * a "clean" one back again). Note that index1 and index2 might now be - * equal again which means that no text will be deleted but tags might be - * removed. + * character being deleted, then back up the first index too. The idea is + * that a deletion involving a range starting at a line start and + * including the final \n (i.e. index2 is "end") is an attempt to delete + * complete lines, so the \n before the deleted block shall become the new + * final \n. Furthermore, remove any tags that are present on the newline + * that isn't going to be deleted after all (this simulates deleting the + * newline and then adding a "clean" one back again). Note that index1 and + * index2 might now be equal again which means that no text will be + * deleted but tags might be removed. */ line1 = TkBTreeLinesTo(textPtr, index1.linePtr); -- cgit v0.12 From 1b8e0125b84845a3b0ba6b69d6c4894aa15627f2 Mon Sep 17 00:00:00 2001 From: fvogel Date: Sun, 27 Mar 2016 15:00:58 +0000 Subject: Beginning of fix for [18c08df753] - Reverted [296bd4c3], and adjusted textDisp-4.9 accordingly by adding one fixedHeight on the two necessary places in the test result --- generic/tkText.c | 12 +++++++++--- tests/text.test | 3 +-- tests/textDisp.test | 8 ++++---- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/generic/tkText.c b/generic/tkText.c index 341ec0f..4942913 100644 --- a/generic/tkText.c +++ b/generic/tkText.c @@ -3003,9 +3003,11 @@ DeleteIndexRange( * The code below is ugly, but it's needed to make sure there is always a * dummy empty line at the end of the text. If the final newline of the * file (just before the dummy line) is being deleted, then back up index - * to just before the newline. Furthermore, remove any tags that are - * present on the newline that isn't going to be deleted after all (this - * simulates deleting the newline and then adding a "clean" one back + * to just before the newline. If there is a newline just before the first + * character being deleted, then back up the first index too, so that an + * even number of lines gets deleted. Furthermore, remove any tags that + * are present on the newline that isn't going to be deleted after all + * (this simulates deleting the newline and then adding a "clean" one back * again). Note that index1 and index2 might now be equal again which * means that no text will be deleted but tags might be removed. */ @@ -3020,6 +3022,10 @@ DeleteIndexRange( oldIndex2 = index2; TkTextIndexBackChars(NULL, &oldIndex2, 1, &index2, COUNT_INDICES); line2--; + if ((index1.byteIndex == 0) && (line1 != 0)) { + TkTextIndexBackChars(NULL, &index1, 1, &index1, COUNT_INDICES); + line1--; + } arrayPtr = TkBTreeGetTags(&index2, NULL, &arraySize); if (arrayPtr != NULL) { for (i = 0; i < arraySize; i++) { diff --git a/tests/text.test b/tests/text.test index 7c1731d..2ca5d54 100644 --- a/tests/text.test +++ b/tests/text.test @@ -1272,10 +1272,9 @@ test text-17.8 {DeleteChars procedure} { .t tag add sel 1.0 end .t delete 4.0 end list [.t tag ranges sel] [.t get 1.0 end] -} {{1.0 4.0} {Line 1 +} {{1.0 3.5} {Line 1 abcde 12345 - }} test text-17.9 {DeleteChars procedure} { setup diff --git a/tests/textDisp.test b/tests/textDisp.test index 885c940..bb009ad 100644 --- a/tests/textDisp.test +++ b/tests/textDisp.test @@ -657,7 +657,7 @@ test textDisp-4.9 {UpdateDisplayInfo, filling in extra vertical space} {textfont update .t delete 15.0 end list [.t bbox 7.0] [.t bbox 12.0] -} [list [list [expr {$hlth + $px + $bw}] [expr {$hlth + $py + $bw + $fixedHeight}] $fixedWidth $fixedHeight] [list [expr {$hlth + $px + $bw}] [expr {$hlth + $py + $bw + 6 * $fixedHeight}] $fixedWidth $fixedHeight]] +} [list [list [expr {$hlth + $px + $bw}] [expr {$hlth + $py + $bw + 2 * $fixedHeight}] $fixedWidth $fixedHeight] [list [expr {$hlth + $px + $bw}] [expr {$hlth + $py + $bw + 7 * $fixedHeight}] $fixedWidth $fixedHeight]] test textDisp-4.10 {UpdateDisplayInfo, filling in extra vertical space} { .t delete 1.0 end .t insert end "1\n2\n3\n4\n5\nLine 6 is such a long line that it wraps around.\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17" @@ -666,7 +666,7 @@ test textDisp-4.10 {UpdateDisplayInfo, filling in extra vertical space} { .t delete 13.0 end update list [.t index @0,0] $tk_textRelayout $tk_textRedraw -} {6.0 {13.0 7.0 6.40 6.20 6.0} {6.0 6.20 6.40 7.0 13.0}} +} {5.0 {12.0 7.0 6.40 6.20 6.0 5.0} {5.0 6.0 6.20 6.40 7.0 12.0}} test textDisp-4.11 {UpdateDisplayInfo, filling in extra vertical space} { .t delete 1.0 end .t insert end "1\n2\n3\n4\n5\nLine 6 is such a long line that it wraps around, not once but really quite a few times.\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17" @@ -675,7 +675,7 @@ test textDisp-4.11 {UpdateDisplayInfo, filling in extra vertical space} { .t delete 14.0 end update list [.t index @0,0] $tk_textRelayout $tk_textRedraw -} {6.60 {14.0 7.0 6.80 6.60} {6.60 6.80 7.0 14.0}} +} {6.40 {13.0 7.0 6.80 6.60 6.40} {6.40 6.60 6.80 7.0 13.0}} test textDisp-4.12 {UpdateDisplayInfo, filling in extra vertical space} { .t delete 1.0 end .t insert end "1\n2\n3\n4\n5\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16" @@ -3697,7 +3697,7 @@ test textDisp-28.1 {"yview" option with bizarre scroll command} { set result [.t2.t index @0,0] update lappend result [.t2.t index @0,0] -} {6.0 2.0} +} {6.0 1.0} test textDisp-29.1 {miscellaneous: lines wrap but are still too long} {textfonts} { catch {destroy .t2} -- cgit v0.12