summaryrefslogtreecommitdiff
path: root/src/edit.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/edit.zig')
-rw-r--r--src/edit.zig23
1 files changed, 8 insertions, 15 deletions
diff --git a/src/edit.zig b/src/edit.zig
index b2909d87..466b5cdb 100644
--- a/src/edit.zig
+++ b/src/edit.zig
@@ -229,10 +229,10 @@ pub fn capturePointerSelection(p: *Pardes, pane: *Pane, slot: usize) !void {
const prefix: i32 = if (pane.file != null) panes.File.gutterWidth(pane) else 0;
for (rows, 0..) |*row, index| {
const visible = first + @as(i32, @intCast(index));
- // A stream: only the first row starts where the press was; the
- // others start after the line numbers, and all but the last run on.
+ // A stream: only the first row starts where the press was, and no
+ // row takes in the line numbers; all but the last run on.
const cols = sweepCols(gesture, visible + @as(i32, pane.tag_rows)).?;
- const left: i32 = if (cols.first) cols.lo else prefix;
+ const left: i32 = if (cols.first) @max(cols.lo, prefix) else prefix;
const right: i32 = cols.hi orelse std.math.maxInt(i32) / 2;
var source = pane.wrapAt(visible);
if (raw) source = .{ .line = panes.terminal.gridOffset(pane) + visible, .at = 0 };
@@ -241,8 +241,8 @@ pub fn capturePointerSelection(p: *Pardes, pane: *Pane, slot: usize) !void {
if (raw) next = .{ .line = source.line + 1, .at = 0 };
const end = if (next.line == source.line) @min(line.len, @as(usize, @intCast(@max(0, next.at)))) else line.len;
const start: usize = @intCast(@max(0, source.at));
- const lo = @min(end, panes.File.byteAtDisplayFrom(line, start, @intCast(@max(0, left - prefix))));
- const at = @min(end, panes.File.byteAtDisplayFrom(line, start, @intCast(@max(0, right - prefix))));
+ const lo = @min(end, panes.File.byteAtDisplayFrom(line, start, @intCast(@max(0, left - prefix - source.pad))));
+ const at = @min(end, panes.File.byteAtDisplayFrom(line, start, @intCast(@max(0, right - prefix - source.pad))));
row.* = .{
.row = source.line,
.lo = lo,
@@ -251,11 +251,6 @@ pub fn capturePointerSelection(p: *Pardes, pane: *Pane, slot: usize) !void {
.raw_terminal = raw,
.prompt_bytes = if (raw) panes.terminal.promptPrefixBytes(pane, source.line, line) else 0,
};
- const rendered = modal.lineSlice(body, @intCast(visible));
- const prefix_end = @min(rendered.len, @as(usize, @intCast(@min(prefix, right + 1))));
- const prefix_start = @min(prefix_end, @as(usize, @intCast(left)));
- row.prefix_len = @intCast(prefix_end - prefix_start);
- @memcpy(row.prefix[0..row.prefix_len], rendered[prefix_start..prefix_end]);
}
pane.next_pointer_selection += 1;
gesture.source_id = pane.next_pointer_selection;
@@ -273,7 +268,7 @@ pub fn selectionText(p: *Pardes, pane: *Pane, sl: Pane.Sel) ![]const u8 {
var total: usize = rows.len -| 1;
for (rows) |row| {
const line = pointerSourceLine(pane, terminal_lines, row.row);
- total += row.prefix_len + @min(row.hi, line.len) - @min(row.lo, line.len);
+ total += @min(row.hi, line.len) - @min(row.lo, line.len);
}
const result = try arena.alloc(u8, total);
var at: usize = 0;
@@ -282,8 +277,6 @@ pub fn selectionText(p: *Pardes, pane: *Pane, sl: Pane.Sel) ![]const u8 {
result[at] = '\n';
at += 1;
}
- @memcpy(result[at..][0..row.prefix_len], row.prefix[0..row.prefix_len]);
- at += row.prefix_len;
const line = pointerSourceLine(pane, terminal_lines, row.row);
const bytes = line[@min(row.lo, line.len)..@min(row.hi, line.len)];
@memcpy(result[at..][0..bytes.len], bytes);
@@ -307,9 +300,9 @@ pub fn selectionText(p: *Pardes, pane: *Pane, sl: Pane.Sel) ![]const u8 {
) != null;
if (!first and !soft) try out.append(arena, '\n');
first = false;
- // Past the first row a body row starts after its line numbers.
+ // A body row starts after its line numbers, wherever the press was.
const gutter: i32 = if (pane.file != null and v >= pane.tag_rows) panes.File.gutterWidth(pane) else 0;
- const lo: usize = @intCast(if (cols.first) cols.lo else gutter);
+ const lo: usize = @intCast(if (cols.first) @max(cols.lo, gutter) else gutter);
const b0 = @min(panes.File.renderedLineByteCol(pane, v, line, lo), line.len);
const b1 = if (cols.hi) |hi|
@max(b0, modal.nextGrapheme(line, @min(panes.File.renderedLineByteCol(pane, v, line, @intCast(hi)), line.len)))