-
Notifications
You must be signed in to change notification settings - Fork 39
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
Buffer switch behaviour #33
Comments
Textadept switches to the "wrong" buffer first because after `buffer:close()`, the buffer immediately before it in `_BUFFERS` is shown/switched to. However, https://github.com/orbitalquark/textadept/blob/cfc696571b49fa0728b19a32671cc6f651181611/core/ui.lua#L442 tries to restore the last visible buffer on `buffer:close()`, so that is why you're seeing two separate save events. (The duplicate restore event I'm unsure of.)
Do you need `save_view_state()` to be called immediately on the new buffer to populate those fields? Other than the fields existing, nothing meaningful is saved, which is why I don't do it.
|
Say you have 2 files open:
You go to the first opened What happens is:
So if you change wrap mode oder margins in the new buffer (like i do in Textredux) the The problem seems to be that there is no "after_switch" event fired for the passing-by of the last buffer in |
Thanks for the concrete example. I'll take a look at this when I have some time.
|
Thanks! Maybe disconnecting events before the switch to the previous buffer could be a fix. -- Keeps track of, and switches back to the previous buffer after buffer close.
events.connect(
events.BUFFER_BEFORE_SWITCH, function() view._prev_buffer = buffer end)
events.connect(events.BUFFER_DELETED, function()
if _BUFFERS[view._prev_buffer] and buffer ~= view._prev_buffer then
events.disconnect(events.VIEW_BEFORE_SWITCH, save_view_state)
events.disconnect(events.BUFFER_BEFORE_SWITCH, save_buffer_state)
view:goto_buffer(view._prev_buffer)
events.connect(events.BUFFER_BEFORE_SWITCH, save_view_state)
events.connect(events.VIEW_BEFORE_SWITCH, save_view_state)
end
end) Seems to fix the example scenario above, will check further. Maybe not both need to be disconnected. [Edited to use correct event] |
The above would likely work with Thus, the following also seems to do the trick: -- Keeps track of, and switches back to the previous buffer after buffer close.
events.connect(
events.BUFFER_BEFORE_SWITCH, function() view._prev_buffer = buffer end)
events.connect(events.BUFFER_DELETED, function()
if _BUFFERS[view._prev_buffer] and buffer ~= view._prev_buffer then
restore_view_state()
view:goto_buffer(view._prev_buffer)
end
end) |
Thanks for debugging this one. Fixed via 0ef954c
|
Awesome, thank you! |
I'm trying to understand the buffer switch behaviour as the view state restoring is sometimes messed up when using Textredux. E.g. i have wrap_mode set to None in a Textredux buffer, but by word otherwise.
When closing a Textredux buffer the wrong wrap_mode is applied to a regular Text buffer.
With
in my init.lua and
in Textadept's
core/ui.lua
(just added a print statement) and a similar statement in thesave_view_store
function it seems, that when II suspect that this is the reason for the problem with the view state being applied to the wrong buffer.
Any ideas why it switches to the wrong buffer first? Should it save view state also after a buffer_new event?
The text was updated successfully, but these errors were encountered: