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

Make GUI tabs track Vim tabs in updates and animate correctly #1535

Merged
merged 1 commit into from
Jan 27, 2025

Conversation

ychin
Copy link
Member

@ychin ychin commented Jan 27, 2025

MMTabline was introduced in #1120, which replaced the ancient PSMTabBarControl for representing Vim tabs. It uses animation to handle tab layouts, but it only worked in some situations, due to the Vim IPC API only sending a tabline update with all the tab labels with no way to track individual tabs. Update the API so that Vim now sends individual unique IDs in the update message as well to allow the GUI to track tabs over time and animate them. Vim does not interally have a concept of unique tab IDs, but we can use the pointer to the structure as such because they are allocated as a linked list and will never change.

Extend MMTabline to have a new updateTabsByTags API to batch update all tabs in one go, which will diff the new tags with existing tabs and create/remove/move tabs as necessary. The scrolling logic has also been moved inside it and it now only scrolls to selected tab when it has changed or moved. When deleting tabs we won't scroll as usually the user doesn't expect it. Dragging tabs also now work correctly when it is removed during a drag, or another tab has been selected.

This does mean the add/close tab APIs are currently unused, as the only entrypoint for modifying tabs from MacVim is currently only via updateTabsByTags.

After this, different Vim operations will now animate correctly, including :tabmove, :bdelete (which could remove multiple tabs at once), :tabnew, :tabclose.

@ychin ychin added the UI Issues related to UI elements, tabs, scrollbars, window resizing, etc. label Jan 27, 2025
@ychin ychin added this to the Release 181 milestone Jan 27, 2025
@ychin
Copy link
Member Author

ychin commented Jan 27, 2025

Just to demonstrate what this PR will do and how the tabs will animate to the correct locations no matter what Vim commands we use:

tabnew and tabclose:

tabnew-tabclose.mov

bdelete to remove more than one tabs:

bdelete.mov

tabmove:

tabmove.mov

Existing functionality from MMTab where we defer resizing the tab while closing tabs using the UI. This still works after this change:

defer-resize.mov

Even dragging a tab while another tab is closed also works seamlessly:

drag-while-tabclose.mov

@ychin ychin requested a review from Copilot January 27, 2025 12:04

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

Files not reviewed (9)
  • src/MacVim/MMBackend.m: Language not supported
  • src/MacVim/MMTabline/MMTab.h: Language not supported
  • src/MacVim/MMTabline/MMTab.m: Language not supported
  • src/MacVim/MMTabline/MMTabline.h: Language not supported
  • src/MacVim/MMTabline/MMTabline.m: Language not supported
  • src/MacVim/MMVimView.h: Language not supported
  • src/MacVim/MMVimView.m: Language not supported
  • src/MacVim/MMWindowController.h: Language not supported
  • src/MacVim/MMWindowController.m: Language not supported
@ychin ychin force-pushed the mmtabs-fix-update-animation-scroll branch from f8bf3fd to b589c84 Compare January 27, 2025 12:05
MMTabline was introduced in macvim-dev#1120, which replaced the ancient
PSMTabBarControl for representing Vim tabs. It uses animation to handle
tab layouts, but it only worked in some situations, due to the Vim IPC
API only sending a tabline update with all the tab labels with no way to
track individual tabs. Update the API so that Vim now sends individual
unique IDs in the update message as well to allow the GUI to track tabs
over time and animate them. Vim does not interally have a concept of
unique tab IDs, but we can use the pointer to the structure as such
because they are allocated as a linked list and will never change.

Extend MMTabline to have a new `updateTabsByTags` API to batch update
all tabs in one go, which will diff the new tags with existing tabs and
create/remove/move tabs as necessary. The scrolling logic has also been
moved inside it and it now only scrolls to selected tab when it has
changed or moved. When deleting tabs we won't scroll as usually the user
doesn't expect it. Dragging tabs also now work correctly when it is
removed during a drag, or another tab has been selected.

This does mean the add/close tab APIs are currently unused, as the only
entrypoint for modifying tabs from MacVim is currently only via
`updateTabsByTags`.

After this, different Vim operations will now animate correctly,
including `:tabmove`, `:bdelete` (which could remove multiple tabs at
once), `:tabnew`, `:tabclose`.
@ychin ychin force-pushed the mmtabs-fix-update-animation-scroll branch from b589c84 to 7fbb445 Compare January 27, 2025 12:16
@ychin ychin merged commit dffce69 into macvim-dev:master Jan 27, 2025
4 checks passed
@ychin ychin deleted the mmtabs-fix-update-animation-scroll branch January 27, 2025 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
UI Issues related to UI elements, tabs, scrollbars, window resizing, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant