Skip to content

Conversation

@cutelisp
Copy link
Contributor

Currently, in the tab bar, each tab is separated by a gap of 4 cells, usually.
When the gap is left-clicked, the tab on the right side of the gap is selected.
This PR makes the tab nearest to the click the selected one.

@cutelisp cutelisp mentioned this pull request Jul 1, 2025
x++
s := util.CharacterCountInString(n)
if vloc.Y == w.Y && vloc.X < x+s {
if vloc.Y == w.Y && vloc.X < x+s+2 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes a side effect: when clicking on the empty space after the last tab, it activates the last tab if the click is 1 or 2 (but not 3 or more) spaces after the last tab name.

Also a note unrelated to this PR: it seems pointless to check vloc.Y == w.Y at each iteration of the loop, we can just check it at the beginning.

So, how about such change:

diff --git a/internal/display/tabwindow.go b/internal/display/tabwindow.go
index 423b966b..96aead73 100644
--- a/internal/display/tabwindow.go
+++ b/internal/display/tabwindow.go
@@ -29,12 +29,19 @@ func (w *TabWindow) Resize(width, height int) {
 }
 
 func (w *TabWindow) LocFromVisual(vloc buffer.Loc) int {
+	if vloc.Y != w.Y {
+		return -1
+	}
+
 	x := -w.hscroll
 
 	for i, n := range w.Names {
 		x++
 		s := util.CharacterCountInString(n)
-		if vloc.Y == w.Y && vloc.X < x+s+2 {
+		if vloc.X < x+s {
+			return i
+		}
+		if i < len(w.Names)-1 && vloc.X < x+s+2 {
 			return i
 		}
 		x += s

Copy link
Collaborator

@JoeKar JoeKar Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes a side effect: when clicking on the empty space after the last tab, it activates the last tab if the click is 1 or 2 (but not 3 or more) spaces after the last tab name.

Here I'm quite undecided.
When we have 3 tabs (a, b & c) open then we can activate:

  • a+2
  • 2+b+2
  • 2+c

Clicking on the left side of a is limited by the boundary of the window, but the right side of c most probably isn't.
Now we have a active and click slightly of the right side after c then c it isn't activated.
We could activate c with the whole remaining space (by adding a check for i == len(w.Names)-1 at the end of the loop and return i too). What do you think?

While we are here already, then we should also fix the use case of wide runes in tab names (also note in #3516) by exchanging all util.CharacterCountInString() to runewidth.StringWidth() to proper address the x position and scroll width.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants