~torresjrjr/public-inbox

ed: fix buffermodified logic v3 APPLIED

Curtis Arthaud: 1
 fix buffermodified logic

 3 files changed, 6 insertions(+), 12 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~torresjrjr/public-inbox/patches/50266/mbox | git am -3
Learn more about email & git

[PATCH ed v3] fix buffermodified logic Export this patch

Signed-off-by: Curtis Arthaud <uku82@gmx.fr>
---
 buffer.ha  | 15 ++++-----------
 command.ha |  2 +-
 file.ha    |  1 +
 3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/buffer.ha b/buffer.ha
index 196afa6..a32216f 100644
--- a/buffer.ha
@@ -11,7 +11,6 @@ type Buffer = struct{
	hist: []ChangeSeq,
	cursor: size,
	modified: bool,
	written: bool,
	redolastchange: bool,
};

@@ -34,8 +33,7 @@ fn buf_insert(buf: *Buffer, n: size, ls: *Line...) void = {

	insert(buf.lines[n], ls...);

	if (buf.written)
		buf.modified = true;
	buf.modified = true;

	hist_append(buf, (n, len(ls)): Addition);

@@ -47,8 +45,7 @@ fn buf_deleteall(buf: *Buffer) void = {
		append(buf.trash, buf.lines[1..]...);
		delete(buf.lines[1..]);
	};
	if (buf.written)
		buf.modified = true;
	buf.modified = true;
};

fn buf_delete(buf: *Buffer, a: size, b: size) void = {
@@ -57,8 +54,7 @@ fn buf_delete(buf: *Buffer, a: size, b: size) void = {
	append(buf.trash, buf.lines[a..b+1]...);
	delete(buf.lines[a..b+1]);

	if (buf.written)
		buf.modified = true;
	buf.modified = true;

	hist_append(buf, (a, (b + 1 - a)): Deletion);

@@ -91,8 +87,7 @@ fn buf_read(

	hist_append(buf, (n + 1, m): Addition);

	if (buf.written)
		buf.modified = true;
	buf.modified = true;

	return (sz, m);
};
@@ -102,8 +97,6 @@ fn buf_write(buf: *Buffer, dest: io::handle, a: size, b: size) (size | io::error
	for (let n = a; n <= b; n += 1)
		sz += fmt::fprintln(dest, buf.lines[n].text)?;

	buf.written = true; // TODO: move into cmd_write() ?

	return sz;
};

diff --git a/command.ha b/command.ha
index 544b027..9ba1207 100644
--- a/command.ha
+++ b/command.ha
@@ -667,7 +667,7 @@ fn cmd_write(s: *Session, cmd: *Command) (void | Error) = {
	if (!s.suppressmode)
		fmt::println(sz)!;

	if (a == 1 && b == len(s.buf.lines))
	if (a == 1 && b == len(s.buf.lines)-1)
		// the entire buffer has been written.
		s.buf.modified = false;

diff --git a/file.ha b/file.ha
index e8bab6d..c3068e7 100644
--- a/file.ha
+++ b/file.ha
@@ -20,6 +20,7 @@ fn edit(s: *Session, cmd: *Command, forced: bool) (void | Error) = {

	buf_deleteall(s.buf);
	const (sz, _) = buf_read(s.buf, rd, 0)?;
	s.buf.modified = false;

	hist_discardseq(s.buf);

--
2.44.0