Skip to content

Conversation

@masmu
Copy link
Contributor

@masmu masmu commented Aug 6, 2025

vResizeSplit and hResizeSplit cannot change the size of the last split in a group of siblings. It resizes the split before the last split instead.

How to reproduce:

PLUGIN_VERSION = "2.0.0"
PLUGIN_NAME = "bug_last_split_cannot_be_resized"

local micro = import("micro")
local buffer = import("micro/buffer")

function resizePane(bp, id, size)
    local tab = bp:Tab()
    local paneIndex = tab:GetPane(id)
    local pane = tab.Panes[paneIndex + 1]
    pane:ResizePane(size)
    tab:SetActive(paneIndex)
end

function createSplits(bp, num)
    local tab = bp:Tab()
    local currentBp = bp
    while true do
        currentBp.Buf:Insert(
            buffer.Loc(1, 1), string.format("pane%s", currentBp:ID()))
        if #tab.Panes >= num then break end
        local newBuf, err = buffer.NewBufferFromFile("")
        currentBp = currentBp:VSplitIndex(newBuf, true)
    end
    tab:SetActive(bp:ID() - 1)
end

function postinit()
    local bp = micro.CurPane()
    if bp.Buf:Size() > 0 then
        return
    end

    createSplits(bp, 3)

    -- resizePane(bp, 1, 30)  -- this works
    -- resizePane(bp, 2, 30)  -- this works

    -- this does not work and sets the size of pane 2 instead
    resizePane(bp, 3, 30)
end

At first, I just fixed the bug, but then I found the entire design of vResizeSplit and hResizeSplit a bit strange.
So I thought it would be a good idea to change vResizeSplit and hResizeSplit so that they work the same way as VSplit and HSplit. This way, you can easily select the direction in which you want to resize. With the old design, you have to use a lot of extra logic in Lua to enable resizing to the left or top.

Fixes #3046

masmu added 2 commits August 6, 2025 20:51
…split in a group of siblings.

The general strategy for changing the size of a split is to set the size of the selected split and adjust the size of the split to its right according to the remaining space.
This calculation works for all cases except the last split. Instead of directly setting the size of the selected (last) split, the existing strategy is to calculate the necessary size of the split to its left based on the available space and thus indirectly adjust the size of the selected split.
However, the necessary adjustment of the new size is missing.
The entire design of the function is somewhat peculiar. Resizing to the right/bottom works well. However you cannot choose the direction in which you wish to resize, and therefore must deal with additional logic to achieve resizing to the left/top.
@masmu
Copy link
Contributor Author

masmu commented Aug 7, 2025

I forgot to mention this fixes issues/3046.

@Neko-Box-Coder
Copy link
Contributor

Neko-Box-Coder commented Aug 9, 2025

Yeah got the same issure when resizing and worked around it by just resizing the previous one 😂

https://github.com/Neko-Box-Coder/MicroOmni/blob/db958a6ba831b962b3619e5d3a8e961d92f5280f/MicroOmni.lua#L108-L113

    -- NOTE: Dumb hack where ResizePane() actually resizes the previous node if the current node 
    --       is at the end
    if isEnd then
        n = n * -1
        node = prevNode
    end

It's good to fix this but the change of function signature will break any plugins that use it, is there a way around it? At least for bufpane?

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.

ResizePane() resizes first/the most left pane

2 participants