aboutsummaryrefslogtreecommitdiffhomepage
path: root/core/ext/pm.lua
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+667e-11@users.noreply.github.com>2009-02-15 01:07:49 -0500
committerGravatar mitchell <70453897+667e-11@users.noreply.github.com>2009-02-15 01:07:49 -0500
commit86ef9ed4b1b74970c85c0fd319ba0dc8eb0b2b8d (patch)
treebd1de960b8b2a93d61004e3a8dbdf6b0854ee52d /core/ext/pm.lua
parent66c019be32ef2f66f73821f93083760018caa2a2 (diff)
PM browser cursors are saved and restored when switching between browsers.
Diffstat (limited to 'core/ext/pm.lua')
-rw-r--r--core/ext/pm.lua20
1 files changed, 20 insertions, 0 deletions
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)