fix: replace tabs in snippets if we are indenting with spaces

This commit is contained in:
CJ van den Berg 2026-02-03 16:36:37 +01:00
parent 56238c776d
commit 7c61b2dac6
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -4934,7 +4934,20 @@ pub const Editor = struct {
}
pub const select_prev_sibling_meta: Meta = .{ .description = "Move selection to previous AST sibling node" };
pub fn insert_snippet(self: *Self, snippet_text: []const u8) Result {
pub fn insert_snippet(self: *Self, snippet_text_: []const u8) Result {
var snippet_buf: std.ArrayList(u8) = .empty;
defer snippet_buf.deinit(self.allocator);
const snippet_text = switch (self.indent_mode) {
.tabs => snippet_text_,
.spaces, .auto => blk: {
const space = " ";
for (snippet_text_) |c| try if (c == '\t')
snippet_buf.appendSlice(self.allocator, space[0..self.indent_size])
else
snippet_buf.append(self.allocator, c);
break :blk snippet_buf.items;
},
};
self.logger.print("snippet: {s}", .{snippet_text});
const value = try snippet.parse(self.allocator, snippet_text);
defer value.deinit(self.allocator);