aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/events.lua4
-rw-r--r--core/ext/pm.lua20
-rw-r--r--src/lua_interface.c5
3 files changed, 28 insertions, 1 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)
diff --git a/src/lua_interface.c b/src/lua_interface.c
index 7a98451b..97b59c14 100644
--- a/src/lua_interface.c
+++ b/src/lua_interface.c
@@ -810,8 +810,9 @@ void l_pm_view_fill(GtkTreeIter *initial_iter) {
lua_pushboolean(lua, initial_iter != NULL);
l_call_function(2, 1, true);
if (!lua_istable(lua, -1)) {
+ if (!lua_isnil(lua, -1)) warn("pm.get_contents_for: return not a table.");
lua_pop(lua, 1); // non-table return
- return warn("pm.get_contents_for: return not a table.");
+ return;
}
GtkTreeIter iter, child;
@@ -841,6 +842,8 @@ void l_pm_view_fill(GtkTreeIter *initial_iter) {
lua_pop(lua, 1); // value
}
lua_pop(lua, 1); // returned table
+
+ l_handle_event("pm_view_filled");
}
/**