diff options
author | Francesco <francesco.bbt@gmail.com> | 2021-06-03 21:45:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-03 21:45:17 +0200 |
commit | b50ab1eeb6e1e9356c92b8b283fef26124265d5d (patch) | |
tree | 1922c31a4f98fed88838ef57f3f8748887553cf0 /plugins | |
parent | ab2f674595c0f11ecfa189e0e0dace77d7de9aa3 (diff) | |
parent | 35fb3df3fc18de6082f2363b00d6c4331a620200 (diff) | |
download | lite-xl-plugins-b50ab1eeb6e1e9356c92b8b283fef26124265d5d.tar.gz lite-xl-plugins-b50ab1eeb6e1e9356c92b8b283fef26124265d5d.zip |
Merge pull request #24 from prantlf/autosaveonfocuslost
Add autosaveonfocuslost
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/autosaveonfocuslost.lua | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/plugins/autosaveonfocuslost.lua b/plugins/autosaveonfocuslost.lua new file mode 100644 index 0000000..bc193a8 --- /dev/null +++ b/plugins/autosaveonfocuslost.lua @@ -0,0 +1,31 @@ +-- mod-version:1 -- lite-xl 1.16 +local core = require "core" +local CommandView = require "core.commandview" +local DocView = require "core.docview" +local RootView = require "core.rootview" + +local on_focus_lost = RootView.on_focus_lost + +local function save_node(node) + if node.type == "leaf" then + local i = 1 + while i <= #node.views do + local view = node.views[i] + if view:is(DocView) and not view:is(CommandView) and + view.doc.filename and view.doc:is_dirty() then + core.log("Saving doc \"%s\"", view.doc.filename) + view.doc:save() + end + i = i + 1 + end + else + if node.a then save_node(node.a) end + if node.b then save_node(node.b) end + end +end + +function RootView:on_focus_lost(...) + save_node(core.root_view.root_node) + + return on_focus_lost(...) +end |