aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2021-12-30 12:11:01 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2021-12-30 15:26:40 +0100
commitfd074ff39a69238bb72b37373babd6043e30a5d8 (patch)
treeb30e907e97b25dbf4f1424a425a873a9a42c2455
parentadaf0235415c6c18fa907467e12a1f614fa2b001 (diff)
downloadlite-xl-fd074ff39a69238bb72b37373babd6043e30a5d8.tar.gz
lite-xl-fd074ff39a69238bb72b37373babd6043e30a5d8.zip
Fix problem when opening project's module document
It wasn't fine to call core.open_doc without filename argument and later call Doc:save without providing both the filename and the absolute filename. It was giving a Doc in an inconsistent status where self.filename was set but not self.abs_filename. Added an asset to detect early the problem if ever happens again. In turn the problem prevented the project's module hook to work if the file was newly created.
-rw-r--r--data/core/commands/core.lua11
-rw-r--r--data/core/doc/init.lua2
2 files changed, 5 insertions, 8 deletions
diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua
index 16b371f3..3242e2ef 100644
--- a/data/core/commands/core.lua
+++ b/data/core/commands/core.lua
@@ -141,14 +141,9 @@ command.add(nil, {
end,
["core:open-project-module"] = function()
- local filename = ".lite_project.lua"
- if system.get_file_info(filename) then
- core.root_view:open_doc(core.open_doc(filename))
- else
- local doc = core.open_doc()
- core.root_view:open_doc(doc)
- doc:save(filename)
- end
+ local doc = core.open_doc(".lite_project.lua")
+ core.root_view:open_doc(doc)
+ doc:save()
end,
["core:change-project-folder"] = function()
diff --git a/data/core/doc/init.lua b/data/core/doc/init.lua
index 06cde9f9..7b97db35 100644
--- a/data/core/doc/init.lua
+++ b/data/core/doc/init.lua
@@ -85,6 +85,8 @@ function Doc:save(filename, abs_filename)
assert(self.filename, "no filename set to default to")
filename = self.filename
abs_filename = self.abs_filename
+ else
+ assert(self.filename or abs_filename, "calling save on unnamed doc without absolute path")
end
local fp = assert( io.open(filename, "wb") )
for _, line in ipairs(self.lines) do