From 9c6c5475d1efdbd14d65a7e34d5073e5b60ab85e Mon Sep 17 00:00:00 2001 From: Guldoman Date: Wed, 18 Oct 2023 06:46:58 +0200 Subject: [PATCH] Save in the `workspace` unsaved named files and `crlf` status (#1597) * Save in the `workspace` unsaved named files * Save in the `workspace` the `crlf` status and restore it for "new" files --- data/plugins/workspace.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/data/plugins/workspace.lua b/data/plugins/workspace.lua index 6426cbdb..3b3bd044 100644 --- a/data/plugins/workspace.lua +++ b/data/plugins/workspace.lua @@ -83,7 +83,8 @@ local function save_view(view) filename = view.doc.filename, selection = { view.doc:get_selection() }, scroll = { x = view.scroll.to.x, y = view.scroll.to.y }, - text = not view.doc.filename and view.doc:get_text(1, 1, math.huge, math.huge) + crlf = view.doc.crlf, + text = view.doc.new_file and view.doc:get_text(1, 1, math.huge, math.huge) } end if mt == LogView then return end @@ -106,7 +107,6 @@ local function load_view(t) if not t.filename then -- document not associated to a file dv = DocView(core.open_doc()) - if t.text then dv.doc:insert(1, 1, t.text) end else -- we have a filename, try to read the file local ok, doc = pcall(core.open_doc, t.filename) @@ -114,9 +114,11 @@ local function load_view(t) dv = DocView(doc) end end - -- doc view "dv" can be nil here if the filename associated to the document - -- cannot be read. if dv and dv.doc then + if dv.doc.new_file and t.text then + dv.doc:insert(1, 1, t.text) + dv.doc.crlf = t.crlf + end dv.doc:set_selection(table.unpack(t.selection)) dv.last_line1, dv.last_col1, dv.last_line2, dv.last_col2 = dv.doc:get_selection() dv.scroll.x, dv.scroll.to.x = t.scroll.x, t.scroll.x