fix(core): drop a taken column's windows from the switcher's recent use
- commit
- 7e3cc95388061833f1c2eea9d44d8d7ce7465010
- author
- brice · · 2026-10-08 20:27 UTC
- parent
- 6282944
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email - refs
- fix/v0.7.0-review
3 files · +15 -1
M internal/core/layout.go +2 -0
| @@ -1046,6 +1046,8 @@ func (w *Workspace) takeColumn() (Column, bool) { | |||
| 1046 | 1046 | if slices.Contains(col.Windows, w.left) { | |
| 1047 | 1047 | w.left = 0 | |
| 1048 | 1048 | } | |
| 1049 | + | // Its windows leave this workspace's recent use with it. | |
| 1050 | + | w.recent = slices.DeleteFunc(w.recent, func(v WindowID) bool { return slices.Contains(col.Windows, v) }) | |
| 1049 | 1051 | w.Columns = slices.Delete(w.Columns, w.Focus, w.Focus+1) | |
| 1050 | 1052 | w.Focus = min(w.Focus, max(len(w.Columns)-1, 0)) | |
| 1051 | 1053 | if len(w.Columns) == 0 { | |
| @@ -1046,6 +1046,8 @@ func (w *Workspace) takeColumn() (Column, bool) { | |||||
| 1046 | if slices.Contains(col.Windows, w.left) { | 1046 | if slices.Contains(col.Windows, w.left) { | ||
| 1047 | w.left = 0 | 1047 | w.left = 0 | ||
| 1048 | } | 1048 | } | ||
| 1049 | + | // Its windows leave this workspace's recent use with it. | |||
| 1050 | + | w.recent = slices.DeleteFunc(w.recent, func(v WindowID) bool { return slices.Contains(col.Windows, v) }) | |||
| 1049 | w.Columns = slices.Delete(w.Columns, w.Focus, w.Focus+1) | 1051 | w.Columns = slices.Delete(w.Columns, w.Focus, w.Focus+1) | ||
| 1050 | w.Focus = min(w.Focus, max(len(w.Columns)-1, 0)) | 1052 | w.Focus = min(w.Focus, max(len(w.Columns)-1, 0)) | ||
| 1051 | if len(w.Columns) == 0 { | 1053 | if len(w.Columns) == 0 { | ||
M internal/core/switcher.go +1 -1
| @@ -51,7 +51,7 @@ func (w *Workspace) noteFocus() { | |||
| 51 | 51 | } | |
| 52 | 52 | col := w.Columns[w.Focus] | |
| 53 | 53 | id := col.Windows[col.Focus] | |
| 54 | - | if len(w.recent) > 0 && w.columnOf(w.recent[0]) == w.Focus { | |
| 54 | + | if len(w.recent) > 0 && slices.Contains(col.Windows, w.recent[0]) { | |
| 55 | 55 | w.recent[0] = id | |
| 56 | 56 | return | |
| 57 | 57 | } | |
| @@ -51,7 +51,7 @@ func (w *Workspace) noteFocus() { | |||||
| 51 | } | 51 | } | ||
| 52 | col := w.Columns[w.Focus] | 52 | col := w.Columns[w.Focus] | ||
| 53 | id := col.Windows[col.Focus] | 53 | id := col.Windows[col.Focus] | ||
| 54 | - | if len(w.recent) > 0 && w.columnOf(w.recent[0]) == w.Focus { | 54 | + | if len(w.recent) > 0 && slices.Contains(col.Windows, w.recent[0]) { |
| 55 | w.recent[0] = id | 55 | w.recent[0] = id | ||
| 56 | return | 56 | return | ||
| 57 | } | 57 | } | ||
M internal/core/switcher_test.go +12 -0
| @@ -60,6 +60,18 @@ func TestMRUOrder(t *testing.T) { | |||
| 60 | 60 | w.MoveColumn(1) | |
| 61 | 61 | w.noteFocus() | |
| 62 | 62 | }, []WindowID{2, 3, 1}}, | |
| 63 | + | {"a column taken to another workspace leaves recent", func(w *Workspace) { | |
| 64 | + | focusNote(w, 1) | |
| 65 | + | focusNote(w, 3) | |
| 66 | + | focusNote(w, 2) | |
| 67 | + | if _, ok := w.takeColumn(); !ok { | |
| 68 | + | t.Fatal("no column taken") | |
| 69 | + | } | |
| 70 | + | if slices.Contains(w.recent, 2) { | |
| 71 | + | t.Fatalf("recent %v keeps the taken window", w.recent) | |
| 72 | + | } | |
| 73 | + | w.noteFocus() | |
| 74 | + | }, []WindowID{3, 1}}, | |
| 63 | 75 | } | |
| 64 | 76 | for _, tt := range tests { | |
| 65 | 77 | t.Run(tt.name, func(t *testing.T) { | |
| @@ -60,6 +60,18 @@ func TestMRUOrder(t *testing.T) { | |||||
| 60 | w.MoveColumn(1) | 60 | w.MoveColumn(1) | ||
| 61 | w.noteFocus() | 61 | w.noteFocus() | ||
| 62 | }, []WindowID{2, 3, 1}}, | 62 | }, []WindowID{2, 3, 1}}, | ||
| 63 | + | {"a column taken to another workspace leaves recent", func(w *Workspace) { | |||
| 64 | + | focusNote(w, 1) | |||
| 65 | + | focusNote(w, 3) | |||
| 66 | + | focusNote(w, 2) | |||
| 67 | + | if _, ok := w.takeColumn(); !ok { | |||
| 68 | + | t.Fatal("no column taken") | |||
| 69 | + | } | |||
| 70 | + | if slices.Contains(w.recent, 2) { | |||
| 71 | + | t.Fatalf("recent %v keeps the taken window", w.recent) | |||
| 72 | + | } | |||
| 73 | + | w.noteFocus() | |||
| 74 | + | }, []WindowID{3, 1}}, | |||
| 63 | } | 75 | } | ||
| 64 | for _, tt := range tests { | 76 | for _, tt := range tests { | ||
| 65 | t.Run(tt.name, func(t *testing.T) { | 77 | t.Run(tt.name, func(t *testing.T) { | ||