terminal: redesign pin map for formatter

This commit is contained in:
Mitchell Hashimoto
2026-08-03 20:09:57 -07:00
parent d4391ff835
commit 2ed67cadd1
5 changed files with 495 additions and 240 deletions

View File

@@ -6,9 +6,9 @@ const std = @import("std");
const build_options = @import("terminal_options");
const oni = @import("oniguruma");
const point = @import("point.zig");
const PinMap = @import("formatter.zig").PinMap;
const Selection = @import("Selection.zig");
const Screen = @import("Screen.zig");
const Pin = @import("PageList.zig").Pin;
const Allocator = std.mem.Allocator;
// Retry budget for StringMap regex searches.
@@ -18,11 +18,15 @@ const Allocator = std.mem.Allocator;
const oni_search_retry_limit = 100_000;
string: [:0]const u8,
map: []Pin,
/// Mapping of string byte offsets to pins. See PinMap for the
/// storage details.
map: PinMap.Map,
pub fn deinit(self: StringMap, alloc: Allocator) void {
alloc.free(self.string);
alloc.free(self.map);
var map = self.map;
map.deinit(alloc);
}
/// Returns an iterator that yields the next match of the given regex.
@@ -106,8 +110,8 @@ pub const Match = struct {
pub fn selection(self: Match) Selection {
const start_idx: usize = @intCast(self.region.starts()[0]);
const end_idx: usize = @intCast(self.region.ends()[0] - 1);
const start_pt = self.map.map[self.offset + start_idx];
const end_pt = self.map.map[self.offset + end_idx];
const start_pt = self.map.map.get(self.offset + start_idx).?;
const end_pt = self.map.map.get(self.offset + end_idx).?;
return .init(start_pt, end_pt, false);
}
};