summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e9144d5)
raw | patch | inline | side by side (parent: e9144d5)
author | Bert Wesarg <bert.wesarg@googlemail.com> | |
Fri, 14 Oct 2011 08:14:52 +0000 (10:14 +0200) | ||
committer | Pat Thoyts <patthoyts@users.sourceforge.net> | |
Tue, 18 Oct 2011 08:27:28 +0000 (09:27 +0100) |
Use the up/down keys to browse the history.
Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>
Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>
lib/search.tcl | patch | blob | history |
diff --git a/lib/search.tcl b/lib/search.tcl
index 9268ec325bb4dd639f7dcc7f0e68c7301b7786a8..15f99d8e5f1d968b23eb2b01d43af21188f8ffe8 100644 (file)
--- a/lib/search.tcl
+++ b/lib/search.tcl
field default_casesensitive
field searchdirn -forwards
+field history
+field history_index
+
field smarktop
field smarkbot
set default_casesensitive 1
}
+ set history [list]
+
${NS}::frame $w
${NS}::label $w.l -text [mc Find:]
entry $w.ent -textvariable ${__this}::searchstring -background lightgreen
trace add variable searchstring write [cb _incrsearch_cb]
bind $w.ent <Return> [cb find_next]
bind $w.ent <Shift-Return> [cb find_prev]
+ bind $w.ent <Key-Up> [cb _prev_search]
+ bind $w.ent <Key-Down> [cb _next_search]
bind $w <Destroy> [list delete_this $this]
return $this
method show {} {
if {![visible $this]} {
grid $w
+ $w.ent delete 0 end
set regexpsearch $default_regexpsearch
set casesensitive $default_casesensitive
+ set history_index [llength $history]
}
focus -force $w.ent
}
if {[visible $this]} {
focus $ctext
grid remove $w
+ _save_search $this
}
}
}
}
+method _save_search {} {
+ if {$searchstring eq {}} {
+ return
+ }
+ if {[llength $history] > 0} {
+ foreach {s_regexp s_case s_expr} [lindex $history end] break
+ } else {
+ set s_regexp $regexpsearch
+ set s_case $casesensitive
+ set s_expr ""
+ }
+ if {$searchstring eq $s_expr} {
+ # update modes
+ set history [lreplace $history end end \
+ [list $regexpsearch $casesensitive $searchstring]]
+ } else {
+ lappend history [list $regexpsearch $casesensitive $searchstring]
+ }
+ set history_index [llength $history]
+}
+
+method _prev_search {} {
+ if {$history_index > 0} {
+ incr history_index -1
+ foreach {s_regexp s_case s_expr} [lindex $history $history_index] break
+ $w.ent delete 0 end
+ $w.ent insert 0 $s_expr
+ set regexpsearch $s_regexp
+ set casesensitive $s_case
+ }
+}
+
+method _next_search {} {
+ if {$history_index < [llength $history]} {
+ incr history_index
+ }
+ if {$history_index < [llength $history]} {
+ foreach {s_regexp s_case s_expr} [lindex $history $history_index] break
+ } else {
+ set s_regexp $default_regexpsearch
+ set s_case $default_casesensitive
+ set s_expr ""
+ }
+ $w.ent delete 0 end
+ $w.ent insert 0 $s_expr
+ set regexpsearch $s_regexp
+ set casesensitive $s_case
+}
+
method find_prev {} {
find_next $this -backwards
}
set searchdirn $dir
$ctext mark unset anchor
if {$searchstring ne {}} {
+ _save_search $this
set start [_get_new_anchor $this]
if {$dir eq "-forwards"} {
set start "$start + 1c"