Add explicit job output panel
This commit is contained in:
+17
-1
@@ -144,7 +144,7 @@ pub const Session = struct {
|
||||
pub fn openFixtureAt(self: *Session, fixture: []const u8, cursor_byte: usize) !void {
|
||||
if (self.buffer) |*buffer| buffer.deinit();
|
||||
var buffer = try Buffer.openFromBytes(self.allocator, fixture);
|
||||
buffer.cursor.byte = previousBoundary(buffer.bytes.items, @min(cursor_byte, buffer.bytes.items.len));
|
||||
buffer.cursor.byte = boundaryAtOrBefore(buffer.bytes.items, @min(cursor_byte, buffer.bytes.items.len));
|
||||
buffer.refreshCell();
|
||||
self.buffer = buffer;
|
||||
}
|
||||
@@ -227,6 +227,13 @@ pub const Session = struct {
|
||||
}
|
||||
};
|
||||
|
||||
pub fn boundaryAtOrBefore(bytes: []const u8, cursor: usize) usize {
|
||||
var i = @min(cursor, bytes.len);
|
||||
if (i == bytes.len) return i;
|
||||
while (i > 0 and isContinuation(bytes[i])) : (i -= 1) {}
|
||||
return i;
|
||||
}
|
||||
|
||||
pub fn previousBoundary(bytes: []const u8, cursor: usize) usize {
|
||||
if (cursor == 0) return 0;
|
||||
var i = @min(cursor, bytes.len) - 1;
|
||||
@@ -298,6 +305,15 @@ fn isWide(cp: u21) bool {
|
||||
(cp >= 0x20000 and cp <= 0x3fffd);
|
||||
}
|
||||
|
||||
test "regular: opening a fixture at a cursor byte keeps exact utf8 boundary" {
|
||||
var session = Session.init(std.testing.allocator);
|
||||
defer session.deinit();
|
||||
|
||||
try session.openFixtureAt("one\nabcdTARGET\n", 8);
|
||||
const snap = try session.snapshot();
|
||||
try std.testing.expectEqual(@as(usize, 8), snap.cursor_byte);
|
||||
}
|
||||
|
||||
test "regular: session opens fixture and dispatches multibyte edits" {
|
||||
var session = Session.init(std.testing.allocator);
|
||||
defer session.deinit();
|
||||
|
||||
Reference in New Issue
Block a user