aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Harrison <adamdharrison@gmail.com>2021-05-16 23:04:03 -0400
committerAdam Harrison <adamdharrison@gmail.com>2021-05-16 23:04:03 -0400
commit5397764fe38e0670c4ed829c38a009a4c43a8347 (patch)
tree8bf3f1a226281a9ec7db8bd352134ecb1d507550
parent65a9a4a1c45d48c09ad78dc5d249b6c401a2b294 (diff)
downloadlite-xl-plugins-5397764fe38e0670c4ed829c38a009a4c43a8347.tar.gz
lite-xl-plugins-5397764fe38e0670c4ed829c38a009a4c43a8347.zip
Added in the restoretabs plugin to restore recently closed tabs.
-rw-r--r--README.md1
-rw-r--r--plugins/restoretabs.lua55
2 files changed, 56 insertions, 0 deletions
diff --git a/README.md b/README.md
index 9701ed2..c164212 100644
--- a/README.md
+++ b/README.md
@@ -95,6 +95,7 @@ Plugin | Description
[`openselected`](plugins/openselected.lua?raw=1) | Opens the selected filename or url
~~[`projectmanager`](plugins/projectmanager.lua?raw=1)~~ | Integrated in lite-xl with improvements ~~Save projects and load/reload them quickly~~
[`rainbowparen`](plugins/rainbowparen.lua?raw=1) | Show nesting of parentheses with rainbow colours
+[`restoretabs`](plugins/restoretabs.lua?raw=1) | Keep a list of recently closed tabs, and restore the tab in order on cntrl+shift+t.
*[`scale`](plugins/scale.lua?raw=1)* | Provides support for dynamically adjusting the scale of the code font / UI (`ctrl+-`, `ctrl+=`)
[`scalestatus`](plugins/scalestatus.lua?raw=1) | Displays current scale (zoom) in status view (depends on scale plugin)
[`selectionhighlight`](plugins/selectionhighlight.lua?raw=1) | Highlights regions of code that match the current selection *([screenshot](https://user-images.githubusercontent.com/3920290/80710883-5f597c80-8ae7-11ea-97f0-76dfacc08439.png))*
diff --git a/plugins/restoretabs.lua b/plugins/restoretabs.lua
new file mode 100644
index 0000000..48bb6ea
--- /dev/null
+++ b/plugins/restoretabs.lua
@@ -0,0 +1,55 @@
+-- lite-xl 1.16
+-- Not perfect, because we can't actually figure out when something closes, but should be good enough, so long as we check the list of open views.
+-- Maybe find a better way to get at "Node"?
+local core = require "core"
+local RootView = require "core.rootview"
+local command = require "core.command"
+local keymap = require "core.keymap"
+
+local update = RootView.update
+local initialized_tab_system = false
+
+local tab_history = { }
+local history_size = 10
+
+RootView.update = function(self)
+ update(self)
+ if not initialized_tab_system then
+ local Node = getmetatable(self.root_node)
+ local old_close = Node.close_view
+
+ Node.close_view = function(self, root, view)
+ if view.doc and view.doc.abs_filename then
+ local closing_filename = view.doc.abs_filename
+ for i,filename in ipairs(tab_history) do
+ if filename == closing_filename then
+ table.remove(tab_history, i)
+ break
+ end
+ end
+ table.insert(tab_history, closing_filename)
+ if #tab_history > history_size then
+ tab_history.remove(tab_history, 1)
+ end
+ end
+ old_close(self, root, view)
+ end
+
+ initialized_tab_system = true
+ end
+end
+
+
+command.add("core.docview", {
+ ["restore-tabs:restore-tab"] = function()
+ if #tab_history > 0 then
+ local file = tab_history[#tab_history]
+ core.root_view:open_doc(core.open_doc(file))
+ table.remove(tab_history)
+ end
+ end
+})
+
+keymap.add {
+ ["ctrl+shift+t"] = "restore-tabs:restore-tab"
+}