Merge pull request #682 from Guldoman/indent_refactor
Refactor how to get the indentation of a `Doc`
This commit is contained in:
@@ -16,14 +16,6 @@ local function doc()
|
||||
end
|
||||
|
||||
|
||||
local function get_indent_string()
|
||||
if config.tab_type == "hard" then
|
||||
return "\t"
|
||||
end
|
||||
return string.rep(" ", config.indent_size)
|
||||
end
|
||||
|
||||
|
||||
local function doc_multiline_selections(sort)
|
||||
local iter, state, idx, line1, col1, line2, col2 = doc():get_selections(sort)
|
||||
return function()
|
||||
@@ -164,11 +156,12 @@ local commands = {
|
||||
end,
|
||||
|
||||
["doc:backspace"] = function()
|
||||
local _, indent_size = doc():get_indent_info()
|
||||
for idx, line1, col1, line2, col2 in doc():get_selections() do
|
||||
if line1 == line2 and col1 == col2 then
|
||||
local text = doc():get_text(line1, 1, line1, col1)
|
||||
if #text >= config.indent_size and text:find("^ *$") then
|
||||
doc():delete_to_cursor(idx, 0, -config.indent_size)
|
||||
if #text >= indent_size and text:find("^ *$") then
|
||||
doc():delete_to_cursor(idx, 0, -indent_size)
|
||||
return
|
||||
end
|
||||
end
|
||||
@@ -273,7 +266,7 @@ local commands = {
|
||||
["doc:toggle-line-comments"] = function()
|
||||
local comment = doc().syntax.comment
|
||||
if not comment then return end
|
||||
local indentation = get_indent_string()
|
||||
local indentation = doc():get_indent_string()
|
||||
local comment_text = comment .. " "
|
||||
for idx, line1, _, line2 in doc_multiline_selections(true) do
|
||||
local uncomment = true
|
||||
|
||||
Reference in New Issue
Block a user