Streamlined, and fixed guldo's problem.

This commit is contained in:
Adam Harrison 2022-01-18 21:37:26 -05:00
parent 30cc205cd4
commit cdbfecc5ce
1 changed files with 16 additions and 19 deletions

View File

@ -97,8 +97,8 @@ local function set_cursor(x, y, snap_type)
core.blink_reset() core.blink_reset()
end end
local function line_comment(comment, line1, line2) local function line_comment(comment, line1, col1, line2, col2)
local comment_text = comment .. " " local comment_text = (type(comment) == 'table' and comment[1] or comment) .. " "
local uncomment = true local uncomment = true
local start_offset = math.huge local start_offset = math.huge
for line = line1, line2 do for line = line1, line2 do
@ -120,9 +120,18 @@ local function line_comment(comment, line1, line2)
end end
elseif s then elseif s then
doc():insert(line, start_offset, comment_text) doc():insert(line, start_offset, comment_text)
if type(comment) == 'table' and #comment > 1 then
doc():insert(line, #doc().lines[line], " " .. comment[2])
if line == line2 then
col2 = col2 + #comment[1] + #comment[2] + 2
end
elseif line == line2 then
col2 = col2 + #comment_text
end end
end end
end end
return line1, col1, line2, col2
end
local function block_comment(comment, line1, col1, line2, col2) local function block_comment(comment, line1, col1, line2, col2)
-- automatically skip spaces -- automatically skip spaces
@ -375,23 +384,11 @@ local commands = {
end, end,
["doc:toggle-line-comments"] = function() ["doc:toggle-line-comments"] = function()
local comment = doc().syntax.comment local comment = doc().syntax.comment or doc().syntax.block_comment
local block = false if comment then
if not comment then
comment = doc().syntax.block_comment
if not comment then return end
block = true
end
for idx, line1, col1, line2, col2 in doc_multiline_selections(true) do for idx, line1, col1, line2, col2 in doc_multiline_selections(true) do
if block then line1, col1, line2, col2 = line_comment(comment, line1, col1, line2, col2)
local nline1, ncol1, nline2, ncol2 doc():set_selections(idx, line1, col1, line2, col2)
for line = line1, line2 do
nline1, ncol1, nline2, ncol2 = block_comment(comment, line, 1, line, #doc().lines[line])
end
doc():set_selections(idx, line1, col1, nline2, ncol2)
else
line_comment(comment, line1, line2)
end end
end end
end, end,