threads / discuss / 28718

Re: git-gui: still smartcase (and pull into git.git)

Subject: Re: git-gui: still smartcase (and pull into git.git)

## tl;dr

3 messages between Oct 19, 2011 and Oct 21, 2011.

replies: 2people: 2as markdown or json

Bert Wesarg· Oct 19, 2011, 14:59 UTC · lore
[ Cc'ing git@vger, because its not that private anymore ;-) ]

On Wed, Oct 19, 2011 at 15:06, Pat Thoyts <patthoyts@users.sourceforge.net> wrote:

Show 11 quoted lines
>
> I've applied the last of your set of patches to the git-gui repository
> now. The search series with the regexp and smartcase search. I added
> themed entry fields using similar code to that I posted but also
> handling xp/vista and dealing with non-themed Tk.
>
> I had to add a trap to deal with partial regexp's. If you tried to
> enable regexp and then entered [Cc]opyrigth it would raise an error
> after opening the brace as its not a valid regexp. Handled by catching
> and returning {} which yields a pink background until the expression
> becomes valid again which I think works well.
Thanks for catching this.
Show 6 quoted lines
>
> As I don't like the smartcase mode I've added a commit to only enable it
> if gui.search.smartcase is enabled. It looks like this was your
> intention anyway but the mode was always enabled. What I don't like
> about it is that you can't uncheck the Case checkbutton if there is a
> capital letter in the search box.

I checked my inspiration for this, it's a patch to the NEdit editor for it's incremental searchbar, and you can't uncheck the Case checkbutton there too, if an capital letter is entered. Other smart-case implementation I know of, aren't incremental, for example less with it's -i option. So duno what should happen. It does definitive makes no sense to enter 'giT' and searching case-insensitive, in my opinion.

I also have incorporated Andrew's suggestion to reset the case flag when the user cleared the entry. Unfortunately, I can't send an updated patch currently, maybe tomorrow, here is just the commit, before fixing up the patch, which is now in your master.

 commit af9e02860629f9da20a9434bfec74c115916f4e2
Author: Bert Wesarg <bert.wesarg@googlemail.com>
Date:   Tue Oct 18 19:43:44 2011 +0200
    searchbar: reset case flag after the user cleared the text
diff --git a/lib/search.tcl b/lib/search.tcl
index 58e6852..3388eb9 100644 lib/search.tcl
--- a/lib/search.tcl
+++ b/lib/search.tcl
@@ -155,10 +155,10 @@ method _incrsearch {} {
 	if {[catch {$ctext index anchor}]} {
 		$ctext mark set anchor [_get_new_anchor $this]
 	}
-	if {[regexp {[[:upper:]]} $searchstring]} {
-		set casesensitive 1
-	}
 	if {$searchstring ne {}} {
+		if {[regexp {[[:upper:]]} $searchstring]} {
+			set casesensitive 1
+		}
 		set here [_do_search $this anchor mlen]
 		if {$here ne {}} {
 			$ctext see $here
@@ -169,6 +169,9 @@ method _incrsearch {} {
 		} else {
 			$w.ent configure -background lightpink
 		}
+	} else {
+		# reset case sensitivity, when the user cleared the entry field
+		set casesensitive $default_casesensitive
 	}
 }

This should probably be now guarded by the new smartcase flag.

On the other hand, maybe we should change the 'gui.search.smartcase'
into 'gui.search.case' with 3 values case/nocase/smart?

>
> All pushed to master now at repo.or.cz. We should see it all end up in
> 1.7.8 I reckon.

But I saw that Juno has already pulled your gitgui-0.15.0 tag, which
was at 843d6597 at that time, and now you moved the tag :(

Bert

>
> Thanks,
> --
> Pat Thoyts                            http://www.patthoyts.tk/
> PGP fingerprint 2C 6E 98 07 2C 59 C8 97  10 CE 11 E6 04 E0 B9 DD
>
Bert Wesarg· Oct 20, 2011, 19:27 UTC · re: Bert Wesarg · lore

[PATCH] git-gui: use a tristate to control the case mode in the searchbar

The config is now called gui.search.case and can have the three values: no/yes/smart. yes is the default.

It also resets the case detection in smart mode, when the entry field was cleared by the use.

Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
 lib/search.tcl |   24 +++++++++++++++++-------
 1 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/lib/search.tcl b/lib/search.tcl
index 04a316b..ef1e555 100644
--- a/lib/search.tcl
+++ b/lib/search.tcl
@@ -26,11 +26,20 @@ constructor new {i_w i_text args} {
 	set ctext  $i_text
 
 	set default_regexpsearch [is_config_true gui.search.regexp]
-	set smartcase [is_config_true gui.search.smartcase]
-	if {$smartcase} {
+	switch -- [get_config gui.search.case] {
+	no {
 		set default_casesensitive 0
-	} else {
+		set smartcase 0
+	}
+	smart {
+		set default_casesensitive 0
+		set smartcase 1
+	}
+	yes -
+	default {
 		set default_casesensitive 1
+		set smartcase 0
+	}
 	}
 
 	set history [list]
@@ -157,12 +166,10 @@ method _incrsearch {} {
 	if {[catch {$ctext index anchor}]} {
 		$ctext mark set anchor [_get_new_anchor $this]
 	}
-	if {$smartcase} {
-		if {[regexp {[[:upper:]]} $searchstring]} {
+	if {$searchstring ne {}} {
+		if {$smartcase && [regexp {[[:upper:]]} $searchstring]} {
 			set casesensitive 1
 		}
-	}
-	if {$searchstring ne {}} {
 		set here [_do_search $this anchor mlen]
 		if {$here ne {}} {
 			$ctext see $here
@@ -175,6 +182,9 @@ method _incrsearch {} {
 			#$w.ent configure -background lightpink
 			$w.ent state pressed
 		}
+	} elseif {$smartcase} {
+		# clearing the field resets the smart case detection
+		set casesensitive 0
 	}
 }
 
-- 
1.7.7.759.gfc8c6
Pat Thoyts· Oct 21, 2011, 21:41 UTC · re: Bert Wesarg · lore

Re: [PATCH] git-gui: use a tristate to control the case mode in the searchbar

Bert Wesarg <bert.wesarg@googlemail.com> writes:
Show 63 quoted lines
>The config is now called gui.search.case and can have the three values:
>no/yes/smart. yes is the default.
>
>It also resets the case detection in smart mode, when the entry field was
>cleared by the use.
>
>Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
>---
> lib/search.tcl |   24 +++++++++++++++++-------
> 1 files changed, 17 insertions(+), 7 deletions(-)
>
>diff --git a/lib/search.tcl b/lib/search.tcl
>index 04a316b..ef1e555 100644
>--- a/lib/search.tcl
>+++ b/lib/search.tcl
>@@ -26,11 +26,20 @@ constructor new {i_w i_text args} {
> 	set ctext  $i_text
> 
> 	set default_regexpsearch [is_config_true gui.search.regexp]
>-	set smartcase [is_config_true gui.search.smartcase]
>-	if {$smartcase} {
>+	switch -- [get_config gui.search.case] {
>+	no {
> 		set default_casesensitive 0
>-	} else {
>+		set smartcase 0
>+	}
>+	smart {
>+		set default_casesensitive 0
>+		set smartcase 1
>+	}
>+	yes -
>+	default {
> 		set default_casesensitive 1
>+		set smartcase 0
>+	}
> 	}
> 
> 	set history [list]
>@@ -157,12 +166,10 @@ method _incrsearch {} {
> 	if {[catch {$ctext index anchor}]} {
> 		$ctext mark set anchor [_get_new_anchor $this]
> 	}
>-	if {$smartcase} {
>-		if {[regexp {[[:upper:]]} $searchstring]} {
>+	if {$searchstring ne {}} {
>+		if {$smartcase && [regexp {[[:upper:]]} $searchstring]} {
> 			set casesensitive 1
> 		}
>-	}
>-	if {$searchstring ne {}} {
> 		set here [_do_search $this anchor mlen]
> 		if {$here ne {}} {
> 			$ctext see $here
>@@ -175,6 +182,9 @@ method _incrsearch {} {
> 			#$w.ent configure -background lightpink
> 			$w.ent state pressed
> 		}
>+	} elseif {$smartcase} {
>+		# clearing the field resets the smart case detection
>+		set casesensitive 0
> 	}
> }
Look good to me. Applied.
-- 
Pat Thoyts                            http://www.patthoyts.tk/
PGP fingerprint 2C 6E 98 07 2C 59 C8 97  10 CE 11 E6 04 E0 B9 DD

← back to recent threads