summaryrefslogtreecommitdiff
path: root/core/ninep
diff options
context:
space:
mode:
Diffstat (limited to 'core/ninep')
-rw-r--r--core/ninep/pane.zig18
1 files changed, 11 insertions, 7 deletions
diff --git a/core/ninep/pane.zig b/core/ninep/pane.zig
index 2616c735..093a9223 100644
--- a/core/ninep/pane.zig
+++ b/core/ninep/pane.zig
@@ -150,9 +150,11 @@ pub const State = struct {
/// buffer less its read-only lines, the `Changes` layer's, which are no
/// text of the file's). Every address, `dot` and range over 9P is of this
/// text (`fileDot`); a write to it is the file's (`spliceBody`).
-pub fn bodyOf(p: *Pardes, pane: *const Pane) []const u8 {
- if (pane.file) |*f| return panes.File.fileText(f, p.scratch.allocator()) catch "";
- return "";
+pub inline fn bodyOf(p: *Pardes, pane: *const Pane) []const u8 {
+ const f = if (pane.file) |*file| file else return "";
+ // No layer shown: the buffer is the file's text (a length test).
+ if (f.layer.lines.len == 0) return f.content;
+ return panes.File.fileText(f, p.scratch.allocator()) catch "";
}
/// The buffer the editor edits (with the layer's lines): what the
@@ -165,7 +167,7 @@ fn bufferOf(pane: *const Pane) []const u8 {
/// Whether 9P reads of the pane are a copy of its file's text, not a
/// region of its buffer (`fsPayload` reads the buffer).
fn layered(pane: *const Pane) bool {
- return if (pane.file) |*f| f.read_only.len > 0 else false;
+ return if (pane.file) |*f| f.layer.lines.len > 0 else false;
}
pub fn fileOf(pane: *Pane) ?*panes.File.State {
@@ -301,20 +303,22 @@ pub fn showOffset(tab: u16, pane: *Pane, off: usize) void {
/// `dotOf` in the file's text's offsets, as 9P serves it (`bodyOf`): a dot
/// in a read-only line is after the file line above it.
-pub fn fileDot(pane: *Pane) State.Range {
+pub inline fn fileDot(pane: *Pane) State.Range {
const d = dotOf(pane);
const f = if (pane.file) |*file| file else return d;
+ if (f.layer.lines.len == 0) return d;
return .{ .q0 = clip(panes.File.fileOffset(f, d.q0)), .q1 = clip(panes.File.fileOffset(f, d.q1)) };
}
/// `setDot` from the file's text's offsets (`fileDot`).
-pub fn setFileDot(tab: u16, pane: *Pane, r: State.Range) void {
+pub inline fn setFileDot(tab: u16, pane: *Pane, r: State.Range) void {
const f = if (pane.file) |*file| file else return setDot(tab, pane, r);
+ if (f.layer.lines.len == 0) return setDot(tab, pane, r);
setDot(tab, pane, .{ .q0 = clip(panes.File.bufferOffset(f, r.q0, false)), .q1 = clip(panes.File.bufferOffset(f, r.q1, r.q1 > r.q0)) });
}
/// `showOffset` of a file's text's offset.
-pub fn showFileOffset(tab: u16, pane: *Pane, off: usize) void {
+pub inline fn showFileOffset(tab: u16, pane: *Pane, off: usize) void {
const f = if (pane.file) |*file| file else return showOffset(tab, pane, off);
showOffset(tab, pane, panes.File.bufferOffset(f, off, false));
}