zyedidia / micro

A modern and intuitive terminal-based text editor
https://micro-editor.github.io
MIT License
24.47k stars 1.16k forks source link

`SetActive` doesn't properly work (at least in plugins) #3093

Closed dustdfg closed 7 months ago

dustdfg commented 7 months ago

Description of the problem or steps to reproduce

I have a plugin that opens sidebar and saves back_link for another pane where user was when opened the bar... At some moment I need to return user to previous pane (just make back_link active and sidebar not active). The following code looks like it should work but it doesn't work

    SideBar.back_link:SetActive(true)
    SideBar.buffer_pane:SetActive(false)

I see that cursor in back_link appears but I still control cursor in sidebar :\

Attempts to do:

    local id = SideBar.back_link:ID()
    action.MainTab():SetActive(id)

return error: Plugin mdtree: runtime error: invalid memory address or nil pointer dereference stack traceback:

Specifications

Commit hash: https://github.com/zyedidia/micro/commit/68d88b571de6dca9fb8f03e2a3caafa2287c38d4 OS: Debian12 Terminal: foot

niten94 commented 7 months ago

I tried looking at the code and I think action.Tab.SetActive is used when setting which pane is active but the index of the pane in the tab (not ID) is passed. The index of a pane is returned when calling Tab.GetPane and passing the ID.

action.MainTab is micro.CurTab in plugins, so I think the previous pane can be set as active in the plugin like this:

local micro = import("micro")
local tab = micro.CurTab()
tab:SetActive(tab:GetPane(SideBar.back_link:ID()))
dustdfg commented 7 months ago

Yeah it works. Thanks! I also looked at code and saw that tab is usually used to set some pane bur overlooked GetPane. Anyway the tab api is main facade for manipulating which pane is active but it isn't so obvious because each buffer also has function for setting active