Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

call onSetActive consistently whenever a bufpane receives focus #3584

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/micro/micro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func startup(args []string) (tcell.SimulationScreen, error) {
return nil, errors.New("No buffers opened")
}

action.InitTabs(b)
action.InitGlobals()
action.InitTabs(b)

err = config.RunPluginFn("init")
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions internal/action/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1899,6 +1899,9 @@ func (h *BufPane) ForceQuit() bool {
h.Unsplit()
} else if len(Tabs.List) > 1 {
Tabs.RemoveTab(h.splitID)
if e := MainTab().CurPane(); e != nil { // e == nil for 'raw' tab
e.SetActive(true)
}
} else {
screen.Screen.Fini()
InfoBar.Close()
Expand Down
12 changes: 8 additions & 4 deletions internal/action/bufpane.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,6 @@ func (h *BufPane) VSplitIndex(buf *buffer.Buffer, right bool) *BufPane {
}
MainTab().AddPane(e, currentPaneIdx)
MainTab().Resize()
MainTab().SetActive(currentPaneIdx)
return e
}

Expand All @@ -680,18 +679,23 @@ func (h *BufPane) HSplitIndex(buf *buffer.Buffer, bottom bool) *BufPane {
}
MainTab().AddPane(e, currentPaneIdx)
MainTab().Resize()
MainTab().SetActive(currentPaneIdx)
return e
}

// VSplitBuf opens the given buffer in a new vertical split.
func (h *BufPane) VSplitBuf(buf *buffer.Buffer) *BufPane {
return h.VSplitIndex(buf, h.Buf.Settings["splitright"].(bool))
e := h.VSplitIndex(buf, h.Buf.Settings["splitright"].(bool))
MainTab().SetActive(MainTab().GetPane(e.ID()))
e.SetActive(true)
return e
}

// HSplitBuf opens the given buffer in a new horizontal split.
func (h *BufPane) HSplitBuf(buf *buffer.Buffer) *BufPane {
return h.HSplitIndex(buf, h.Buf.Settings["splitbottom"].(bool))
e := h.HSplitIndex(buf, h.Buf.Settings["splitbottom"].(bool))
MainTab().SetActive(MainTab().GetPane(e.ID()))
e.SetActive(true)
return e
}

// Close this pane.
Expand Down
22 changes: 6 additions & 16 deletions internal/action/tab.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package action

import (
luar "layeh.com/gopher-luar"

"github.com/zyedidia/micro/v2/internal/buffer"
"github.com/zyedidia/micro/v2/internal/config"
"github.com/zyedidia/micro/v2/internal/display"
ulua "github.com/zyedidia/micro/v2/internal/lua"
"github.com/zyedidia/micro/v2/internal/screen"
"github.com/zyedidia/micro/v2/internal/views"
"github.com/zyedidia/tcell/v2"
Expand Down Expand Up @@ -153,17 +150,9 @@ func (t *TabList) SetActive(a int) {
t.TabWindow.SetActive(a)

for i, p := range t.List {
if i == a {
if !p.isActive {
p.isActive = true

err := config.RunPluginFn("onSetActive", luar.New(ulua.L, p.CurPane()))
if err != nil {
screen.TermMessage(err)
}
}
} else {
p.isActive = false
p.isActive = i == a
if h := p.CurPane(); h != nil { // h == nil for 'raw' tab
h.SetActive(i == a)
}
}
}
Expand Down Expand Up @@ -210,12 +199,13 @@ func InitTabs(bufs []*buffer.Buffer) {
Tabs = NewTabList(bufs[:1])
for _, b := range bufs[1:] {
if multiopen == "vsplit" {
MainTab().CurPane().VSplitBuf(b)
MainTab().CurPane().VSplitIndex(b, true)
} else { // default hsplit
MainTab().CurPane().HSplitBuf(b)
MainTab().CurPane().HSplitIndex(b, true)
}
}
}
MainTab().CurPane().SetActive(true)

screen.RestartCallback = Tabs.ResetMouse
}
Expand Down
1 change: 0 additions & 1 deletion internal/display/bufwindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func NewBufWindow(x, y, width, height int, buf *buffer.Buffer) *BufWindow {
w.View = new(View)
w.X, w.Y, w.Width, w.Height = x, y, width, height
w.SetBuffer(buf)
w.active = true

w.sline = NewStatusLine(w)

Expand Down
4 changes: 1 addition & 3 deletions runtime/help/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,13 @@ that micro defines:

* `deinit()`: cleanup function called when your plugin is unloaded or reloaded.

* `onSetActive(bufpane)`: runs when changing the currently active panel.

* `onBufferOpen(buf)`: runs when a buffer is opened. The input contains
the buffer object.

* `onBufPaneOpen(bufpane)`: runs when a bufpane is opened. The input
contains the bufpane object.

* `onSetActive(bufpane)`: runs when changing the currently active bufpane.
* `onSetActive(bufpane)`: runs when a bufpane becomes active.

* `onAction(bufpane)`: runs when `Action` is triggered by the user, where
`Action` is a bindable action (see `> help keybindings`). A bufpane
Expand Down
Loading