AckslD / muren.nvim

Multiple replacements in neovim
361 stars 4 forks source link

feat(ui): Position UI windows by anchor and offsets #25

Closed al-ce closed 1 year ago

al-ce commented 1 year ago

Adds four new options to customize the position of the UI popup window(s):

The anchor and the offset values adjust the row and column position for each window (preview, patterns, replacements, options).

If the window would be out of bounds due to a combination of the anchor or offset opts and the overall size of the windows, the adjusted row/col positions of the UI are set to a max limit, placing them at their opposite anchor point.

al-ce commented 1 year ago

Thanks for the opportunity to collaborate! I leaned towards making the options and the function a bit blunt with their naming and structure but I'm happy to do any refactors you'd like to see. Please push any changes you see fit to make.

AckslD commented 1 year ago

@al-ce seems really cool! I'm a bit swamped with things atm so sorry for not getting to this yet but just wanted to let you know it's still on my todo :)

al-ce commented 1 year ago

@al-ce seems really cool! I'm a bit swamped with things atm so sorry for not getting to this yet but just wanted to let you know it's still on my todo :)

No worries, take your time! Hope all is well

AckslD commented 1 year ago

Could also be done in a follow up PR but do you think it would be useful to pass eg the anchor specification as an argument to the command? Such that you can open it where you want without changing the config?

al-ce commented 1 year ago

Could also be done in a follow up PR but do you think it would be useful to pass eg the anchor specification as an argument to the command? Such that you can open it where you want without changing the config?

I tackled this in a different branch. https://github.com/al-ce/muren.nvim/commit/8e5cc6dbe250eec159168d5cbc447d08e133c76b

https://github.com/al-ce/muren.nvim/assets/23170004/66d40c36-3265-44f0-88e4-4712fc00e957

EDIT: The video above doesn't show it but the subcommands respect the preset offset options (which were set to 0 for this demo). Could increase nargs to accept offsets here too (I think?)

https://github.com/al-ce/muren.nvim/assets/23170004/b5ea8dec-1ea0-4eca-863f-03ac0bc49966

It touches code in more modules than this PR currently does and makes some stronger design choices so I wanted to check with you before pushing it here. Moreover, if we decide to abandon this PR for a nui.nvim redesign (or even if we go ahead with this but eventually replace it), you probably don't want to deal with reworking those changes in that other branch. Just posting it here as a reference!

If you prefer the style of 4792b69 over the refactors in c669a6f, they can be reverted.

Thanks again for the opportunity, this is a fun weekend exercise! No worries if we don't merge this given the discussion around nui, which we can continue in the open issue. I just didn't want to leave the comments you left unaddressed. Hope all is well!

AckslD commented 1 year ago

Hi @al-ce, I think both this PR and the changes for the commands look good. We can either merge this and then the updates to the commands or you first merge the updates to the commands here. Up to you what you find easier.

al-ce commented 1 year ago

Thanks! We should probably go ahead and merge it here since there would be a breaking change from this PR's latest commit to the ones from the other branch. In both the Lua function args and the command args, the anchor is set with some combination of top/bottom + left/right. So I changed the user-end opts to reflect that, condensing vertical_anchor and horizontal_anchor, to anchor, which can be one of:

'top', 'bottom', 'left', 'right', 'top_left', 'top_right', 'bottom_left', 'bottom_right'

If the value isn't one of these, the anchor value is set to center, we notify the user without raising errors, and open muren as it would by default (rather than raising an error and preventing muren from functioning normally, since ui position is a secondary concern). The video below shows my setup.

I also added second and third position args for the :Muren commands. For example, :MurenOpen, :MurenOpen top, :MurenOpen top 15, :MurenOpen top 15 5 are all valid. The last two are vertical offset and horizontal offset, which will override the default or the user's offset opts. Otherwise those opts are respected.

https://github.com/al-ce/muren.nvim/assets/23170004/029db738-1a49-4ba6-a683-efd3f9585f56

Thanks again for taking a look at this!

al-ce commented 1 year ago

Pushed one commit to address the visual selection issue and another to clean up some of the mess I made in prior commits 😅

AckslD commented 1 year ago

Thanks for all the work @al-ce, high quality of code and great communication! :)

al-ce commented 1 year ago

Thanks for the opportunity and the guidance! Enjoyed it