From 841159b26fa13e260e3f76b85749fe98f437de29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Buckwalter?= Date: Thu, 27 Apr 2023 08:29:43 +0200 Subject: [PATCH] Fix undo of multiline insertion. Problem fixed: Insert a newline at cj>1. Undo (^Z). The undo operation removes cj-1 characters following the point of the insertion. --- buffer.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/buffer.lua b/buffer.lua index ac41e2d..3fe5b74 100644 --- a/buffer.lua +++ b/buffer.lua @@ -334,7 +334,11 @@ function buffer.op_undo(b, sl) if sl.op == "del" then return b:bufins(sl, true) elseif sl.op == "ins" then - return b:bufdel(sl.ci+#sl-1, sl.cj+ulen(sl[#sl]), true) + if #sl == 1 then -- Insertion was limited to part of a single line + return b:bufdel(sl.ci+#sl-1, sl.cj+ulen(sl[#sl]), true) + else -- Insertion spanned multiple lines + return b:bufdel(sl.ci+#sl-1, ulen(sl[#sl]), true) + end else return nil, "unknown op" end