summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CHANGELOG.md13
-rw-r--r--src/body_layer.zig2
-rw-r--r--src/draw.zig95
-rw-r--r--src/grammar_manifest.zig108
-rw-r--r--src/gui/gui.zig14
-rw-r--r--src/layout.zig14
-rw-r--r--src/mouse.zig261
-rw-r--r--src/surface.zig18
-rw-r--r--src/syntax.zig114
9 files changed, 155 insertions, 484 deletions
diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md
index 3297336e..da489b82 100644
--- a/src/CHANGELOG.md
+++ b/src/CHANGELOG.md
@@ -2,6 +2,19 @@
## Unreleased
+- A drag draws no guide lines: no dashes where a pane or column would
+ land, no rail for a carried column, no dashed seam under a pane rule
+ held. The line between two columns no longer resizes them (nor, at a
+ pane's corner, the panes too): a press there is a press in the pane.
+ A column resizes by its box, left of its tag; a pane by its own box,
+ or in a window by the rule above it.
+
+- An edit to the core recompiles it about 3 s sooner (`core-test`, 13 s to
+ 10 s): the build keeps each grammar's highlight patterns that pardes
+ colours once, where every compile of every program that takes the core
+ did it again, a quarter of its time. A package that depends on pardes
+ is given the same filtered queries.
+
- The core measures a grapheme's cells over uucode itself
(`File.utf8Width`, libvaxis's `gwidth` to the cell on every scalar
value), so libvaxis is the tui's and the gui's alone, not the core
diff --git a/src/body_layer.zig b/src/body_layer.zig
index 76aec179..dbf0156d 100644
--- a/src/body_layer.zig
+++ b/src/body_layer.zig
@@ -195,7 +195,7 @@ pub fn joinBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
layer.id = @intCast(id);
layer.serial = pane.serial;
const body = s.region(.body, id).?;
- layer.viewport = .{ .x = body.rect.x, .y = body.rect.y, .w = body.rect.w - body.clip, .h = body.rect.h };
+ layer.viewport = .{ .x = body.rect.x, .y = body.rect.y, .w = body.rect.w, .h = body.rect.h };
layer.cols = width;
layer.rows = @intCast(logical_rows);
layer.context_rows = pane.context_rows;
diff --git a/src/draw.zig b/src/draw.zig
index a0a28cc7..2fabff06 100644
--- a/src/draw.zig
+++ b/src/draw.zig
@@ -115,24 +115,6 @@ pub fn place(p: *Pardes, s: *Surface) void {
}
if (p.settings.workspace_tag)
s.addRegion(.{ .kind = .workspace_tag, .rect = .{ .x = 0, .y = 0, .w = s.cols, .h = p.topBarHeight() } });
- // A column carried to the window's right edge shows where it lands as a
- // rail in the last cell: the layers under it stop a cell short.
- if (v.drag == .column_move) rail: {
- const d = v.drag.column_move;
- const source = layout.columnBySerial(p, d.serial) orelse break :rail;
- const edge: u16 = switch (layout.columnDrop(p, source, d.cur_x, d.grab)) {
- .stay => break :rail,
- .reorder => |target| if (target < source) v.col_x[target] else v.col_x[target] + v.col_w[target],
- .edge => |x| x,
- };
- if (edge != s.cols) break :rail;
- for (s.regions[0..s.nregions]) |*region| switch (region.kind) {
- .body, .tag, .notice, .column_tag => if (region.rect.x + region.rect.w == s.cols) {
- region.clip = 1;
- },
- else => {},
- };
- }
}
/// A pane's grip in the grid: `box` focused, else halfway between its ring
@@ -251,8 +233,6 @@ fn joinNotice(p: *Pardes, s: *Surface, arena: std.mem.Allocator, region: Region)
if (layer.cursor) |caret| {
if (caret.x >= skip) s.cursor = .{ .x = region.rect.x + caret.x - @as(u16, @intCast(skip)), .y = region.rect.y, .bar = caret.bar };
}
- // Laid out at its full width; only shown short of the rail.
- layer.viewport.w -|= region.clip;
}
pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
@@ -327,77 +307,6 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
try paintHeaders(p, s);
- switch (v.drag) {
- .border_v => |d| {
- if (d.cur_x < s.cols) {
- var row: u16 = p.topBarHeight();
- while (row < s.rows) : (row += 1) s.overlayDash(d.cur_x, row, "╎");
- s.addRegion(.{ .kind = .guide, .rect = .{ .x = d.cur_x, .y = p.topBarHeight(), .w = 1, .h = s.rows -| p.topBarHeight() } });
- }
- if (d.corner) |k| if (d.cur_y < s.rows) {
- const first = if (k.col == d.left_col) v.col_x[k.col] else d.cur_x +| 1;
- const end = if (k.col == d.left_col) d.cur_x else v.col_x[k.col] +| v.col_w[k.col] -| 1;
- var col = first;
- while (col <= end and col < s.cols) : (col += 1) s.overlayDash(col, d.cur_y, "╌");
- if (col > first) s.addRegion(.{ .kind = .guide, .rect = .{ .x = first, .y = d.cur_y, .w = col - first, .h = 1 } });
- };
- },
- // A column that went away mid-drag has nothing to guide.
- .border_h => |d| if (d.cur_y < s.rows and d.col < v.ncol and v.col_x[d.col] < s.cols) {
- const end = @min(s.cols, v.col_x[d.col] + v.col_w[d.col]);
- var col = v.col_x[d.col];
- while (col < end) : (col += 1) s.overlayDash(col, d.cur_y, "╌");
- s.addRegion(.{ .kind = .guide, .rect = .{ .x = v.col_x[d.col], .y = d.cur_y, .w = end - v.col_x[d.col], .h = 1 } });
- },
- .column_move => |d| rail: {
- const source = layout.columnBySerial(p, d.serial) orelse break :rail;
- if (s.cols == 0) break :rail;
- // Where the column's left edge would land, reordered or not.
- const edge: u16 = switch (layout.columnDrop(p, source, d.cur_x, d.grab)) {
- .stay => break :rail,
- .reorder => |target| if (target < source) v.col_x[target] else v.col_x[target] + v.col_w[target],
- .edge => |x| x,
- };
- // The layers under an outside rail stop a cell short of it:
- // `place` clipped them.
- // The rail runs in the seam cell left of the edge, where a
- // border drag's does: the edge cell itself is a gutter, which
- // the GUI paints as a scroll rail that swallowed the dashes.
- // At the window's left edge there is no seam, so it runs just
- // past that scroll rail instead. It takes the lit grip's
- // color: this is where the grabbed column lands.
- const x = @min(if (edge == 0) config.GUTTER - 1 else edge - 1, s.cols -| 1);
- var row: u16 = p.topBarHeight();
- // A guide region for each run of it the tags do not break.
- var run: u16 = row;
- while (row < s.rows) : (row += 1) {
- // Past the left edge's scroll rail the rail would cut
- // through column 0's grip and pane boxes: leave them whole.
- if (edge == 0 and s.at(x, row).style.font_role == .tagline) {
- if (row > run) s.addRegion(.{ .kind = .guide, .rect = .{ .x = x, .y = run, .w = 1, .h = row - run } });
- run = row + 1;
- continue;
- }
- s.overlayDash(x, row, "╎");
- s.at(x, row).style.fg = .{ .rgb = chrome.column_box };
- }
- if (row > run) s.addRegion(.{ .kind = .guide, .rect = .{ .x = x, .y = run, .w = 1, .h = row - run } });
- },
- .move => |d| if (d.cur_x < s.cols) {
- if (layout.movePlacement(p, d.id, d.cur_x, d.cur_y)) |placement| if (placement.row < s.rows and v.col_x[placement.preview_col] + v.col_w[placement.preview_col] <= s.cols) {
- var col: u16 = v.col_x[placement.preview_col];
- while (col < v.col_x[placement.preview_col] + v.col_w[placement.preview_col]) : (col += 1) {
- s.set(col, placement.row, "╌", .{ .fg = .{ .rgb = chrome.lineno } });
- }
- s.set(d.cur_x, placement.row, "▌", .{ .fg = .{ .rgb = chrome.lineno } });
- s.addRegion(.{ .kind = .guide, .rect = .{ .x = v.col_x[placement.preview_col], .y = placement.row, .w = v.col_w[placement.preview_col], .h = 1 } });
- s.addRegion(.{ .kind = .guide, .rect = .{ .x = d.cur_x, .y = placement.row, .w = 1, .h = 1 } });
- };
- },
- // A hover draws no hint: columns resize by their grips.
- .none, .select => {},
- }
-
// debug overlay: a small stats box drawn last, top-right ("Debug")
if (p.settings.debug) if (p.panes[v.active]) |at| {
var nlive: usize = 0;
@@ -606,8 +515,6 @@ fn paintHeaders(p: *Pardes, s: *Surface) !void {
const layer = &s.tag_layers[MAX_PANES + c];
try renderHeaderLayer(p, layer, .column, @intCast(c), region.rect, tagline.columnTag(p, c), top, bg, fg);
if (v.col_x[c] < s.cols) joinHeaderRows(s, layer, fg);
- // Laid out at its full width; only shown short of the rail.
- layer.viewport.w -|= region.clip;
};
}
@@ -809,7 +716,7 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r
layer.kind = .pane;
layer.id = @intCast(id);
layer.serial = pane.serial;
- layer.viewport = .{ .x = region.rect.x, .y = region.rect.y, .w = region.rect.w - region.clip, .h = rows };
+ layer.viewport = .{ .x = region.rect.x, .y = region.rect.y, .w = region.rect.w, .h = rows };
layer.cols = columns;
layer.rows = rows;
layer.context_rows = 0;
diff --git a/src/grammar_manifest.zig b/src/grammar_manifest.zig
index 38c54916..711c31a4 100644
--- a/src/grammar_manifest.zig
+++ b/src/grammar_manifest.zig
@@ -1,6 +1,7 @@
//! Dependency-free tree-sitter grammar metadata shared by build.zig and the
-//! runtime syntax registry. Keep target symbols and query values out of this
-//! file: the build runner imports it as host code.
+//! runtime syntax registry, and the highlight-query filter the build runs.
+//! Keep target symbols and query values out of this file: the build runner
+//! imports it as host code.
const std = @import("std");
@@ -14,6 +15,8 @@ pub const Grammar = struct {
src: []const u8 = "src",
scanner: bool = false,
query: []const u8 = "queries/highlights.scm",
+ /// Patterns appended to the highlights query before it is filtered.
+ highlights_extra: []const u8 = "",
};
pub const all = [_]Grammar{
@@ -48,7 +51,13 @@ pub const all = [_]Grammar{
.{ .name = "ruby", .dep = "ts_ruby", .exts = &.{ ".rb", ".rake" }, .tier = .full, .scanner = true },
.{ .name = "rust", .dep = "ts_rust", .exts = &.{".rs"}, .tier = .full, .scanner = true },
.{ .name = "scala", .dep = "ts_scala", .exts = &.{ ".scala", ".sc" }, .tier = .full, .scanner = true },
- .{ .name = "typst", .dep = "ts_typst", .exts = &.{ ".typ", ".typst" }, .tier = .full, .scanner = true, .query = "queries/typst/highlights.scm" },
+ .{ .name = "typst", .dep = "ts_typst", .exts = &.{ ".typ", ".typst" }, .tier = .full, .scanner = true, .query = "queries/typst/highlights.scm", .highlights_extra =
+ \\
+ \\(call item: (ident) @keyword)
+ \\(call item: (field field: (ident) @keyword))
+ \\"#" @keyword
+ \\
+ },
.{ .name = "zig", .dep = "ts_zig", .exts = &.{ ".zig", ".zon" }, .tier = .zig },
};
@@ -92,3 +101,96 @@ pub fn byPath(path: []const u8) ?usize {
for (all, 0..) |g, i| for (g.exts) |e| if (std.ascii.eqlIgnoreCase(ext, e)) return i;
return null;
}
+
+/// pardes's syntax classes: what a capture colours a byte as.
+pub const Syn = enum(u8) { none, keyword, string, number, comment };
+
+pub fn synFor(name: []const u8) Syn {
+ for ([_]struct { []const u8, Syn }{
+ .{ "comment", .comment },
+ .{ "string", .string },
+ .{ "character", .string },
+ .{ "number", .number },
+ .{ "numeric", .number },
+ .{ "float", .number },
+ .{ "boolean", .number },
+ .{ "keyword", .keyword },
+ .{ "include", .keyword },
+ .{ "conditional", .keyword },
+ .{ "repeat", .keyword },
+ .{ "title", .keyword },
+ .{ "uri", .string },
+ .{ "reference", .number },
+ .{ "heading", .keyword },
+ .{ "strong", .comment },
+ .{ "bold", .comment },
+ .{ "emphasis", .number },
+ .{ "italic", .number },
+ .{ "literal", .string },
+ .{ "raw", .string },
+ }) |m| {
+ if (std.mem.indexOf(u8, name, m[0]) != null) return m[1];
+ }
+ return .none;
+}
+
+/// The patterns of highlights query `source` that capture a class (synFor),
+/// written to `out` (source.len bytes): what a grammar's query compiles to.
+/// build.zig filters each one with it, ts_queries' `<name>_highlights`.
+pub fn colorQuery(source: []const u8, out: []u8) []u8 {
+ var written: usize = 0;
+ var at: usize = 0;
+ while (at < source.len) {
+ while (at < source.len) {
+ if (std.ascii.isWhitespace(source[at])) {
+ at += 1;
+ } else if (source[at] == ';') {
+ while (at < source.len and source[at] != '\n') at += 1;
+ } else break;
+ }
+ const begin = at;
+ var depth: usize = 0;
+ var colored = false;
+ var complete = false;
+ while (at < source.len) {
+ const byte = source[at];
+ if (complete and (byte == '(' or byte == '[' or byte == '"')) break;
+ if (byte == ';') {
+ while (at < source.len and source[at] != '\n') at += 1;
+ continue;
+ }
+ if (byte == '"') {
+ at += 1;
+ while (at < source.len) : (at += 1) {
+ if (source[at] == '\\') {
+ at += 1;
+ } else if (source[at] == '"') {
+ at += 1;
+ break;
+ }
+ }
+ if (depth == 0) complete = true;
+ continue;
+ }
+ if (byte == '(' or byte == '[') depth += 1;
+ if (byte == ')' or byte == ']') {
+ depth -= 1;
+ if (depth == 0) complete = true;
+ }
+ if (byte == '@') {
+ const name = at + 1;
+ at = name;
+ while (at < source.len and (std.ascii.isAlphanumeric(source[at]) or
+ source[at] == '_' or source[at] == '.' or source[at] == '-')) at += 1;
+ colored = colored or synFor(source[name..at]) != .none;
+ continue;
+ }
+ at += 1;
+ }
+ if (colored) {
+ @memcpy(out[written..][0 .. at - begin], source[begin..at]);
+ written += at - begin;
+ }
+ }
+ return out[0..written];
+}
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index 202f4aa8..45157dd3 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -868,12 +868,12 @@ const Group = struct {
};
/// The frame's draw groups, bottom to top: the page and the panes, the
-/// notices floating over them, the guides and the debug box the core paints
-/// over those, and ink (the bar cursors; the cursor's glide draws after it).
+/// notices floating over them, the debug box the core paints over those,
+/// and ink (the bar cursors; the cursor's glide draws after it).
const Groups = struct {
items: [4]Group = @splat(.{}),
notices: usize = 1,
- guides: usize = 2,
+ debug: usize = 2,
ink: usize = 3,
len: usize = 4,
};
@@ -883,7 +883,7 @@ const Groups = struct {
const Cover = packed struct(u16) {
/// A layer draws it; the grid's copy is not drawn.
layer: bool = false,
- /// Under a guide or the debug box: drawn from the grid over the panes.
+ /// Under the debug box: drawn from the grid over the panes.
floating: bool = false,
/// In a pane's grip, `grip_offset` cells from its left: the grip's
/// glyph is the cell that far to the left.
@@ -950,7 +950,7 @@ fn coverFrame(cover: []Cover, cols: u16, rows: u16, body_layers: []const pardes.
mark.rect(cover, cols, rows, .{ .x = region.rect.x, .y = 0, .w = 1, .h = rows }, "anchor", true);
if (region.active) if (bar) |b| mark.rect(cover, cols, rows, .{ .x = region.rect.x, .y = b.y, .w = region.rect.w, .h = b.h }, "focus", true);
},
- .guide, .debug => mark.rect(cover, cols, rows, region.rect, "floating", true),
+ .debug => mark.rect(cover, cols, rows, region.rect, "floating", true),
else => {},
};
}
@@ -4559,7 +4559,7 @@ fn renderFrame(
while (col < surface.cols) : (col += 1) {
const at = @as(usize, row) * surface.cols + col;
if (covered[at].layer and !covered[at].floating) continue;
- const group_index = if (covered[at].floating) groups.guides else 0;
+ const group_index = if (covered[at].floating) groups.debug else 0;
groups.items[group_index].cell_count = std.math.add(u32, groups.items[group_index].cell_count, cellInstanceCount(&surface.cells[at])) catch return error.GpuCapacity;
}
}
@@ -4608,7 +4608,7 @@ fn renderFrame(
while (col < surface.cols) : (col += 1) {
const at = @as(usize, row) * surface.cols + col;
if (covered[at].layer and !covered[at].floating) continue;
- const group_index = if (covered[at].floating) groups.guides else 0;
+ const group_index = if (covered[at].floating) groups.debug else 0;
emitSurfaceCell(
g,
chrome,
diff --git a/src/layout.zig b/src/layout.zig
index fca4c846..0cfbf04a 100644
--- a/src/layout.zig
+++ b/src/layout.zig
@@ -180,8 +180,8 @@ pub fn columnDrop(p: *const Pardes, source: usize, x: u16, grab: u16) ColumnDrop
}
/// Share out the width of columns `left` and `left + 1` so the left one is
-/// `left_width` cells, neither below MINW. A border drag and a column grip
-/// dropped inside its own place both end here.
+/// `left_width` cells, neither below MINW. A column grip dropped inside its
+/// own place ends here.
pub fn setColumnPairWidth(p: *Pardes, left: usize, left_width: u64) void {
const v = p.view();
if (left + 1 >= v.ncol) return;
@@ -2099,15 +2099,7 @@ test "repeated non-dyadic column splits preserve every unrelated boundary" {
try std.testing.expect(splitColumn(p, 0, 1, false));
p.sync();
- const handle = p.view().col_x[0] + p.view().col_w[0] - 1;
- const untouched = weightsOf(p);
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = TOPBAR_H + 1 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle, .row = TOPBAR_H + 1 } });
- try std.testing.expectEqual(untouched, weightsOf(p));
-
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = TOPBAR_H + 1 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = 417, .row = TOPBAR_H + 1 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = 417, .row = TOPBAR_H + 1 } });
+ setColumnPairWidth(p, 0, 418);
p.sync();
try std.testing.expectEqual(@as(u16, 418), p.view().rects[0].w);
diff --git a/src/mouse.zig b/src/mouse.zig
index 783b12b7..2ca984ba 100644
--- a/src/mouse.zig
+++ b/src/mouse.zig
@@ -1,6 +1,5 @@
//! The mouse: what a pointer is over, the three buttons' presses, drags and
-//! releases (acme's chords, border and seam drags, gestures), and the
-//! chrome targets a shell asks about.
+//! releases (acme's chords, grip and seam drags, gestures).
const pardes = @import("pardes.zig");
const tagline = @import("tagline.zig");
const exec = @import("exec.zig");
@@ -19,7 +18,6 @@ const Pane = panes.Pane;
const MAX_PANES = pardes.MAX_PANES;
const Layer = @import("Layer.zig");
const Jump = @import("Jump.zig");
-const TOPBAR_H = pardes.TOPBAR_H;
const BOX_H = pardes.BOX_H;
const TAG_TEXT_INSET = pardes.TAG_TEXT_INSET;
const Builtin = pardes.Builtin;
@@ -29,7 +27,6 @@ const Pardes = pardes.Pardes;
pub const Drag = union(enum) {
none,
- border_v: struct { left_col: usize, cur_x: u16, corner: ?struct { col: usize, idx: usize } = null, cur_y: u16 = 0 },
border_h: struct { col: usize, top_idx: usize, cur_y: u16 },
move: struct { id: usize, cur_x: u16, cur_y: u16 },
/// `grab`: how far into the grip it was pressed, so the column's left
@@ -58,7 +55,7 @@ pub const Drag = union(enum) {
fn button(drag: Drag) ?Mouse.Button {
return switch (drag) {
.none => null,
- .border_v, .border_h, .move, .column_move => config.select_button,
+ .border_h, .move, .column_move => config.select_button,
.select => |selection| selection.button,
};
}
@@ -126,38 +123,6 @@ fn seamRowOf(p: *const Pardes, c: usize, k: usize) u16 {
return r.y + r.h -| 1;
}
-pub const ChromeTarget = struct { col: u16, row: u16 };
-
-/// The chrome a press at `col`, `row` takes: the tag rows; then,
-/// on the cell, a pane's grip, a column's handle or a seam; then a cell
-/// away, any of a pane's tag, a handle or a seam.
-pub fn chromeTarget(p: *const Pardes, col: u16, row: u16) ?ChromeTarget {
- const v = p.view();
- if (row < p.topBarHeight() + layout.columnBarHeight(p)) return .{ .col = col, .row = row };
- for ([_]u16{ 0, 1 }) |slack| {
- for (p.panes, 0..) |slot, id| {
- const pane = slot orelse continue;
- const rect = v.rects[id];
- const tag = p.tagTop(pane, rect);
- const edge = if (slack == 0) rect.x + config.GUTTER else rect.x + rect.w;
- if (row >= tag and row < tag + pane.tag_rows and col >= rect.x and col < rect.x + rect.w and col < edge)
- return .{ .col = col, .row = row };
- }
- for (0..p.view().ncol -| 1) |column| {
- const handle = v.col_x[column] + v.col_w[column] -| 1;
- if (@max(col, handle) - @min(col, handle) == slack) return .{ .col = handle, .row = row };
- }
- for (0..p.view().ncol) |column| {
- if (col < v.col_x[column] or col >= v.col_x[column] + v.col_w[column]) continue;
- for (0..p.view().cols[column].n -| 1) |index| {
- const seam = seamRowOf(p, column, index);
- if (@max(row, seam) - @min(row, seam) == slack) return .{ .col = col, .row = seam };
- }
- }
- }
- return null;
-}
-
pub fn paneAt(p: *const Pardes, col: u16, row: u16) ?usize {
for (p.panes, 0..) |slot, id| {
if (slot == null) continue;
@@ -781,18 +746,6 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
return;
}
}
- for (0..p.view().ncol -| 1) |c| {
- if (mcol == v.col_x[c] + v.col_w[c] -| 1) {
- const corner: @FieldType(@FieldType(Drag, "border_v"), "corner") = if (seamIdxAt(p, c, mrow)) |k|
- .{ .col = c, .idx = k }
- else if (seamIdxAt(p, c + 1, mrow)) |k|
- .{ .col = c + 1, .idx = k }
- else
- null;
- v.drag = .{ .border_v = .{ .left_col = c, .cur_x = mcol, .corner = corner, .cur_y = mrow } };
- return;
- }
- }
// Two panes are resized on the rule between them, never on a
// row of text; with no rule, by the grip, as acme moves a
// window by its button.
@@ -923,12 +876,6 @@ fn seamIdxAt(p: *const Pardes, c: usize, mrow: u16) ?usize {
return null;
}
-fn clampBorderCol(lx: u16, lw: u16, rw: u16, mcol: u16) u16 {
- const lo = lx + config.MINW;
- const hi = lx +| lw +| rw -| config.MINW;
- return if (lo <= hi) std.math.clamp(mcol, lo, hi) else mcol;
-}
-
fn clampBorderRow(ay: u16, ah: u16, bh: u16, mrow: u16) u16 {
const lo = ay + BOX_H - 1;
const hi = ay +| ah +| bh -| (BOX_H + 1);
@@ -938,20 +885,6 @@ fn clampBorderRow(ay: u16, ah: u16, bh: u16, mrow: u16) u16 {
pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) void {
const v = p.view();
switch (v.drag) {
- .border_v => |*d| {
- const c = d.left_col;
- d.cur_x = if (c + 1 < v.ncol)
- clampBorderCol(v.col_x[c], v.col_w[c], v.col_w[c + 1], mcol)
- else
- mcol;
- if (d.corner) |k| if (k.idx + 1 < v.cols[k.col].n) {
- const a = v.rects[v.cols[k.col].panes[k.idx]];
- const b = v.rects[v.cols[k.col].panes[k.idx + 1]];
- d.cur_y = clampBorderRow(a.y, a.h, b.h, mrow);
- } else {
- d.cur_y = mrow;
- };
- },
.border_h => |*d| {
const cc = d.col;
const k = d.top_idx;
@@ -1239,18 +1172,6 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void {
defer v.drag = .none;
defer v.chord_hold = false;
switch (v.drag) {
- .border_v => |d| {
- const c = d.left_col;
- const old_seam = v.col_x[c] + v.col_w[c] -| 1;
- // the handle is the left pane's LAST column (inclusive), so
- // the new width includes it — a no-drag click changes nothing
- if (c + 1 < v.ncol and d.cur_x != old_seam)
- layout.setColumnPairWidth(p, c, (d.cur_x + 1) -| v.col_x[c]);
- if (d.corner) |k| {
- if (d.cur_y != seamRowOf(p, k.col, k.idx))
- layout.applyRowSplit(p, k.col, k.idx, d.cur_y);
- }
- },
.border_h => |d| if (d.cur_y != seamRowOf(p, d.col, d.top_idx))
layout.applyRowSplit(p, d.col, d.top_idx, d.cur_y),
.column_move => |d| if (layout.columnBySerial(p, d.serial)) |column| switch (layout.columnDrop(p, column, d.cur_x, d.grab)) {
@@ -1391,7 +1312,7 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void {
const test_metrics: pardes.RowMetrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 6, .tagline_h = 12 };
-fn cornerFixture(gpa: std.mem.Allocator) !*Pardes {
+fn twoColumns(gpa: std.mem.Allocator) !*Pardes {
const p = try Pardes.init(gpa, .{ .cols = 100, .rows = 30, .shells = 3 });
p.update(.{ .resize = .{ .cols = 100, .rows = 30 } });
p.view().active = p.view().cols[1].panes[0];
@@ -1463,7 +1384,7 @@ fn layerCenter(layer: *const Layer, col: u16, comptime tag: bool) [2]f32 {
}
test "a pane's last row of text is no resize handle; the rule over the next pane is" {
- const p = try cornerFixture(std.testing.allocator);
+ const p = try twoColumns(std.testing.allocator);
defer p.deinit();
const seam = seamRowOf(p, 1, 0);
const inside = p.view().col_x[1] + p.view().col_w[1] / 2;
@@ -1473,8 +1394,22 @@ test "a pane's last row of text is no resize handle; the rule over the next pane
try std.testing.expect(nudgeRightSeam(p, 2) == seam + 2);
}
+test "the line between two columns is no resize handle: a press there is a sweep in the pane" {
+ const p = try twoColumns(std.testing.allocator);
+ defer p.deinit();
+ const line = p.view().col_x[0] + p.view().col_w[0] - 1;
+ const row = p.view().rects[p.view().cols[0].panes[0]].y + BOX_H + 1;
+ const weight = p.view().cols[0].weight;
+ p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = line, .row = row } });
+ try std.testing.expect(p.view().drag == .select);
+ p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = line + 8, .row = row } });
+ p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = line + 8, .row = row } });
+ p.sync();
+ try std.testing.expectEqual(weight, p.view().cols[0].weight);
+}
+
test "a pane's grip dragged up or down its own column moves its top, down to the floor of the pane above" {
- const p = try cornerFixture(std.testing.allocator);
+ const p = try twoColumns(std.testing.allocator);
defer p.deinit();
const upper = p.view().cols[1].panes[0];
const lower = p.view().cols[1].panes[1];
@@ -1499,26 +1434,6 @@ test "a pane's grip dragged up or down its own column moves its top, down to the
try std.testing.expectEqual(to, p.view().rects[lower].y);
}
-test "a press near chrome takes it: the tag rows, a column's handle or a seam on its cell or a cell away, a pane's tag; nothing in a body" {
- const p = try cornerFixture(std.testing.allocator);
- defer p.deinit();
- // Column 0's two panes share its rows evenly; column 1's lower one is
- // tall, its middle a body row.
- const handle = p.view().col_x[0] + p.view().col_w[0] - 1;
- const seam = seamRowOf(p, 0, 0);
- const mid = p.view().col_x[0] + p.view().col_w[0] / 2;
- const top = p.view().rects[p.view().cols[0].panes[0]].y;
- const low = p.view().rects[p.view().cols[1].panes[1]];
- const body = low.y + low.h / 2;
- try std.testing.expectEqual(ChromeTarget{ .col = 5, .row = 0 }, chromeTarget(p, 5, 0).?);
- try std.testing.expectEqual(ChromeTarget{ .col = handle, .row = body }, chromeTarget(p, handle, body).?);
- try std.testing.expectEqual(ChromeTarget{ .col = handle, .row = body }, chromeTarget(p, handle + 1, body).?);
- try std.testing.expectEqual(ChromeTarget{ .col = mid, .row = seam }, chromeTarget(p, mid, seam).?);
- try std.testing.expectEqual(ChromeTarget{ .col = mid, .row = seam }, chromeTarget(p, mid, seam - 1).?);
- try std.testing.expectEqual(ChromeTarget{ .col = mid, .row = top }, chromeTarget(p, mid, top).?);
- try std.testing.expect(chromeTarget(p, mid, seam - 3) == null);
-}
-
test "plain left click clears explicit modal selection" {
const gpa = std.testing.allocator;
// Wide enough for the tag on one row: the body starts under it.
@@ -1558,144 +1473,6 @@ test "a selection drag and its release leave the selection done" {
try std.testing.expectEqual(.done, pane.sel[sel_slot].state);
}
-test "a corner drag's two axes clamp independently" {
- // a 100-wide window split 50/50, and a 30-row column split 15/14 under the
- // topbar: the shape windowops.snap drives
- const lx: u16 = 0;
- const lw: u16 = 50;
- const rw: u16 = 50;
- const ay: u16 = TOPBAR_H;
- const ah: u16 = 15;
- const bh: u16 = 14;
- const row_lo: u16 = ay + BOX_H - 1;
- const row_hi: u16 = ay + ah + bh - (BOX_H + 1);
-
- // each axis alone, at both walls
- try std.testing.expectEqual(@as(u16, config.MINW), clampBorderCol(lx, lw, rw, 0));
- try std.testing.expectEqual(@as(u16, 100 - config.MINW), clampBorderCol(lx, lw, rw, 999));
- try std.testing.expectEqual(row_lo, clampBorderRow(ay, ah, bh, 0));
- try std.testing.expectEqual(row_hi, clampBorderRow(ay, ah, bh, 999));
-
- // THE corner property: drag off the right edge while staying mid-height —
- // x sits at its wall, y still tracks the mouse row exactly
- try std.testing.expectEqual(@as(u16, 100 - config.MINW), clampBorderCol(lx, lw, rw, 999));
- try std.testing.expectEqual(@as(u16, 12), clampBorderRow(ay, ah, bh, 12));
- // and the mirror: pinned at the bottom, x still free
- try std.testing.expectEqual(row_hi, clampBorderRow(ay, ah, bh, 999));
- try std.testing.expectEqual(@as(u16, 40), clampBorderCol(lx, lw, rw, 40));
- // both pinned at once is just both walls, not a stuck gesture
- try std.testing.expectEqual(@as(u16, config.MINW), clampBorderCol(lx, lw, rw, 0));
- try std.testing.expectEqual(row_hi, clampBorderRow(ay, ah, bh, 999));
-
- // degenerate pairs pass through untouched, each on its own terms: a pane
- // pair with no room stays draggable even when the column pair has room
- try std.testing.expectEqual(@as(u16, 7), clampBorderCol(0, 5, 5, 7));
- try std.testing.expectEqual(@as(u16, 40), clampBorderCol(lx, lw, rw, 40));
- try std.testing.expectEqual(@as(u16, 9), clampBorderRow(TOPBAR_H, 1, 0, 9));
-}
-
-test "a v-handle press at the RIGHT column's seam drags both boundaries" {
- const p = try cornerFixture(std.testing.allocator);
- defer p.deinit();
- try std.testing.expectEqual(@as(usize, 2), p.view().cols[1].n);
-
- const handle = p.view().col_x[0] + p.view().col_w[0] - 1;
- const right_seam = nudgeRightSeam(p, 3);
- try std.testing.expect(right_seam != seamRowOf(p, 0, 0));
-
- const w0 = p.view().cols[0].weight;
- const v_left = p.panes[p.view().cols[0].panes[0]].?.vweight;
- const v_right = p.panes[p.view().cols[1].panes[0]].?.vweight;
-
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = right_seam } });
- try std.testing.expect(p.view().drag == .border_v);
- const corner = p.view().drag.border_v.corner orelse return error.NoCorner;
- try std.testing.expectEqual(@as(usize, 1), corner.col);
- try std.testing.expectEqual(@as(usize, 0), corner.idx);
-
- p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = handle + 8, .row = right_seam - 4 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle + 8, .row = right_seam - 4 } });
- p.sync();
-
- // both halves committed: the column pair widened, and the RIGHT column's
- // pane pair reweighted — while the left column's panes stayed put
- try std.testing.expect(p.view().cols[0].weight > w0);
- try std.testing.expect(p.panes[p.view().cols[1].panes[0]].?.vweight != v_right);
- try std.testing.expectEqual(v_left, p.panes[p.view().cols[0].panes[0]].?.vweight);
-}
-
-test "a tie row still moves the LEFT column's pane pair only" {
- const p = try cornerFixture(std.testing.allocator);
- defer p.deinit();
-
- // put column 1's seam exactly on column 0's, the row the eye reads as one
- // line across the whole window
- const left_seam = seamRowOf(p, 0, 0);
- _ = nudgeRightSeam(p, @as(i32, left_seam) - @as(i32, seamRowOf(p, 1, 0)));
- try std.testing.expectEqual(left_seam, seamRowOf(p, 1, 0));
-
- const handle = p.view().col_x[0] + p.view().col_w[0] - 1;
- const v_left = p.panes[p.view().cols[0].panes[0]].?.vweight;
- const v_right = p.panes[p.view().cols[1].panes[0]].?.vweight;
-
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = left_seam } });
- const corner = p.view().drag.border_v.corner orelse return error.NoCorner;
- try std.testing.expectEqual(@as(usize, 0), corner.col);
-
- p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = handle, .row = left_seam - 4 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle, .row = left_seam - 4 } });
- p.sync();
- try std.testing.expect(p.panes[p.view().cols[0].panes[0]].?.vweight != v_left);
- try std.testing.expectEqual(v_right, p.panes[p.view().cols[1].panes[0]].?.vweight);
-}
-
-test "a v-handle press at nobody's seam is still a plain edge drag" {
- const p = try cornerFixture(std.testing.allocator);
- defer p.deinit();
- const right_seam = nudgeRightSeam(p, 3);
- const left_seam = seamRowOf(p, 0, 0);
-
- const handle = p.view().col_x[0] + p.view().col_w[0] - 1;
- var row: u16 = TOPBAR_H + 1;
- while (row == left_seam or row == right_seam) row += 1;
-
- const w0 = p.view().cols[0].weight;
- const v_left = p.panes[p.view().cols[0].panes[0]].?.vweight;
- const v_right = p.panes[p.view().cols[1].panes[0]].?.vweight;
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = row } });
- try std.testing.expect(p.view().drag == .border_v);
- try std.testing.expect(p.view().drag.border_v.corner == null);
- p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = handle + 8, .row = row + 5 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle + 8, .row = row + 5 } });
- p.sync();
- // exactly ONE boundary moved
- try std.testing.expect(p.view().cols[0].weight > w0);
- try std.testing.expectEqual(v_left, p.panes[p.view().cols[0].panes[0]].?.vweight);
- try std.testing.expectEqual(v_right, p.panes[p.view().cols[1].panes[0]].?.vweight);
-}
-
-test "a RIGHT-column corner's two axes clamp independently" {
- const p = try cornerFixture(std.testing.allocator);
- defer p.deinit();
- const right_seam = nudgeRightSeam(p, 3);
- const handle = p.view().col_x[0] + p.view().col_w[0] - 1;
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = handle, .row = right_seam } });
- try std.testing.expectEqual(@as(usize, 1), (p.view().drag.border_v.corner orelse return error.NoCorner).col);
-
- // off the right edge at mid-height: x parks at its MINW wall, y is the mouse
- p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = 999, .row = right_seam } });
- try std.testing.expectEqual(@as(u16, 100 - config.MINW), p.view().drag.border_v.cur_x);
- try std.testing.expectEqual(right_seam, p.view().drag.border_v.cur_y);
-
- // and the mirror: below the bottom at mid-width. y parks, x tracks again
- p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = handle, .row = 999 } });
- try std.testing.expectEqual(handle, p.view().drag.border_v.cur_x);
- const a = p.view().rects[p.view().cols[1].panes[0]];
- const b = p.view().rects[p.view().cols[1].panes[1]];
- try std.testing.expectEqual(clampBorderRow(a.y, a.h, b.h, 999), p.view().drag.border_v.cur_y);
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle, .row = 999 } });
-}
-
test "mouse thumb buttons navigate once and clear selection gestures" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12 });
defer p.deinit();
diff --git a/src/surface.zig b/src/surface.zig
index 46b6c664..c0f352ee 100644
--- a/src/surface.zig
+++ b/src/surface.zig
@@ -204,8 +204,6 @@ pub const Region = struct {
/// A column below the workspace tag, its bar and panes: its left
/// edge is the spine a pixel shell rules down it.
column,
- /// A drag's guide or a seam's hover hint, drawn over the panes.
- guide,
/// The debug stats box, drawn over the panes.
debug,
};
@@ -243,15 +241,9 @@ pub const Region = struct {
/// it shows, in pixels. Its placements are laid at the whole pixel; a
/// pixel frontend draws them the fraction higher.
scroll_px: f64 = 0,
- /// Cells the column-move rail takes off the right edge while it runs
- /// there: layers and pixel shells stop short of them, the grid does not.
- clip: u16 = 0,
};
-/// Guides a frame can draw: a run of a column-move rail per pane it skips
-/// the tags of, and a handful of border and hover dashes.
-pub const MAX_GUIDES = MAX_PANES + 4;
-pub const MAX_REGIONS = 1 + MAX_PANES * (4 + panes.Pane.Notices.max) + pardes.MAX_COLS * 3 + 1 + MAX_GUIDES + 1;
+pub const MAX_REGIONS = 1 + MAX_PANES * (4 + panes.Pane.Notices.max) + pardes.MAX_COLS * 3 + 1 + 1;
/// The colours a pixel shell draws its chrome in (rules, rails, grips, the
/// tag underlay), resolved by the core each frame, so a frontend attached
@@ -471,14 +463,6 @@ pub const Surface = struct {
while (xx < x + w) : (xx += 1) s.at(xx, yy).* = .{};
}
}
-
- /// swap ONLY the glyph, keeping the cell's colors — the resize-handle hint
- pub fn overlayDash(s: *Surface, x: u16, y: u16, glyph: []const u8) void {
- const c = s.at(x, y);
- @memcpy(c.text[0..glyph.len], glyph);
- c.len = @intCast(glyph.len);
- c.default = false;
- }
};
test "cell visual equality ignores dead grapheme tail bytes" {
diff --git a/src/syntax.zig b/src/syntax.zig
index 2526e113..8533aaa9 100644
--- a/src/syntax.zig
+++ b/src/syntax.zig
@@ -22,7 +22,7 @@ const ts_queries = if (enabled) @import("ts_queries") else struct {};
const LanguageFn = *const fn () callconv(.c) *const ts.Language;
-pub const Syn = enum(u8) { none, keyword, string, number, comment };
+pub const Syn = grammar_manifest.Syn;
/// A query compiled when first asked for: "" for none, null when it fails.
const Lazy = struct { src: []const u8 = "", query: ?*ts.Query = null, failed: bool = false };
@@ -55,81 +55,6 @@ fn specCount() comptime_int {
}
return count;
}
-const typst_supplement =
- \\
- \\(call item: (ident) @keyword)
- \\(call item: (field field: (ident) @keyword))
- \\"#" @keyword
- \\
-;
-
-fn querySrc(comptime g: grammar_manifest.Grammar) []const u8 {
- const base = @field(ts_queries, g.name ++ "_highlights");
- const source = if (comptime std.mem.eql(u8, g.name, "typst")) base ++ typst_supplement else base;
- return comptime colorQuery(source);
-}
-
-fn colorQuery(comptime source: []const u8) []const u8 {
- @setEvalBranchQuota(2_000_000);
- var result: [source.len]u8 = undefined;
- var written: usize = 0;
- var at: usize = 0;
- while (at < source.len) {
- while (at < source.len) {
- if (std.ascii.isWhitespace(source[at])) {
- at += 1;
- } else if (source[at] == ';') {
- while (at < source.len and source[at] != '\n') at += 1;
- } else break;
- }
- const begin = at;
- var depth: usize = 0;
- var colored = false;
- var complete = false;
- while (at < source.len) {
- const byte = source[at];
- if (complete and (byte == '(' or byte == '[' or byte == '"')) break;
- if (byte == ';') {
- while (at < source.len and source[at] != '\n') at += 1;
- continue;
- }
- if (byte == '"') {
- at += 1;
- while (at < source.len) : (at += 1) {
- if (source[at] == '\\') {
- at += 1;
- } else if (source[at] == '"') {
- at += 1;
- break;
- }
- }
- if (depth == 0) complete = true;
- continue;
- }
- if (byte == '(' or byte == '[') depth += 1;
- if (byte == ')' or byte == ']') {
- depth -= 1;
- if (depth == 0) complete = true;
- }
- if (byte == '@') {
- const name = at + 1;
- at = name;
- while (at < source.len and (std.ascii.isAlphanumeric(source[at]) or
- source[at] == '_' or source[at] == '.' or source[at] == '-')) at += 1;
- colored = colored or synFor(source[name..at]) != .none;
- continue;
- }
- at += 1;
- }
- if (colored) {
- @memcpy(result[written..][0 .. at - begin], source[begin..at]);
- written += at - begin;
- }
- }
- const filtered = result[0..written].*;
- return &filtered;
-}
-
fn initSpecs() [specCount()]Spec {
var out: [specCount()]Spec = undefined;
var i = 0;
@@ -139,7 +64,7 @@ fn initSpecs() [specCount()]Spec {
.name = g.name,
.exts = g.exts,
.language = @extern(LanguageFn, .{ .name = "tree_sitter_" ++ g.name }),
- .query_src = querySrc(g),
+ .query_src = @field(ts_queries, g.name ++ "_highlights"),
.objects = .{ .src = @field(ts_queries, g.name ++ "_textobjects") },
.indents = .{ .src = @field(ts_queries, g.name ++ "_indents") },
};
@@ -219,7 +144,7 @@ fn ensure(spec: *Spec) !Selected {
const capture_styles = spec.capture_styles[0..query.captureCount()];
for (capture_styles, 0..) |*style, id| {
const name = query.captureNameForId(@intCast(id)) orelse "";
- style.* = @backingInt(synFor(name));
+ style.* = @backingInt(grammar_manifest.synFor(name));
if (style.* == 0) query.disableCapture(name);
}
const parser = ts.Parser.create();
@@ -260,34 +185,6 @@ fn runQuery(styles: []u8, sel: Selected, tree: *ts.Tree, base: usize) void {
}
}
-fn synFor(name: []const u8) Syn {
- for ([_]struct { []const u8, Syn }{
- .{ "comment", .comment },
- .{ "string", .string },
- .{ "character", .string },
- .{ "number", .number },
- .{ "numeric", .number },
- .{ "float", .number },
- .{ "boolean", .number },
- .{ "keyword", .keyword },
- .{ "include", .keyword },
- .{ "conditional", .keyword },
- .{ "repeat", .keyword },
- .{ "title", .keyword },
- .{ "uri", .string },
- .{ "reference", .number },
- .{ "heading", .keyword },
- .{ "strong", .comment },
- .{ "bold", .comment },
- .{ "emphasis", .number },
- .{ "italic", .number },
- .{ "literal", .string },
- .{ "raw", .string },
- }) |m| {
- if (std.mem.indexOf(u8, name, m[0]) != null) return m[1];
- }
- return .none;
-}
pub fn highlightFileRange(gpa: std.mem.Allocator, path: []const u8, content: []const u8, start_raw: usize, end_raw: usize) ![]u8 {
const zone = tracy.zone(@src(), "highlightFileRange");
defer zone.end();
@@ -1909,8 +1806,7 @@ test "syntax query filtering preserves upstream colors" {
inline for (grammar_manifest.all) |grammar| {
if (comptime grammarSelected(grammar)) {
const selected = (try forLang(grammar.name)).?;
- const raw_source = @field(ts_queries, grammar.name ++ "_highlights") ++
- (if (comptime std.mem.eql(u8, grammar.name, "typst")) typst_supplement else "");
+ const raw_source = @field(ts_queries, grammar.name ++ "_highlights_unfiltered");
var error_offset: u32 = 0;
const raw_query = try ts.Query.create(selected.lang, raw_source, &error_offset);
defer raw_query.destroy();
@@ -1918,7 +1814,7 @@ test "syntax query filtering preserves upstream colors" {
reference.query = raw_query;
reference.capture_styles = try std.testing.allocator.alloc(u8, raw_query.captureCount());
defer std.testing.allocator.free(reference.capture_styles);
- for (reference.capture_styles, 0..) |*style, id| style.* = @backingInt(synFor(raw_query.captureNameForId(@intCast(id)) orelse ""));
+ for (reference.capture_styles, 0..) |*style, id| style.* = @backingInt(grammar_manifest.synFor(raw_query.captureNameForId(@intCast(id)) orelse ""));
const tree = selected.parser.parseString(source, null) orelse return error.ParseFailed;
defer tree.destroy();
var expected: [source.len]u8 = @splat(0);