summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvincentdarley <vincentdarley>2004-09-23 14:56:35 (GMT)
committervincentdarley <vincentdarley>2004-09-23 14:56:35 (GMT)
commitff49febdf99cde8f07bc81a9e5ad5cc8810c8b1f (patch)
tree988d0d18dbc1fa77612fcdb7e3ca8fb110c77785
parent1709b7b141a400dba7c70616c6a6d46cb0ceaea0 (diff)
downloadtk-ff49febdf99cde8f07bc81a9e5ad5cc8810c8b1f.zip
tk-ff49febdf99cde8f07bc81a9e5ad5cc8810c8b1f.tar.gz
tk-ff49febdf99cde8f07bc81a9e5ad5cc8810c8b1f.tar.bz2
text widget search fix
-rw-r--r--ChangeLog6
-rw-r--r--generic/tkText.c21
-rw-r--r--tests/text.test30
3 files changed, 55 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 44113c3..691728b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2004-09-23 Vince Darley <vincentdarley@users.sourceforge.net>
+
+ * generic/tkTest.c
+ * tests/text.test: fix and tests for [Bug 1026485] -- negative
+ text search ranges should not lead to any matches.
+
2004-09-22 Jeff Hobbs <jeffh@ActiveState.com>
* win/tkWinInt.h (TkWinDisplayChanged): added decl
diff --git a/generic/tkText.c b/generic/tkText.c
index f8a1abd..eb7beb7 100644
--- a/generic/tkText.c
+++ b/generic/tkText.c
@@ -14,7 +14,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkText.c,v 1.53 2004/09/10 13:42:45 rmax Exp $
+ * RCS: @(#) $Id: tkText.c,v 1.54 2004/09/23 14:57:03 vincentdarley Exp $
*/
#include "default.h"
@@ -4923,6 +4923,25 @@ SearchPerform(interp, searchSpecPtr, patObj, fromPtr, toPtr)
* Find the optional end location, similarly.
*/
if (toPtr != NULL) {
+ CONST TkTextIndex *indexToPtr, *indexFromPtr;
+ TkText *textPtr = (TkText*)(searchSpecPtr->clientData);
+
+ indexToPtr = TkTextGetIndexFromObj(interp, textPtr, toPtr);
+ if (indexToPtr == NULL) {
+ return TCL_ERROR;
+ }
+ indexFromPtr = TkTextGetIndexFromObj(interp, textPtr, fromPtr);
+ /*
+ * Check for any empty search range here. It might be better
+ * in the future to embed that in SearchCore (whose default
+ * behaviour is to wrap when given a negative search range).
+ */
+ if (searchSpecPtr->backwards) {
+ if (TkTextIndexCmp(indexFromPtr, indexToPtr) == -1) return TCL_OK;
+ } else {
+ if (TkTextIndexCmp(indexFromPtr, indexToPtr) == 1) return TCL_OK;
+ }
+
if ((*searchSpecPtr->lineIndexProc)(interp, toPtr, searchSpecPtr,
&searchSpecPtr->stopLine,
&searchSpecPtr->stopOffset) != TCL_OK) {
diff --git a/tests/text.test b/tests/text.test
index 63b43ce..aeebf6f 100644
--- a/tests/text.test
+++ b/tests/text.test
@@ -6,7 +6,7 @@
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.
#
-# RCS: @(#) $Id: text.test,v 1.32 2004/09/10 12:13:43 vincentdarley Exp $
+# RCS: @(#) $Id: text.test,v 1.33 2004/09/23 14:57:25 vincentdarley Exp $
package require tcltest 2.1
eval tcltest::configure $argv
@@ -2677,6 +2677,34 @@ test text-20.175 {TextSearchCmd, regexp search multi-line} {
set res
} {2.3 13}
+test text-20.176 {TextSearchCmd, empty search range} {
+ deleteWindows
+ pack [text .t2]
+ .t2 insert 1.0 "a\na\na\n"
+ .t2 search -- a 2.0 1.0
+} {}
+
+test text-20.177 {TextSearchCmd, empty search range} {
+ deleteWindows
+ pack [text .t2]
+ .t2 insert 1.0 "a\na\na\n"
+ .t2 search -backwards -- a 1.0 2.0
+} {}
+
+test text-20.178 {TextSearchCmd, empty search range} {
+ deleteWindows
+ pack [text .t2]
+ .t2 insert 1.0 "a\na\na\n"
+ .t2 search -- a 1.0 1.0
+} {}
+
+test text-20.179 {TextSearchCmd, empty search range} {
+ deleteWindows
+ pack [text .t2]
+ .t2 insert 1.0 "a\na\na\n"
+ .t2 search -backwards -- a 2.0 2.0
+} {}
+
deleteWindows
text .t2 -highlightthickness 0 -bd 0 -relief flat -padx 0 -width 100
pack .t2