From 1a51dad23c01cce42834dc8bd665a71189114a58 Mon Sep 17 00:00:00 2001 From: jgmdev Date: Sun, 20 Jun 2021 00:13:07 -0400 Subject: [PATCH] Added Doc:on_close() for plugins --- data/core/doc/init.lua | 10 ++++++++-- data/core/init.lua | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/data/core/doc/init.lua b/data/core/doc/init.lua index 0c5ba8fb..c33ade5a 100644 --- a/data/core/doc/init.lua +++ b/data/core/doc/init.lua @@ -1,5 +1,6 @@ local Object = require "core.object" local Highlighter = require "core.doc.highlighter" +local core = require "core" local syntax = require "core.syntax" local config = require "core.config" local common = require "core.common" @@ -181,10 +182,10 @@ local function selection_iterator(invariant, idx) end end --- If idx_reverse is true, it'll reverse iterate. If nil, or false, regular iterate. +-- If idx_reverse is true, it'll reverse iterate. If nil, or false, regular iterate. -- If a number, runs for exactly that iteration. function Doc:get_selections(sort_intra, idx_reverse) - return selection_iterator, { self.selections, sort_intra, idx_reverse }, + return selection_iterator, { self.selections, sort_intra, idx_reverse }, idx_reverse == true and ((#self.selections / 4) + 1) or ((idx_reverse or -1)+1) end -- End of cursor seciton. @@ -493,5 +494,10 @@ end function Doc:on_text_change(type) end +-- For plugins to get notified when a document is closed +function Doc:on_close() + core.log_quiet("Closed doc \"%s\"", self:get_name()) +end + return Doc diff --git a/data/core/init.lua b/data/core/init.lua index e571e6b4..a23026b2 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -972,7 +972,7 @@ function core.step() local doc = core.docs[i] if #core.get_views_referencing_doc(doc) == 0 then table.remove(core.docs, i) - core.log_quiet("Closed doc \"%s\"", doc:get_name()) + doc:on_close() end end