Fixed undo stack.

This commit is contained in:
Adam Harrison 2021-06-05 16:06:21 -04:00
parent 93670a314d
commit a7f39017ff
2 changed files with 12 additions and 9 deletions

View File

@ -159,9 +159,16 @@ end
function Doc:get_selection(sort)
if sort then
return sort_positions(self.selections[1], self.selections[2], self.selections[3], self.selections[4])
local result = {}
for sidx, line1, col1, line2, col2 in self:get_selections(true) do
table.insert(result, line1)
table.insert(result, col1)
table.insert(result, line2)
table.insert(result, col2)
end
return result
end
return self.selections[1], self.selections[2], self.selections[3], self.selections[4]
return unpack(self.selections)
end
function Doc:get_selection_count()
@ -292,14 +299,11 @@ local function pop_undo(self, undo_stack, redo_stack, modified)
if cmd.type == "insert" then
local line, col, text = table.unpack(cmd)
self:raw_insert(line, col, text, redo_stack, cmd.time)
elseif cmd.type == "remove" then
local line1, col1, line2, col2 = table.unpack(cmd)
self:raw_remove(line1, col1, line2, col2, redo_stack, cmd.time)
elseif cmd.type == "selection" then
self.selection.a.line, self.selection.a.col = cmd[1], cmd[2]
self.selection.b.line, self.selection.b.col = cmd[3], cmd[4]
self.selections = { unpack(cmd) }
end
modified = modified or (cmd.type ~= "selection")

View File

@ -278,12 +278,11 @@ function DocView:on_mouse_moved(x, y, ...)
local clicks = self.mouse_selecting.clicks
if keymap.modkeys["ctrl"] then
if l1 > l2 then
l2 = l1
l1, l2 = l2, l1
end
local idx = 1
for i = l1, l2 do
idx = idx + 1
self.doc:set_selections(idx, i, math.min(c1, #self.doc.lines[i]), i, math.min(c1, #self.doc.lines[i]))
self.doc:set_selections(i - l1 + 1, i, math.min(c1, #self.doc.lines[i]), i, math.min(c1, #self.doc.lines[i]))
end
else
self.doc:set_selection(mouse_selection(self.doc, clicks, l1, c1, l2, c2))