Fossil SCM

Add the ability to search by NoCase, RegExp, or WholeWord.

drh 2016-07-29 21:40 trunk
Commit 2a5de7ea2e119a66b92cc6103325a8285eb4d09b
1 file changed +14 -4
+14 -4
--- src/diff.tcl
+++ src/diff.tcl
@@ -389,11 +389,15 @@
389389
pack .bb.sframe.e -side left -fill y -expand 1
390390
::ttk::button .bb.sframe.nx -text \u2193 -width 1 \
391391
-command {searchNext -forwards +1 1.0 end}
392392
::ttk::button .bb.sframe.pv -text \u2191 -width 1 \
393393
-command {searchNext -backwards -1 end 1.0}
394
- pack .bb.sframe.nx .bb.sframe.pv -side left
394
+ tk_optionMenu .bb.sframe.typ ::search_type \
395
+ Exact {No Case} {RegExp} {Whole Word}
396
+ .bb.sframe.typ config -width 10
397
+ set ::search_type Exact
398
+ pack .bb.sframe.nx .bb.sframe.pv .bb.sframe.typ -side left
395399
}
396400
pack .bb.sframe -side left
397401
}
398402
}
399403
proc searchNext {direction incr start stop} {
@@ -402,22 +406,28 @@
402406
set w $::search
403407
if {"$w"==".txtA"} {set other .txtB} {set other .txtA}
404408
if {[lsearch [$w mark names] search]<0} {
405409
$w mark set search $start
406410
}
407
- set idx [$w search -count count $direction -- \
411
+ switch $::search_type {
412
+ Exact {set st -exact}
413
+ {No Case} {set st -nocase}
414
+ {RegExp} {set st -regexp}
415
+ {Whole Word} {set st -regexp; set pattern \\y$pattern\\y}
416
+ }
417
+ set idx [$w search -count count $direction $st -- \
408418
$pattern "search $incr chars" $stop]
409419
if {"$idx"==""} {
410420
set this $w
411421
set w $other
412422
set other $this
413
- set idx [$w search -count count $direction -- $pattern $start $stop]
423
+ set idx [$w search -count count $direction $st -- $pattern $start $stop]
414424
if {"$idx"==""} {
415425
set this $w
416426
set w $other
417427
set other $this
418
- set idx [$w search -count count $direction -- $pattern $start $stop]
428
+ set idx [$w search -count count $direction $st -- $pattern $start $stop]
419429
}
420430
}
421431
$w tag remove search 1.0 end
422432
$w mark unset search
423433
$other tag remove search 1.0 end
424434
--- src/diff.tcl
+++ src/diff.tcl
@@ -389,11 +389,15 @@
389 pack .bb.sframe.e -side left -fill y -expand 1
390 ::ttk::button .bb.sframe.nx -text \u2193 -width 1 \
391 -command {searchNext -forwards +1 1.0 end}
392 ::ttk::button .bb.sframe.pv -text \u2191 -width 1 \
393 -command {searchNext -backwards -1 end 1.0}
394 pack .bb.sframe.nx .bb.sframe.pv -side left
 
 
 
 
395 }
396 pack .bb.sframe -side left
397 }
398 }
399 proc searchNext {direction incr start stop} {
@@ -402,22 +406,28 @@
402 set w $::search
403 if {"$w"==".txtA"} {set other .txtB} {set other .txtA}
404 if {[lsearch [$w mark names] search]<0} {
405 $w mark set search $start
406 }
407 set idx [$w search -count count $direction -- \
 
 
 
 
 
 
408 $pattern "search $incr chars" $stop]
409 if {"$idx"==""} {
410 set this $w
411 set w $other
412 set other $this
413 set idx [$w search -count count $direction -- $pattern $start $stop]
414 if {"$idx"==""} {
415 set this $w
416 set w $other
417 set other $this
418 set idx [$w search -count count $direction -- $pattern $start $stop]
419 }
420 }
421 $w tag remove search 1.0 end
422 $w mark unset search
423 $other tag remove search 1.0 end
424
--- src/diff.tcl
+++ src/diff.tcl
@@ -389,11 +389,15 @@
389 pack .bb.sframe.e -side left -fill y -expand 1
390 ::ttk::button .bb.sframe.nx -text \u2193 -width 1 \
391 -command {searchNext -forwards +1 1.0 end}
392 ::ttk::button .bb.sframe.pv -text \u2191 -width 1 \
393 -command {searchNext -backwards -1 end 1.0}
394 tk_optionMenu .bb.sframe.typ ::search_type \
395 Exact {No Case} {RegExp} {Whole Word}
396 .bb.sframe.typ config -width 10
397 set ::search_type Exact
398 pack .bb.sframe.nx .bb.sframe.pv .bb.sframe.typ -side left
399 }
400 pack .bb.sframe -side left
401 }
402 }
403 proc searchNext {direction incr start stop} {
@@ -402,22 +406,28 @@
406 set w $::search
407 if {"$w"==".txtA"} {set other .txtB} {set other .txtA}
408 if {[lsearch [$w mark names] search]<0} {
409 $w mark set search $start
410 }
411 switch $::search_type {
412 Exact {set st -exact}
413 {No Case} {set st -nocase}
414 {RegExp} {set st -regexp}
415 {Whole Word} {set st -regexp; set pattern \\y$pattern\\y}
416 }
417 set idx [$w search -count count $direction $st -- \
418 $pattern "search $incr chars" $stop]
419 if {"$idx"==""} {
420 set this $w
421 set w $other
422 set other $this
423 set idx [$w search -count count $direction $st -- $pattern $start $stop]
424 if {"$idx"==""} {
425 set this $w
426 set w $other
427 set other $this
428 set idx [$w search -count count $direction $st -- $pattern $start $stop]
429 }
430 }
431 $w tag remove search 1.0 end
432 $w mark unset search
433 $other tag remove search 1.0 end
434

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button