From 381b1b944dee3e054fd534d9622dc4cdbb184ab6 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Sat, 20 Nov 2021 03:57:57 +0100 Subject: `indent_convert`: Restore selections --- plugins/indent_convert.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'plugins/indent_convert.lua') diff --git a/plugins/indent_convert.lua b/plugins/indent_convert.lua index 6eb82b0..8d66033 100644 --- a/plugins/indent_convert.lua +++ b/plugins/indent_convert.lua @@ -7,6 +7,9 @@ config.plugins.indent_convert = { update_indent_type = true -- set to false to avoid updating the document indent type } +-- TODO: only set document indent type if there are no selections +-- TODO: correctly restore selections accounting for the offset caused by the conversion + -- To replace N spaces with tabs, we match the last N spaces before the start of -- the actual code and replace them with a tab. -- We repeat this until we can't find any more spaces before the code. @@ -82,7 +85,10 @@ end local function tabs_to_spaces() local doc = core.active_view.doc + local selections = doc.selections doc:replace(replacer(doc, tabs_replacer)) + doc.selections = selections + doc:sanitize_selection() if config.plugins.indent_convert.update_indent_type then doc.indent_info = { type = "soft", @@ -94,7 +100,10 @@ end local function spaces_to_tabs() local doc = core.active_view.doc + local selections = doc.selections doc:replace(replacer(doc, spaces_replacer)) + doc.selections = selections + doc:sanitize_selection() if config.plugins.indent_convert.update_indent_type then doc.indent_info = { type = "hard", -- cgit v1.2.3