Skip to content

Commit 2e44db1

Browse files
committed
Implemented new actions FirstTab, LastTab, FirstSplit and LastSplit and changed the default behavior of NextTab, PreviousTab, NextSplit, PreviousSplit to not walk in circles anymore
1 parent e6d4e37 commit 2e44db1

File tree

6 files changed

+65
-44
lines changed

6 files changed

+65
-44
lines changed

internal/action/actions.go

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,27 +1793,38 @@ func (h *BufPane) AddTab() bool {
17931793

17941794
// PreviousTab switches to the previous tab in the tab list
17951795
func (h *BufPane) PreviousTab() bool {
1796-
tabsLen := len(Tabs.List)
1797-
if tabsLen == 1 {
1796+
if Tabs.Active() == 0 {
17981797
return false
17991798
}
1800-
1801-
a := Tabs.Active() + tabsLen
1802-
Tabs.SetActive((a - 1) % tabsLen)
1803-
1799+
Tabs.SetActive(Tabs.Active() - 1)
18041800
return true
18051801
}
18061802

18071803
// NextTab switches to the next tab in the tab list
18081804
func (h *BufPane) NextTab() bool {
1809-
tabsLen := len(Tabs.List)
1810-
if tabsLen == 1 {
1805+
if Tabs.Active() == len(Tabs.List)-1 {
18111806
return false
18121807
}
1808+
Tabs.SetActive(Tabs.Active() + 1)
1809+
return true
1810+
}
18131811

1814-
a := Tabs.Active()
1815-
Tabs.SetActive((a + 1) % tabsLen)
1812+
// FirstTab switches to the first tab in the tab list
1813+
func (h *BufPane) FirstTab() bool {
1814+
if Tabs.Active() == 0 {
1815+
return false
1816+
}
1817+
Tabs.SetActive(0)
1818+
return true
1819+
}
18161820

1821+
// LastTab switches to the last tab in the tab list
1822+
func (h *BufPane) LastTab() bool {
1823+
lastTabIndex := len(Tabs.List) - 1
1824+
if Tabs.Active() == lastTabIndex {
1825+
return false
1826+
}
1827+
Tabs.SetActive(lastTabIndex)
18171828
return true
18181829
}
18191830

@@ -1848,36 +1859,38 @@ func (h *BufPane) Unsplit() bool {
18481859

18491860
// NextSplit changes the view to the next split
18501861
func (h *BufPane) NextSplit() bool {
1851-
if len(h.tab.Panes) == 1 {
1862+
if h.tab.active == len(h.tab.Panes)-1 {
18521863
return false
18531864
}
1854-
1855-
a := h.tab.active
1856-
if a < len(h.tab.Panes)-1 {
1857-
a++
1858-
} else {
1859-
a = 0
1860-
}
1861-
1862-
h.tab.SetActive(a)
1863-
1865+
h.tab.SetActive(h.tab.active + 1)
18641866
return true
18651867
}
18661868

18671869
// PreviousSplit changes the view to the previous split
18681870
func (h *BufPane) PreviousSplit() bool {
1869-
if len(h.tab.Panes) == 1 {
1871+
if h.tab.active == 0 {
18701872
return false
18711873
}
1874+
h.tab.SetActive(h.tab.active - 1)
1875+
return true
1876+
}
18721877

1873-
a := h.tab.active
1874-
if a > 0 {
1875-
a--
1876-
} else {
1877-
a = len(h.tab.Panes) - 1
1878+
// FirstSplit changes the view to the first split
1879+
func (h *BufPane) FirstSplit() bool {
1880+
if h.tab.active == 0 {
1881+
return false
18781882
}
1879-
h.tab.SetActive(a)
1883+
h.tab.SetActive(0)
1884+
return true
1885+
}
18801886

1887+
// LastSplit changes the view to the last split
1888+
func (h *BufPane) LastSplit() bool {
1889+
lastPaneIdx := len(h.tab.Panes) - 1
1890+
if h.tab.active == lastPaneIdx {
1891+
return false
1892+
}
1893+
h.tab.SetActive(lastPaneIdx)
18811894
return true
18821895
}
18831896

internal/action/bufpane.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,8 +824,12 @@ var BufKeyActions = map[string]BufKeyAction{
824824
"AddTab": (*BufPane).AddTab,
825825
"PreviousTab": (*BufPane).PreviousTab,
826826
"NextTab": (*BufPane).NextTab,
827+
"FirstTab": (*BufPane).FirstTab,
828+
"LastTab": (*BufPane).LastTab,
827829
"NextSplit": (*BufPane).NextSplit,
828830
"PreviousSplit": (*BufPane).PreviousSplit,
831+
"FirstSplit": (*BufPane).FirstSplit,
832+
"LastSplit": (*BufPane).LastSplit,
829833
"Unsplit": (*BufPane).Unsplit,
830834
"VSplit": (*BufPane).VSplitAction,
831835
"HSplit": (*BufPane).HSplitAction,

internal/action/defaults.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package action
33
var termdefaults = map[string]string{
44
"<Ctrl-q><Ctrl-q>": "Exit",
55
"<Ctrl-e><Ctrl-e>": "CommandMode",
6-
"<Ctrl-w><Ctrl-w>": "NextSplit",
6+
"<Ctrl-w><Ctrl-w>": "NextSplit|FirstSplit",
77
}
88

99
// DefaultBindings returns a map containing micro's default keybindings

internal/action/defaults_darwin.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ var bufdefaults = map[string]string{
5252
"Ctrl-v": "Paste",
5353
"Ctrl-a": "SelectAll",
5454
"Ctrl-t": "AddTab",
55-
"Alt-,": "PreviousTab",
56-
"Alt-.": "NextTab",
55+
"Alt-,": "PreviousTab|LastTab",
56+
"Alt-.": "NextTab|FirstTab",
5757
"Home": "StartOfTextToggle",
5858
"End": "EndOfLine",
5959
"CtrlHome": "CursorStart",
6060
"CtrlEnd": "CursorEnd",
6161
"PageUp": "CursorPageUp",
6262
"PageDown": "CursorPageDown",
63-
"CtrlPageUp": "PreviousTab",
64-
"CtrlPageDown": "NextTab",
63+
"CtrlPageUp": "PreviousTab|LastTab",
64+
"CtrlPageDown": "NextTab|FirstTab",
6565
"ShiftPageUp": "SelectPageUp",
6666
"ShiftPageDown": "SelectPageDown",
6767
"Ctrl-g": "ToggleHelp",
@@ -72,7 +72,7 @@ var bufdefaults = map[string]string{
7272
"Ctrl-b": "ShellMode",
7373
"Ctrl-q": "Quit",
7474
"Ctrl-e": "CommandMode",
75-
"Ctrl-w": "NextSplit",
75+
"Ctrl-w": "NextSplit|FirstSplit",
7676
"Ctrl-u": "ToggleMacro",
7777
"Ctrl-j": "PlayMacro",
7878
"Insert": "ToggleOverwriteMode",

internal/action/defaults_other.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ var bufdefaults = map[string]string{
5555
"Ctrl-v": "Paste",
5656
"Ctrl-a": "SelectAll",
5757
"Ctrl-t": "AddTab",
58-
"Alt-,": "PreviousTab",
59-
"Alt-.": "NextTab",
58+
"Alt-,": "PreviousTab|LastTab",
59+
"Alt-.": "NextTab|FirstTab",
6060
"Home": "StartOfTextToggle",
6161
"End": "EndOfLine",
6262
"CtrlHome": "CursorStart",
6363
"CtrlEnd": "CursorEnd",
6464
"PageUp": "CursorPageUp",
6565
"PageDown": "CursorPageDown",
66-
"CtrlPageUp": "PreviousTab",
67-
"CtrlPageDown": "NextTab",
66+
"CtrlPageUp": "PreviousTab|LastTab",
67+
"CtrlPageDown": "NextTab|FirstTab",
6868
"ShiftPageUp": "SelectPageUp",
6969
"ShiftPageDown": "SelectPageDown",
7070
"Ctrl-g": "ToggleHelp",
@@ -75,7 +75,7 @@ var bufdefaults = map[string]string{
7575
"Ctrl-b": "ShellMode",
7676
"Ctrl-q": "Quit",
7777
"Ctrl-e": "CommandMode",
78-
"Ctrl-w": "NextSplit",
78+
"Ctrl-w": "NextSplit|FirstSplit",
7979
"Ctrl-u": "ToggleMacro",
8080
"Ctrl-j": "PlayMacro",
8181
"Insert": "ToggleOverwriteMode",

runtime/help/keybindings.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,15 @@ QuitAll
253253
AddTab
254254
PreviousTab
255255
NextTab
256+
FirstTab
257+
LastTab
256258
NextSplit
257259
Unsplit
258260
VSplit
259261
HSplit
260262
PreviousSplit
263+
FirstSplit
264+
LastSplit
261265
ToggleMacro
262266
PlayMacro
263267
Suspend (Unix only)
@@ -502,16 +506,16 @@ conventions for text editing defaults.
502506
"Ctrl-v": "Paste",
503507
"Ctrl-a": "SelectAll",
504508
"Ctrl-t": "AddTab",
505-
"Alt-,": "PreviousTab",
506-
"Alt-.": "NextTab",
509+
"Alt-,": "PreviousTab|LastTab",
510+
"Alt-.": "NextTab|FirstTab",
507511
"Home": "StartOfText",
508512
"End": "EndOfLine",
509513
"CtrlHome": "CursorStart",
510514
"CtrlEnd": "CursorEnd",
511515
"PageUp": "CursorPageUp",
512516
"PageDown": "CursorPageDown",
513-
"CtrlPageUp": "PreviousTab",
514-
"CtrlPageDown": "NextTab",
517+
"CtrlPageUp": "PreviousTab|LastTab",
518+
"CtrlPageDown": "NextTab|FirstTab",
515519
"ShiftPageUp": "SelectPageUp",
516520
"ShiftPageDown": "SelectPageDown",
517521
"Ctrl-g": "ToggleHelp",
@@ -522,7 +526,7 @@ conventions for text editing defaults.
522526
"Ctrl-b": "ShellMode",
523527
"Ctrl-q": "Quit",
524528
"Ctrl-e": "CommandMode",
525-
"Ctrl-w": "NextSplit",
529+
"Ctrl-w": "NextSplit|FirstSplit",
526530
"Ctrl-u": "ToggleMacro",
527531
"Ctrl-j": "PlayMacro",
528532
"Insert": "ToggleOverwriteMode",

0 commit comments

Comments
 (0)