Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FS-originated modifications work the same as Acme #512

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion file/observable_editable_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ func (e *ObservableEditableBuffer) notifyTagObservers(before TagStatus) {
// Mark is a forwarding function for file.Mark.
// This sets an undo point. NB: call Mark before mutating the file.
// Argument seq should be > 0 to create a valid Undo/Redo point.
// TODO(rjk): Should this update the tag?
func (e *ObservableEditableBuffer) Mark(seq int) {
e.f.Mark()
e.seq = seq
Expand Down Expand Up @@ -294,7 +295,6 @@ func (e *ObservableEditableBuffer) InsertAt(rp0 int, rs []rune) {
}

// Insert is a forwarding function for file.Insert.
// p0 is position in runes.
func (e *ObservableEditableBuffer) Insert(p0 OffsetTuple, s []byte, nr int) {
before := e.getTagStatus()
defer e.notifyTagObservers(before)
Expand Down
2 changes: 1 addition & 1 deletion wind.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,6 @@ func (w *Window) ClampAddr() {
}

func (w *Window) UpdateTag(newtagstatus file.TagStatus) {
// log.Printf("Window.UpdateTag, status %+v", newtagstatus)
// log.Printf("Window.UpdateTag, status %+v, %d", newtagstatus, global.seq)
w.setTag1()
}
25 changes: 23 additions & 2 deletions xfid.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ func xfidwrite(x *Xfid) {

// updateText writes x.fcall.Data to text buffer t and sends the 9P response.
updateText := func(t *Text) {
// log.Printf("updateText global.seq %d, seq state %s", global.seq, t.file.DebugSeqState())
r := fullrunewrite(x)
if len(r) != 0 {
w.Commit(t)
Expand All @@ -414,6 +415,13 @@ func xfidwrite(x *Xfid) {
global.seq++
t.file.Mark(global.seq)
}
// To align with how Acme works, the file on disk has not been changed
// but Edwood's in-memory store of the file would now be different from
// the backing file and also not undoable back to the backign state as
// has been programmatically modified via the filesystem API.
if t.file.Seq() == 0 && w.nomark {
t.file.Modded()
}
q, nr := t.BsInsert(q0, r, true) // TODO(flux): BsInsert returns nr?
q0 = q
t.SetSelect(t.q0, t.q1) // insert could leave it somewhere else
Expand Down Expand Up @@ -656,11 +664,24 @@ forloop:
w.limit.q0 = w.addr.q0
w.limit.q1 = w.addr.q1
case "nomark": // turn off automatic marking
// Snapshot the file state first to make sure that we do the right thing.
// But perhaps we are setting up the buffer. So if the seq is not 0, skip
// this. Are multiple undo snapshots harmful? (Perhaps this causes bugs
// with undo from the command language?)
if w.body.file.Seq() > 0 {
global.seq++
w.body.file.Mark(global.seq)
}
w.nomark = true
// Once we've nomark'ed, if seq == 0, mutations will be undoable.
// but the file will be different than disk. So mark it dirty in update.
case "mark": // mark file
w.nomark = false
// global.seq++
// w.body.file.Mark(global.seq)
// Premise is that the next undoable mutation will set an undo point.
// TODO:(rjk): Maintaining this invariant is tricky. It should be tested
// and the code in text.go should be appropriately structured to make it
// easy to reason about and to test.
// TODO(rjk): The premise is wrong. The first edit does not.
case "nomenu": // turn off automatic menu
w.filemenu = false
case "menu": // enable automatic menu
Expand Down
Loading