diff options
author | 2009-02-15 01:07:49 -0500 | |
---|---|---|
committer | 2009-02-15 01:07:49 -0500 | |
commit | 86ef9ed4b1b74970c85c0fd319ba0dc8eb0b2b8d (patch) | |
tree | bd1de960b8b2a93d61004e3a8dbdf6b0854ee52d /core | |
parent | 66c019be32ef2f66f73821f93083760018caa2a2 (diff) | |
download | textadept-86ef9ed4b1b74970c85c0fd319ba0dc8eb0b2b8d.tar.gz textadept-86ef9ed4b1b74970c85c0fd319ba0dc8eb0b2b8d.zip |
PM browser cursors are saved and restored when switching between browsers.
Diffstat (limited to 'core')
-rw-r--r-- | core/events.lua | 4 | ||||
-rw-r--r-- | core/ext/pm.lua | 20 |
2 files changed, 24 insertions, 0 deletions
diff --git a/core/events.lua b/core/events.lua index a1e32dc8..f0d629cc 100644 --- a/core/events.lua +++ b/core/events.lua @@ -68,6 +68,7 @@ module('textadept.events', package.seeall) -- alt: flag indicating whether or not alt is pressed. -- menu_clicked(menu_id) -- menu_id: the numeric ID of the menu item. +-- pm_view_filled() local events = textadept.events @@ -141,6 +142,9 @@ end function menu_clicked(menu_id_str) return handle('menu_clicked', tonumber(menu_id_str)) end +function pm_view_filled() + return handle('pm_view_filled') +end -- Scintilla notifications. function char_added(n) diff --git a/core/ext/pm.lua b/core/ext/pm.lua index e70ae6e2..03741960 100644 --- a/core/ext/pm.lua +++ b/core/ext/pm.lua @@ -46,6 +46,10 @@ local pm = textadept.pm +-- For restoring browser cursors +local browser_cursors = {} +local last_browser = nil + --- -- Requests treeview contents from browser that matches pm_entry's text. -- This function is called internally and shouldn't be called by a script. @@ -67,6 +71,13 @@ local pm = textadept.pm function pm.get_contents_for(full_path, expanding) for _, browser in pairs(pm.browsers) do if browser.matches(full_path[1]) then + if last_browser and last_browser ~= pm.entry_text then + -- Switching browsers, save the current one's cursor. + -- Don't reset last_browser here though, we still need to detect the + -- switch when the 'pm_view_filled' event is called so as to restore + -- the cursor to the new browser. + browser_cursors[last_browser] = pm.cursor + end return browser.get_contents_for(full_path, expanding) end end @@ -130,3 +141,12 @@ function pm.toggle_visible() pm.width = pm.prev_width or 150 end end + +textadept.events.add_handler('pm_view_filled', + function() -- tries to restore the cursor for a previous browser + if last_browser ~= pm.entry_text then + last_browser = pm.entry_text + local previous_cursor = browser_cursors[pm.entry_text] + if previous_cursor then pm.cursor = previous_cursor end + end + end) |