Code Monkey home page Code Monkey logo

Comments (7)

orbitalquark avatar orbitalquark commented on May 27, 2024

from textadept.

rgieseke avatar rgieseke commented on May 27, 2024

Say you have 2 files open:

  • init.lua
  • session

You go to the first opened init.lua, then you open a new buffer and close the new buffer:

What happens is:

Saving view state	session
Switch to init.lua
Restoring	init.lua
Switch to init.lua
Restoring	init.lua

So if you change wrap mode oder margins in the new buffer (like i do in Textredux) the session file passed by while closing inherits the view state from the new buffer.

The problem seems to be that there is no "after_switch" event fired for the passing-by of the last buffer in _BUFFERS.

from textadept.

orbitalquark avatar orbitalquark commented on May 27, 2024

from textadept.

rgieseke avatar rgieseke commented on May 27, 2024

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]

from textadept.

rgieseke avatar rgieseke commented on May 27, 2024

The above would likely work with save_view_state only.

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)

from textadept.

orbitalquark avatar orbitalquark commented on May 27, 2024

from textadept.

rgieseke avatar rgieseke commented on May 27, 2024

Awesome, thank you!
Next time i'll try to submit a reproducible test case, this is nice :-)

from textadept.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.