From 5649a675dfb76712afa08a8711459fc263bdbeb3 Mon Sep 17 00:00:00 2001 From: ericm Date: Fri, 21 Jul 2000 23:44:11 +0000 Subject: * tests/text.test: Added tests for searching when text is elided. * generic/tkText.c (TextSearchCmd): Text search was not returning the correct index when the search covered (but did not search) elided characters; corrected this by adjusting the match index by the number of elided characters preceeding the start of the match, just as is done with embedded windows, etc. [Bug: 5470]. --- ChangeLog | 14 ++++++++++++-- generic/tkText.c | 14 +++++++++----- tests/text.test | 31 ++++++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index d2e8a12..9d25081 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,18 @@ +2000-07-21 Eric Melski + + * tests/text.test: Added tests for searching when text is elided. + + * generic/tkText.c (TextSearchCmd): Text search was not returning + the correct index when the search covered (but did not search) + elided characters; corrected this by adjusting the match index by + the number of elided characters preceeding the start of the match, + just as is done with embedded windows, etc. [Bug: 5470]. + 2000-07-21 Mo DeJong * win/configure.in: Add TK_STUB_LIB_FLAG and - TK_BUILD_STUB_LIB_SPEC. These are needed to - build a stub enabled extension. + TK_BUILD_STUB_LIB_SPEC. These are needed to build a stub enabled + extension. 2000-07-20 Eric Melski diff --git a/generic/tkText.c b/generic/tkText.c index f4ebda7..cd5cac0 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.15 2000/07/19 18:13:50 ericm Exp $ + * RCS: @(#) $Id: tkText.c,v 1.16 2000/07/21 23:44:11 ericm Exp $ */ #include "default.h" @@ -1952,7 +1952,8 @@ TextSearchCmd(textPtr, interp, argc, argv) /* * The index information returned by the regular expression * parser only considers textual information: it doesn't - * account for embedded windows or any other non-textual info. + * account for embedded windows, elided text (when we are not + * searching elided text) or any other non-textual info. * Scan through the line's segments again to adjust both * matchChar and matchCount. * @@ -1961,13 +1962,16 @@ TextSearchCmd(textPtr, interp, argc, argv) * of the line. */ + curIndex.linePtr = linePtr; curIndex.byteIndex = 0; for (segPtr = linePtr->segPtr, leftToScan = matchByte; leftToScan >= 0 && segPtr; segPtr = segPtr->nextPtr) { - if (segPtr->typePtr != &tkTextCharType) { + if (segPtr->typePtr != &tkTextCharType || \ + (!searchElide && TkTextIsElided(textPtr, &curIndex))) { matchByte += segPtr->size; - continue; + } else { + leftToScan -= segPtr->size; } - leftToScan -= segPtr->size; + curIndex.byteIndex += segPtr->size; } for (leftToScan += matchLength; leftToScan > 0; segPtr = segPtr->nextPtr) { diff --git a/tests/text.test b/tests/text.test index 651e7d8..1d3a7bd 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.10 2000/02/03 17:29:58 ericm Exp $ +# RCS: @(#) $Id: text.test,v 1.11 2000/07/21 23:44:12 ericm Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { source [file join [pwd] [file dirname [info script]] defs.tcl] @@ -1110,7 +1110,36 @@ test text-20.65 {TextSearchCmd, unicode with non-text segments} { set result } {1.3 3} +test text-20.66 {TextSearchCmd, hidden text does not affect match index} { + eval destroy [winfo child .] + pack [text .t2] + .t2 insert end "12345H7890" + .t2 search 7 1.0 +} 1.6 +test text-20.67 {TextSearchCmd, hidden text does not affect match index} { + eval destroy [winfo child .] + pack [text .t2] + .t2 insert end "12345H7890" + .t2 tag configure hidden -elide true + .t2 tag add hidden 1.5 + .t2 search 7 1.0 +} 1.6 +test text-20.68 {TextSearchCmd, hidden text does not affect match index} { + eval destroy [winfo child .] + pack [text .t2] + .t2 insert end "foobar\nbarbaz\nbazboo" + .t2 search boo 1.0 +} 3.3 +test text-20.69 {TextSearchCmd, hidden text does not affect match index} { + eval destroy [winfo child .] + pack [text .t2] + .t2 insert end "foobar\nbarbaz\nbazboo" + .t2 tag configure hidden -elide true + .t2 tag add hidden 2.0 3.0 + .t2 search boo 1.0 +} 3.3 + eval destroy [winfo child .] text .t2 -highlightthickness 0 -bd 0 -relief flat -padx 0 -width 100 pack .t2 -- cgit v0.12