All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pratyush Yadav <me@yadavpratyush.com>
To: Bert Wesarg <bert.wesarg@googlemail.com>
Cc: Pratyush Yadav <me@yadavpratyush.com>, <git@vger.kernel.org>,
	Birger Skogeng Pedersen <birger.sp@gmail.com>
Subject: [PATCH] git-gui: use path name instead of list index to track last clicked file
Date: Tue,  3 Sep 2019 20:15:36 +0530	[thread overview]
Message-ID: <20190903144536.8935-1-me@yadavpratyush.com> (raw)
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


  reply	other threads:[~2019-09-03 14:45 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-20 13:32 git-gui, feature request: add hotkeys to focus different widgets Birger Skogeng Pedersen
2018-02-23 10:22 ` [PATCH] git-gui: Add hotkeys to change focus between ui widgets Birger Skogeng Pedersen
2018-02-23 16:42   ` Birger Skogeng Pedersen
2018-02-28 12:10 ` Birger Skogeng Pedersen
2018-03-05 16:55   ` Johannes Schindelin
2018-03-06 14:35     ` Birger Skogeng Pedersen
2018-03-06 19:28       ` Junio C Hamano
2019-08-31 12:23         ` [PATCH] git-gui: Add hotkeys to set widget focus Birger Skogeng Pedersen
2019-08-31 12:27           ` Birger Skogeng Pedersen
2019-09-01 11:32           ` Pratyush Yadav
2019-09-01 16:21             ` Junio C Hamano
2019-09-01 18:24             ` Birger Skogeng Pedersen
2019-09-01 19:01             ` Bert Wesarg
2019-09-01 19:36               ` [PATCH] " Birger Skogeng Pedersen
2019-09-02 18:19                 ` Pratyush Yadav
2019-09-02 18:35                   ` Birger Skogeng Pedersen
2019-09-02 18:53                     ` Pratyush Yadav
2019-09-02 19:05                       ` Birger Skogeng Pedersen
2019-09-02 19:42                 ` Bert Wesarg
2019-09-03 14:21                   ` Birger Skogeng Pedersen
2019-09-03 14:22                   ` Pratyush Yadav
2019-09-03 14:45                     ` Pratyush Yadav [this message]
2019-09-03 18:07                       ` [PATCH v4] " Birger Skogeng Pedersen
2019-09-03 18:13                         ` Birger Skogeng Pedersen
2019-09-03 19:30                           ` Birger Skogeng Pedersen
2019-09-03 21:49                         ` Pratyush Yadav
2019-09-04 14:30                           ` [PATCH v5] " Birger Skogeng Pedersen
2019-09-04 18:59                             ` Johannes Sixt
2019-09-04 19:20                               ` Birger Skogeng Pedersen
2019-09-04 21:39                                 ` Johannes Sixt
2019-09-04 22:31                                   ` Pratyush Yadav
2019-09-04 23:38                                     ` Junio C Hamano
2019-09-05 12:33                                       ` Pratyush Yadav
2019-09-04 19:55                               ` Bert Wesarg
2019-09-04 21:45                                 ` Johannes Sixt
2019-09-10 19:12                             ` Pratyush Yadav
2019-09-11  6:49                               ` Birger Skogeng Pedersen
2019-09-11 17:48                                 ` Pratyush Yadav
2019-09-11 18:11                                   ` Johannes Sixt
2019-09-03 16:06                     ` [PATCH] [PATCH] " Bert Wesarg
2019-09-01 22:27             ` Philip Oakley
2019-09-02 12:25               ` Pratyush Yadav
2019-09-02 17:23                 ` Philip Oakley
2019-09-03 22:18                   ` Pratyush Yadav
2019-09-01 18:58           ` Bert Wesarg
2019-09-01 19:25             ` Birger Skogeng Pedersen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190903144536.8935-1-me@yadavpratyush.com \
    --to=me@yadavpratyush.com \
    --cc=bert.wesarg@googlemail.com \
    --cc=birger.sp@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.