From b278306fc94b421eaedf8764301042391ff1569b Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 19 May 2021 16:41:28 -0400 Subject: [PATCH] Changed deindent, so that if the deindent runs into an unusual line with a partial indent at the front, it'll still de-indent that. (#193) --- data/core/commands/doc.lua | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index ee930150..cf4430d3 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -45,15 +45,22 @@ local function insert_at_start_of_selected_lines(text, skip_empty) doc():set_selection(line1, col1 + #text, line2, col2 + #text, swap) end + -local function remove_from_start_of_selected_lines(text, skip_empty) +local function remove_from_start_of_selected_lines(text, skip_empty, remove_partial) local line1, col1, line2, col2, swap = doc_multiline_selection(true) for line = line1, line2 do local line_text = doc().lines[line] - if line_text:sub(1, #text) == text - and (not skip_empty or line_text:find("%S")) - then - doc():remove(line, 1, line, #text + 1) + for i = #text, 1, -1 do + if line_text:sub(1, i) == text:sub(1, i) + and (not skip_empty or line_text:find("%S")) + then + doc():remove(line, 1, line, i + 1) + break + end + if not remove_partial then + break + end end end doc():set_selection(line1, col1 - #text, line2, col2 - #text, swap) @@ -193,7 +200,7 @@ local commands = { ["doc:unindent"] = function() local text = get_indent_string() - remove_from_start_of_selected_lines(text) + remove_from_start_of_selected_lines(text, false, true) end, ["doc:duplicate-lines"] = function()