diff options
Diffstat (limited to 'src/Buffer.zig')
| -rw-r--r-- | src/Buffer.zig | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/Buffer.zig b/src/Buffer.zig index 555ad1d..ce27d95 100644 --- a/src/Buffer.zig +++ b/src/Buffer.zig | |||
| @@ -25,7 +25,7 @@ rx: usize, | |||
| 25 | rowoff: usize, | 25 | rowoff: usize, |
| 26 | coloff: usize, | 26 | coloff: usize, |
| 27 | 27 | ||
| 28 | dirty: bool, | 28 | edited: bool, |
| 29 | 29 | ||
| 30 | config: Config, | 30 | config: Config, |
| 31 | syntax: ?Syntax, | 31 | syntax: ?Syntax, |
| @@ -52,7 +52,7 @@ pub fn init(allocator: Allocator, name: []const u8) !Buffer { | |||
| 52 | .rowoff = 0, | 52 | .rowoff = 0, |
| 53 | .coloff = 0, | 53 | .coloff = 0, |
| 54 | 54 | ||
| 55 | .dirty = false, | 55 | .edited = false, |
| 56 | 56 | ||
| 57 | .config = config, | 57 | .config = config, |
| 58 | .syntax = null, | 58 | .syntax = null, |
| @@ -161,14 +161,14 @@ pub fn deleteChar(self: *Buffer) !void { | |||
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | if (self.cx < self.rows.items[self.cy].data.items.len) { | 163 | if (self.cx < self.rows.items[self.cy].data.items.len) { |
| 164 | self.dirty = true; | 164 | self.edited = true; |
| 165 | try self.rows.items[self.cy].deleteChar(self, self.cx); | 165 | try self.rows.items[self.cy].deleteChar(self, self.cx); |
| 166 | } else { | 166 | } else { |
| 167 | if (self.cy == self.rows.items.len - 1) { | 167 | if (self.cy == self.rows.items.len - 1) { |
| 168 | return; | 168 | return; |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | self.dirty = true; | 171 | self.edited = true; |
| 172 | try self.rows.items[self.cy].appendString(self, self.rows.items[self.cy + 1].data.items); | 172 | try self.rows.items[self.cy].appendString(self, self.rows.items[self.cy + 1].data.items); |
| 173 | self.deleteRow(self.cy + 1); | 173 | self.deleteRow(self.cy + 1); |
| 174 | } | 174 | } |
| @@ -179,7 +179,7 @@ pub fn deleteAllRows(self: *Buffer) void { | |||
| 179 | return; | 179 | return; |
| 180 | } | 180 | } |
| 181 | 181 | ||
| 182 | self.dirty = true; | 182 | self.edited = true; |
| 183 | while (self.rows.popOrNull()) |row| { | 183 | while (self.rows.popOrNull()) |row| { |
| 184 | row.deinit(); | 184 | row.deinit(); |
| 185 | } | 185 | } |
| @@ -201,7 +201,7 @@ pub fn deleteRow(self: *Buffer, at: usize) void { | |||
| 201 | return; | 201 | return; |
| 202 | } | 202 | } |
| 203 | 203 | ||
| 204 | self.dirty = true; | 204 | self.edited = true; |
| 205 | 205 | ||
| 206 | self.rows.orderedRemove(at).deinit(); | 206 | self.rows.orderedRemove(at).deinit(); |
| 207 | var i = at; | 207 | var i = at; |
| @@ -291,7 +291,7 @@ pub fn drawStatusBar(self: Buffer, writer: anytype, screencols: usize) !void { | |||
| 291 | try self.allocator.dupe(u8, self.short_name); | 291 | try self.allocator.dupe(u8, self.short_name); |
| 292 | defer self.allocator.free(name); | 292 | defer self.allocator.free(name); |
| 293 | 293 | ||
| 294 | const modified = if (self.dirty) | 294 | const modified = if (self.isDirty()) |
| 295 | @as([]const u8, " (modified)") | 295 | @as([]const u8, " (modified)") |
| 296 | else | 296 | else |
| 297 | @as([]const u8, ""); | 297 | @as([]const u8, ""); |
| @@ -437,7 +437,7 @@ pub fn insertChar(self: *Buffer, char: u8) !void { | |||
| 437 | try self.rows.items[self.cy].insertChar(self, self.cx, char); | 437 | try self.rows.items[self.cy].insertChar(self, self.cx, char); |
| 438 | self.cx += 1; | 438 | self.cx += 1; |
| 439 | 439 | ||
| 440 | self.dirty = true; | 440 | self.edited = true; |
| 441 | } | 441 | } |
| 442 | 442 | ||
| 443 | pub fn insertNChars(self: *Buffer, char: u8, count: usize) !void { | 443 | pub fn insertNChars(self: *Buffer, char: u8, count: usize) !void { |
| @@ -448,7 +448,7 @@ pub fn insertNChars(self: *Buffer, char: u8, count: usize) !void { | |||
| 448 | } | 448 | } |
| 449 | 449 | ||
| 450 | pub fn insertNewline(self: *Buffer) !void { | 450 | pub fn insertNewline(self: *Buffer) !void { |
| 451 | self.dirty = true; | 451 | self.edited = true; |
| 452 | 452 | ||
| 453 | if (self.cx == 0) { | 453 | if (self.cx == 0) { |
| 454 | try self.insertRow(self.cy, ""); | 454 | try self.insertRow(self.cy, ""); |
| @@ -484,7 +484,17 @@ pub fn insertRow(self: *Buffer, at: usize, data: []const u8) !void { | |||
| 484 | } | 484 | } |
| 485 | try self.rows.items[at].update(self); | 485 | try self.rows.items[at].update(self); |
| 486 | 486 | ||
| 487 | self.dirty = true; | 487 | self.edited = true; |
| 488 | } | ||
| 489 | |||
| 490 | pub fn isDirty(self: Buffer) bool { | ||
| 491 | if (self.short_name.len > 0) { | ||
| 492 | if (self.short_name[0] == '*' and self.short_name[self.short_name.len-1] == '*') { | ||
| 493 | return false; | ||
| 494 | } | ||
| 495 | } | ||
| 496 | |||
| 497 | return self.edited; | ||
| 488 | } | 498 | } |
| 489 | 499 | ||
| 490 | pub fn killLine(self: *Buffer) !void { | 500 | pub fn killLine(self: *Buffer) !void { |
| @@ -496,7 +506,7 @@ pub fn killLine(self: *Buffer) !void { | |||
| 496 | if (self.cx == row.data.items.len) { | 506 | if (self.cx == row.data.items.len) { |
| 497 | return self.deleteChar(); | 507 | return self.deleteChar(); |
| 498 | } else { | 508 | } else { |
| 499 | self.dirty = true; | 509 | self.edited = true; |
| 500 | try row.data.resize(self.cx); | 510 | try row.data.resize(self.cx); |
| 501 | return row.update(self); | 511 | return row.update(self); |
| 502 | } | 512 | } |
| @@ -672,7 +682,7 @@ pub fn save(self: *Buffer, editor: *Editor) !void { | |||
| 672 | }; | 682 | }; |
| 673 | 683 | ||
| 674 | try editor.setStatusMessage("Saved to '{s}'", .{file_path}); | 684 | try editor.setStatusMessage("Saved to '{s}'", .{file_path}); |
| 675 | self.dirty = false; | 685 | self.edited = false; |
| 676 | } | 686 | } |
| 677 | 687 | ||
| 678 | pub fn scroll(self: *Buffer, screenrows: usize, screencols: usize) void { | 688 | pub fn scroll(self: *Buffer, screenrows: usize, screencols: usize) void { |