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)
This commit is contained in:
parent
86a7037ed9
commit
b278306fc9
|
@ -46,14 +46,21 @@ local function insert_at_start_of_selected_lines(text, skip_empty)
|
||||||
end
|
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)
|
local line1, col1, line2, col2, swap = doc_multiline_selection(true)
|
||||||
for line = line1, line2 do
|
for line = line1, line2 do
|
||||||
local line_text = doc().lines[line]
|
local line_text = doc().lines[line]
|
||||||
if line_text:sub(1, #text) == text
|
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"))
|
and (not skip_empty or line_text:find("%S"))
|
||||||
then
|
then
|
||||||
doc():remove(line, 1, line, #text + 1)
|
doc():remove(line, 1, line, i + 1)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
if not remove_partial then
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
doc():set_selection(line1, col1 - #text, line2, col2 - #text, swap)
|
doc():set_selection(line1, col1 - #text, line2, col2 - #text, swap)
|
||||||
|
@ -193,7 +200,7 @@ local commands = {
|
||||||
|
|
||||||
["doc:unindent"] = function()
|
["doc:unindent"] = function()
|
||||||
local text = get_indent_string()
|
local text = get_indent_string()
|
||||||
remove_from_start_of_selected_lines(text)
|
remove_from_start_of_selected_lines(text, false, true)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["doc:duplicate-lines"] = function()
|
["doc:duplicate-lines"] = function()
|
||||||
|
|
Loading…
Reference in New Issue