diff options
Diffstat (limited to 'core/Prompt.zig')
| -rw-r--r-- | core/Prompt.zig | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/core/Prompt.zig b/core/Prompt.zig index 706ff54d..c54bb228 100644 --- a/core/Prompt.zig +++ b/core/Prompt.zig @@ -1803,3 +1803,45 @@ test "C-r's history has the band's cursor like any list (UX D5): `▶` on its ne try std.testing.expectEqualStrings("self", p.registers.value('/', 0).?); try std.testing.expectEqualStrings("self", p.prompt_history.search.get(1).?); } + +test "a search's current hit under C-r's band is put in the rows the band leaves the body, the band over its top rows; one already there is not moved (UX DESIGN I1, D14)" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); + defer p.deinit(); + while (p.nextEffect()) |_| {} + var text: std.ArrayList(u8) = .empty; + defer text.deinit(std.testing.allocator); + for (1..201) |i| try text.print(std.testing.allocator, "{s} {d}\n", .{ if (i == 105 or i == 125) "the hit on row" else "a row", i }); + const pane = try p.setTestFile(text.items); + // A history whose lines all hold `hit`: C-r's band as tall as they. + for ([_][]const u8{ "/hitA", "/hitB", "/hitC", "/hitD", "/hitE", "/hitF", "/hitG", "/hitH" }) |q| { + typeKeys(p, q); + p.update(.{ .key = .{ .cp = Key.enter } }); + } + try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row); + // The view at line 100, the caret on its first row; line 105 the + // fifth row of the body, where the band will be. + panes.File.setTop(pane, .{ .line = 99 }); + pane.body.cur_row = 99; + p.sync(); + typeKeys(p, "/"); + p.update(.{ .key = .{ .cp = 'r', .ctrl = true } }); + p.sync(); + const id = p.view().active; + const rows = pane.rows; + const at = Band.covered(p, pane, id); + try std.testing.expect(at.band >= 8 and pane.view.covered > 6); + try std.testing.expectEqual(@as(usize, 99), pane.file.?.scroll); + typeKeys(p, "hit"); + p.sync(); + // The hit, line 105, under the band: in the body's visible rows. + try std.testing.expectEqual(@as(i32, 104), pane.body.cur_row); + const row = @as(usize, @intCast(pane.body.cur_row)) - pane.file.?.scroll; + try std.testing.expect(row >= pane.view.covered and row < rows); + try std.testing.expectEqual(rows, pane.rows); + // The next keys keep the hit where it is: it is visible. + const top = pane.file.?.scroll; + typeKeys(p, " on"); + p.sync(); + try std.testing.expectEqual(@as(i32, 104), pane.body.cur_row); + try std.testing.expectEqual(top, pane.file.?.scroll); +} |
