From da6ca47d6d53db41a974859bf961ddc2d8f9d1d3 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 b3db9087841c153570ebfc1edd7ac33f3dd8bbcf 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