From 5e35824a2203caba451788cc40da9f0a44ac0dc4 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Fri, 6 Dec 2024 23:21:45 +0100 Subject: [PATCH] fix: restore cursors if unindent fails --- src/tui/editor.zig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 372b11e..c53ad9d 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -2638,6 +2638,10 @@ pub const Editor = struct { pub fn unindent(self: *Self, _: Context) Result { const b = try self.buf_for_update(); + errdefer blk: { + self.cursels.clearAndFree(); + self.cursels = self.cursels_saved.clone() catch break :blk; + } const root = try self.with_cursels_mut(b.root, unindent_cursel, b.allocator); try self.update_buf(root); }