aboutsummaryrefslogtreecommitdiff
path: root/plugins/indent_convert.lua
diff options
context:
space:
mode:
authorGuldoman <giulio.lettieri@gmail.com>2021-11-20 04:30:55 +0100
committerGuldoman <giulio.lettieri@gmail.com>2021-11-20 04:30:55 +0100
commitbcc2c09c4f900a1895e3a57b26e46b64a44c4671 (patch)
treed263e231102d3633cce8b6988600c99c2a3d2cc4 /plugins/indent_convert.lua
parent381b1b944dee3e054fd534d9622dc4cdbb184ab6 (diff)
downloadlite-xl-plugins-bcc2c09c4f900a1895e3a57b26e46b64a44c4671.tar.gz
lite-xl-plugins-bcc2c09c4f900a1895e3a57b26e46b64a44c4671.zip
`indent_convert`: Update the `Doc` indent size with the correct one
Diffstat (limited to 'plugins/indent_convert.lua')
-rw-r--r--plugins/indent_convert.lua26
1 files changed, 16 insertions, 10 deletions
diff --git a/plugins/indent_convert.lua b/plugins/indent_convert.lua
index 8d66033..61d4a98 100644
--- a/plugins/indent_convert.lua
+++ b/plugins/indent_convert.lua
@@ -72,27 +72,32 @@ local function tabs_replacer(text, indent_size)
return text, total
end
-local function replacer(doc, fn)
- local size = config.indent_size
+local function replacer(doc, fn, indent_size)
+ return function(text)
+ return fn(text, indent_size)
+ end
+end
+
+local function get_indent_size(doc)
+ local indent_size = config.indent_size
if type(doc.get_indent_info) == "function" then
-- use the new `Doc:get_indent_info` function
- size = select(2, doc:get_indent_info())
- end
- return function(text)
- return fn(text, size)
+ indent_size = select(2, doc:get_indent_info())
end
+ return indent_size
end
local function tabs_to_spaces()
local doc = core.active_view.doc
+ local indent_size = get_indent_size(doc)
local selections = doc.selections
- doc:replace(replacer(doc, tabs_replacer))
+ doc:replace(replacer(doc, tabs_replacer, indent_size))
doc.selections = selections
doc:sanitize_selection()
if config.plugins.indent_convert.update_indent_type then
doc.indent_info = {
type = "soft",
- size = config.indent_size,
+ size = indent_size,
confirmed = true
}
end
@@ -100,14 +105,15 @@ end
local function spaces_to_tabs()
local doc = core.active_view.doc
+ local indent_size = get_indent_size(doc)
local selections = doc.selections
- doc:replace(replacer(doc, spaces_replacer))
+ doc:replace(replacer(doc, spaces_replacer, indent_size))
doc.selections = selections
doc:sanitize_selection()
if config.plugins.indent_convert.update_indent_type then
doc.indent_info = {
type = "hard",
- size = config.indent_size,
+ size = indent_size,
confirmed = true
}
end