git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-gui: use path name instead of list index to track last clicked file

From
Pratyush Yadav <me@yadavpratyush.com>
Date
Sep 3, 2019, 14:45 UTC
Message-ID
<20190903144536.8935-1-me@yadavpratyush.com>
In-Reply-To
<20190903142252.oovvxslvvzteaqlc@yadavpratyush.com>
Birger,

You would probably want to squash this patch with yours when you send a re-roll. Of course, I'd like some comments and tests on the patch before considering it "done". Just letting you know that I'd like to have this change in your original patch/commit, not as a separate commit. I put it in a separate patch for now for easier readability.

Also, FYI, pass '--scissors' to git-am when applying this to not get the above text in the commit message.

-- >8 -- For using the hotkeys CTRL/CMD+1/2/3/4, we save the index of the last clicked file. This index may change if some external command changes the repo state. So use the path name of the file instead.

Signed-off-by: Pratyush Yadav <me@yadavpratyush.com>
---
 git-gui.sh | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/git-gui.sh b/git-gui.sh
index ce620f1..9be1b6a 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -2527,7 +2527,7 @@ proc toggle_or_diff {mode w args} {
 	$ui_index tag remove in_sel 0.0 end
 	$ui_workdir tag remove in_sel 0.0 end

-	set file_lists_last_clicked($w) $lno
+	set file_lists_last_clicked($w) $path

 	# Determine the state of the file
 	if {[info exists file_states($path)]} {
@@ -2648,17 +2648,15 @@ proc select_path_in {widget} {

 	set _list_length [llength $file_lists($widget)]
 	if {$_list_length > 0} {
-
-		set _index $file_lists_last_clicked($widget)
-		if {$_index eq {}} {
-			set _index 1
-		} elseif {$_index > $_list_length} {
-			set _index $_list_length
+		set path $file_lists_last_clicked($widget)
+		set index [lsearch -sorted -exact $file_lists($widget) $path]
+		if {$index < 0} {
+			set index 0
+			set path [lindex $file_lists($widget) $index]
 		}

 		focus $widget
-		set last_clicked [list $widget $_index]
-		set path [lindex $file_lists($widget) [expr $_index - 1]]
+		set last_clicked [list $widget [expr $index + 1]]
 		array unset selected_paths
 		set selected_paths($path) 1
 		show_diff $path $widget
--
2.21.0
Previous: Pratyush YadavNext: Birger Skogeng Pedersen
Message 22 of 46 in “git-gui, feature request: add hotkeys to focus different widgets”
  1. Birger Skogeng PedersenFeb 20, 2018
  2. git-gui: Add hotkeys to change focus between ui widgetsBirger Skogeng Pedersen, Feb 23, 2018
  3. Birger Skogeng PedersenFeb 23, 2018
  4. git-gui: Add hotkeys to change focus between ui widgetsBirger Skogeng Pedersen, Feb 28, 2018
  5. Johannes SchindelinMar 5, 2018
  6. Birger Skogeng PedersenMar 6, 2018
  7. Junio C HamanoMar 6, 2018
  8. git-gui: Add hotkeys to set widget focusBirger Skogeng Pedersen, Aug 31, 2019
  9. Birger Skogeng PedersenAug 31, 2019
  10. Pratyush YadavSep 1, 2019
  11. Junio C HamanoSep 1, 2019
  12. Birger Skogeng PedersenSep 1, 2019
  13. Bert WesargSep 1, 2019
  14. [PATCH] git-gui: Add hotkeys to set widget focusBirger Skogeng Pedersen, Sep 1, 2019
  15. Pratyush YadavSep 2, 2019
  16. Birger Skogeng PedersenSep 2, 2019
  17. Pratyush YadavSep 2, 2019
  18. Birger Skogeng PedersenSep 2, 2019
  19. Bert WesargSep 2, 2019
  20. Birger Skogeng PedersenSep 3, 2019
  21. Pratyush YadavSep 3, 2019
  22. git-gui: use path name instead of list index to track last clicked filePratyush Yadav, Sep 3, 2019
  23. git-gui: Add hotkeys to set widget focusBirger Skogeng Pedersen, Sep 3, 2019
  24. Birger Skogeng PedersenSep 3, 2019
  25. Birger Skogeng PedersenSep 3, 2019
  26. Pratyush YadavSep 3, 2019
  27. git-gui: Add hotkeys to set widget focusBirger Skogeng Pedersen, Sep 4, 2019
  28. Johannes SixtSep 4, 2019
  29. Birger Skogeng PedersenSep 4, 2019
  30. Johannes SixtSep 4, 2019
  31. Pratyush YadavSep 4, 2019
  32. Junio C HamanoSep 4, 2019
  33. Pratyush YadavSep 5, 2019
  34. Bert WesargSep 4, 2019
  35. Johannes SixtSep 4, 2019
  36. Pratyush YadavSep 10, 2019
  37. Birger Skogeng PedersenSep 11, 2019
  38. Pratyush YadavSep 11, 2019
  39. Johannes SixtSep 11, 2019
  40. Bert WesargSep 3, 2019
  41. Philip OakleySep 1, 2019
  42. Pratyush YadavSep 2, 2019
  43. Philip OakleySep 2, 2019
  44. Pratyush YadavSep 3, 2019
  45. Bert WesargSep 1, 2019
  46. Birger Skogeng PedersenSep 1, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.