From 4592dd807d7aed5d5b7d56bdf88d05a253b13ab4 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 15 Jul 2025 12:36:50 +0200 Subject: [PATCH 1/4] fix: allow font names longer than 31 characters in win32 closes #275 --- src/win32/FontFace.zig | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/win32/FontFace.zig b/src/win32/FontFace.zig index 6bf2e81..811340e 100644 --- a/src/win32/FontFace.zig +++ b/src/win32/FontFace.zig @@ -2,11 +2,13 @@ const FontFace = @This(); const std = @import("std"); -// it seems that Windows only supports font faces with up to 31 characters -pub const max = 31; +// it seems that Windows only supports font faces with up to 31 characters, +// but we use a larger buffer here because GetFamilyNames can apparently +// return longer strings +pub const max = 254; buf: [max + 1]u16, -len: u5, +len: usize, pub fn initUtf8(utf8: []const u8) error{ TooLong, InvalidUtf8 }!FontFace { const utf16_len = std.unicode.calcUtf16LeLen(utf8) catch return error.InvalidUtf8; From 0003a52aaff5e40f060516f720b53e2ec361fa6e Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 15 Jul 2025 12:38:06 +0200 Subject: [PATCH 2/4] refactor: avoid unnecessary @intCast and @ptrCast in FontFace.zig --- src/win32/FontFace.zig | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/win32/FontFace.zig b/src/win32/FontFace.zig index 811340e..6b6f15b 100644 --- a/src/win32/FontFace.zig +++ b/src/win32/FontFace.zig @@ -14,19 +14,19 @@ pub fn initUtf8(utf8: []const u8) error{ TooLong, InvalidUtf8 }!FontFace { const utf16_len = std.unicode.calcUtf16LeLen(utf8) catch return error.InvalidUtf8; if (utf16_len > max) return error.TooLong; - var result: FontFace = .{ .buf = undefined, .len = @intCast(utf16_len) }; - result.buf[utf16_len] = 0; - const actual_len = try std.unicode.utf8ToUtf16Le(&result.buf, utf8); + var self: FontFace = .{ .buf = undefined, .len = utf16_len }; + const actual_len = try std.unicode.utf8ToUtf16Le(&self.buf, utf8); std.debug.assert(actual_len == utf16_len); - return result; + self.buf[actual_len] = 0; + return self; } pub fn ptr(self: *const FontFace) [*:0]const u16 { - std.debug.assert(self.buf[@as(usize, self.len)] == 0); - return @ptrCast(&self.buf); + return self.slice().ptr; } pub fn slice(self: *const FontFace) [:0]const u16 { - return self.ptr()[0..self.len :0]; + std.debug.assert(self.buf[self.len] == 0); + return self.buf[0..self.len :0]; } pub fn eql(self: *const FontFace, other: *const FontFace) bool { return std.mem.eql(u16, self.slice(), other.slice()); From c5655468e34767752b920b4c695ae3ad45d1d105 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 15 Jul 2025 13:14:47 +0200 Subject: [PATCH 3/4] fix: make keybind module respect command.suppressed_errors list Also, make suppressed_errors a static string map for a little extra performance. --- src/command.zig | 18 +++++++++++------- src/keybind/keybind.zig | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/command.zig b/src/command.zig index e7e0829..8577a9a 100644 --- a/src/command.zig +++ b/src/command.zig @@ -188,17 +188,21 @@ pub fn get_arguments(id: ID) ?[]const ArgumentType { return (commands.items[id] orelse return null).meta.arguments; } -const suppressed_errors = .{ - "enable_fast_scroll", - "disable_fast_scroll", - "clear_diagnostics", -}; +const suppressed_errors = std.StaticStringMap(void).initComptime(.{ + .{ "enable_fast_scroll", void }, + .{ "disable_fast_scroll", void }, + .{ "clear_diagnostics", void }, +}); pub fn executeName(name: []const u8, ctx: Context) tp.result { const id = get_id(name); if (id) |id_| return execute(id_, ctx); - inline for (suppressed_errors) |err| if (std.mem.eql(u8, err, name)) return; - return tp.exit_fmt("CommandNotFound: {s}", .{name}); + return notFoundError(name); +} + +pub fn notFoundError(name: []const u8) !void { + if (!suppressed_errors.has(name)) + return tp.exit_fmt("CommandNotFound: {s}", .{name}); } fn CmdDef(comptime T: type) type { diff --git a/src/keybind/keybind.zig b/src/keybind/keybind.zig index 0a69f6c..e3c71e1 100644 --- a/src/keybind/keybind.zig +++ b/src/keybind/keybind.zig @@ -291,7 +291,7 @@ const Command = struct { fn execute(self: *@This()) !void { const id = self.command_id orelse command.get_id_cache(self.command, &self.command_id) orelse { - return tp.exit_fmt("CommandNotFound: {s}", .{self.command}); + return command.notFoundError(self.command); }; var buf: [2048]u8 = undefined; @memcpy(buf[0..self.args.len], self.args); From bc2fbec083e1af52bbf1d11acb309b0847f3cef4 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 15 Jul 2025 13:15:38 +0200 Subject: [PATCH 4/4] refactor: clean-up std.StaticStringMap naming --- src/keybind/keybind.zig | 2 +- src/syntax/src/file_type.zig | 4 ++-- src/tui/status/widget.zig | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/keybind/keybind.zig b/src/keybind/keybind.zig index e3c71e1..9ffb43b 100644 --- a/src/keybind/keybind.zig +++ b/src/keybind/keybind.zig @@ -18,7 +18,7 @@ const SelectionStyle = @import("Buffer").Selection.Style; const parse_flow = @import("parse_flow.zig"); const parse_vim = @import("parse_vim.zig"); -const builtin_keybinds = std.static_string_map.StaticStringMap([]const u8).initComptime(.{ +const builtin_keybinds = std.StaticStringMap([]const u8).initComptime(.{ .{ "flow", @embedFile("builtin/flow.json") }, .{ "vim", @embedFile("builtin/vim.json") }, .{ "helix", @embedFile("builtin/helix.json") }, diff --git a/src/syntax/src/file_type.zig b/src/syntax/src/file_type.zig index 8030272..c59a922 100644 --- a/src/syntax/src/file_type.zig +++ b/src/syntax/src/file_type.zig @@ -95,7 +95,7 @@ pub const FirstLineMatch = struct { }; const static_file_type_list = load_file_types(@import("file_types.zig")); -const static_file_types = std.static_string_map.StaticStringMap(FileType).initComptime(static_file_type_list); +const static_file_types = std.StaticStringMap(FileType).initComptime(static_file_type_list); fn vec(comptime args: anytype) []const []const u8 { var cmd: []const []const u8 = &[_][]const u8{}; @@ -147,7 +147,7 @@ pub const FileTypeQueries = struct { injections_bin: ?[]const u8, }; -pub const queries = std.static_string_map.StaticStringMap(FileTypeQueries).initComptime(load_queries()); +pub const queries = std.StaticStringMap(FileTypeQueries).initComptime(load_queries()); fn load_queries() []const struct { []const u8, FileTypeQueries } { if (!build_options.use_tree_sitter) return &.{}; diff --git a/src/tui/status/widget.zig b/src/tui/status/widget.zig index 5dfcf2f..1ee1446 100644 --- a/src/tui/status/widget.zig +++ b/src/tui/status/widget.zig @@ -5,7 +5,7 @@ const log = @import("log"); const Widget = @import("../Widget.zig"); -const widgets = std.static_string_map.StaticStringMap(CreateFunction).initComptime(.{ +const widgets = std.StaticStringMap(CreateFunction).initComptime(.{ .{ "mode", @import("modestate.zig").create }, .{ "file", @import("filestate.zig").create }, .{ "log", @import("minilog.zig").create },