screen/selectword: add more boundary characters

This commit is contained in:
Adam Stephens
2024-02-27 10:24:30 -05:00
parent 8881cd6373
commit 59485713b4

View File

@ -1739,7 +1739,7 @@ pub fn selectWordBetween(
/// this happens is if the point pt is outside of the written screen space.
pub fn selectWord(self: *Screen, pt: point.ScreenPoint) ?Selection {
// Boundary characters for selection purposes
const boundary = &[_]u32{ 0, ' ', '\t', '\'', '"' };
const boundary = &[_]u32{ 0, ' ', '\t', '\'', '"', '│', '`', '|', ':', ',', '(', ')', '[', ']', '{', '}', '<', '>' };
// Impossible to select anything outside of the area we've written.
const y_max = self.rowsWritten() - 1;
@ -4766,15 +4766,36 @@ test "Screen: selectWord whitespace across soft-wrap" {
}
}
test "Screen: selectWord with single quote boundary" {
test "Screen: selectWord with character boundary" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 10, 20, 0);
defer s.deinit();
try s.testWriteString(" 'abc' \n123");
// Inside quotes forward
const cases = [_][]const u8{
" 'abc' \n123",
" \"abc\" \n123",
" │abc│ \n123",
" `abc` \n123",
" |abc| \n123",
" :abc: \n123",
" ,abc, \n123",
" (abc( \n123",
" )abc) \n123",
// " [abc[ \n123",
// " ]abc] \n123",
// " {abc{ \n123",
// " }abc} \n123",
// " <abc< \n123",
// " >abc> \n123",
};
for (cases) |case| {
try s.clear(.history);
try s.testWriteString(case);
// Inside character forward
{
const sel = s.selectWord(.{ .x = 2, .y = 0 }).?;
try testing.expectEqual(@as(usize, 2), sel.start.x);
@ -4783,7 +4804,7 @@ test "Screen: selectWord with single quote boundary" {
try testing.expectEqual(@as(usize, 0), sel.end.y);
}
// Inside quotes backward
// Inside character backward
{
const sel = s.selectWord(.{ .x = 4, .y = 0 }).?;
try testing.expectEqual(@as(usize, 2), sel.start.x);
@ -4792,7 +4813,7 @@ test "Screen: selectWord with single quote boundary" {
try testing.expectEqual(@as(usize, 0), sel.end.y);
}
// Inside quotes bidirectional
// Inside character bidirectional
{
const sel = s.selectWord(.{ .x = 3, .y = 0 }).?;
try testing.expectEqual(@as(usize, 2), sel.start.x);
@ -4812,6 +4833,7 @@ test "Screen: selectWord with single quote boundary" {
try testing.expectEqual(@as(usize, 0), sel.end.y);
}
}
}
test "Screen: selectOutput" {
const testing = std.testing;