Closed jxzwp closed 2 months ago
Oh, good catch. Thanks for the detailed write up. I'm in the middle of refactoring Textadept's existing tests, so I'll add this case and fix it in due time.
This should be fixed by https://github.com/orbitalquark/textadept/commit/64f4559671490c4f85f9706ef19821ce28497241. I think the simpler fix is to just switch to a non-focused buffer before closing it.
Open Textadept. Open multiple files, at least three, so there are multiple tabs. Switch from the current tab to another one, remembering which tab was previously active. Click the X close button on a tab that isn't the active tab and isn't the previously active tab. The active tab/buffer is switched to another one, when it should remain active.
The problem is in the BUFFER_DELETED event handler at textadept/core/ui.lua:387 https://github.com/orbitalquark/textadept/blob/df12db04cbd28126e47ebe82b7c7e54b501eae48/core/ui.lua#L387
It implicitly assumes that the buffer that was just closed was the active buffer, and switches to the previously active buffer stored in
view._prev_buffer
. Since the tab close buttons were added this assumption isn't always true.A possible solution is below. In the TAB_CLOSE_CLICKED event handler at textadept/core/ui.lua:272, add a field called
inactive
to the buffer being closed if it isn't the currently active buffer.Then in the BUFFER_DELETED at textadept/core/ui.lua:387 check for the presence on the
inactive
field on the buffer being closed, if it's present exit early so the buffer isn't switched.Thanks for all the time you've spent creating Textadept.