Commits

Anonymous committed 3849bfb

git-gui: Disable native platform text selection in "lists"

Sometimes we use a Tk text widget as though it were a listbox.
This happens typically when we want to show an icon to the left
of the text label or just when a text widget is generally a better
choice then the native listbox widget.

In these cases if we want the user to have control over the selection
we implement our own "in_sel" tag that shows the selected region
and we perform our own selection management in the background
via keybindings and mouse bindings. In such uses we don't want
the user to be able to activate the native platform selection by
dragging their mouse through the text widget. Doing so creates a
very confusing display and the user is left wondering what it may
mean to have two different types of selection in the same widget.

Tk doesn't allow us to delete the "sel" tag that it uses internally
to manage the native selection but it will allow us to make it
invisible by setting the tag to have the same display properties
as unselected text. So long as we don't actually use the "sel"
tag for anything in code its effectively invisible.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Comments (0)

Files changed (3)

 	return $m
 }
 
+proc rmsel_tag {text} {
+	$text tag conf sel \
+		-background [$text cget -background] \
+		-foreground [$text cget -foreground] \
+		-borderwidth 0
+	$text tag conf in_sel -background lightgray
+	bind $text <Motion> break
+	return $text
+}
+
 ######################################################################
 ##
 ## find git
 .vpane.files add .vpane.files.workdir -sticky nsew
 
 foreach i [list $ui_index $ui_workdir] {
-	$i tag conf in_diff -background lightgray
-	$i tag conf in_sel  -background lightgray
+	rmsel_tag $i
+	$i tag conf in_diff -background [$i tag cget in_sel -background]
 }
 unset i
 
 		-width 70 \
 		-xscrollcommand [list $w.list.sbx set] \
 		-yscrollcommand [list $w.list.sby set]
-	$w_list tag conf in_sel \
-		-background [$w_list cget -foreground] \
-		-foreground [$w_list cget -background]
+	rmsel_tag $w_list
 	scrollbar $w.list.sbx -orient h -command [list $w_list xview]
 	scrollbar $w.list.sby -orient v -command [list $w_list yview]
 	pack $w.list.sbx -side bottom -fill x

lib/choose_font.tcl

 		-width 30 \
 		-height 10 \
 		-yscrollcommand [list $w.inner.family.sby set]
+	rmsel_tag $w_family
 	scrollbar $w.inner.family.sby -command [list $w_family yview]
 	pack $w.inner.family.l -side top -fill x
 	pack $w.inner.family.sby -side right -fill y
 		-relief sunken \
 		-height 3 \
 		-width 40
+	rmsel_tag $w_example
 	$w_example tag conf example -justify center
 	$w_example insert end [mc "This is example text.\nIf you like this text, it can be your font."] example
 	$w_example conf -state disabled
 
 	$w_family tag conf pick
 	$w_family tag bind pick <Button-1> [cb _pick_family %x %y]\;break
-	$w_family tag conf cpck -background lightgray
 	foreach f $all_families {
 		set sel [list pick]
 		if {$f eq $f_family} {
-			lappend sel cpck
+			lappend sel in_sel
 		}
 		$w_family insert end "$f\n" $sel
 	}
 	set i [lindex [split [$w_family index @$x,$y] .] 0]
 	set n [lindex $all_families [expr {$i - 1}]]
 	if {$n ne {}} {
-		$w_family tag remove cpck 0.0 end
-		$w_family tag add cpck $i.0 [expr {$i + 1}].0
+		$w_family tag remove in_sel 0.0 end
+		$w_family tag add in_sel $i.0 [expr {$i + 1}].0
 		set f_family $n
 		_update $this
 	}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.