Skip to content

Commit

Permalink
fix: regression when adding text on spaces, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
nedpals committed Nov 28, 2023
1 parent 172e11c commit 76c02d4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions source.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ func applyOperation(op string, doc *EditableDocument, changeset Changeset) Posit
insertDiff := applyInsertOperation(doc, Changeset{
NewText: changeset.NewText,
Id: changeset.Id,
StartPos: changeset.StartPos.Add(deleteDiff),
EndPos: changeset.StartPos.Add(deleteDiff),
StartPos: changeset.StartPos,
EndPos: changeset.StartPos,
})

// combine the diff to create an interesecting diff
Expand Down
29 changes: 29 additions & 0 deletions source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,35 @@ func TestEditableDocument(t *testing.T) {
}
})

t.Run("EditableDocument.ReplaceWithPadding", func(t *testing.T) {
doc, err := ParseDocument("test", strings.NewReader(` hello = 1`), parser, testLanguage, nil)
if err != nil {
t.Error(err)
} else if doc.TotalLines() < 1 {
t.Errorf("Expected document to have at least 1 line, got %d", doc.TotalLines())
}

editableDoc := doc.Editable()

editableDoc.Apply(Changeset{
NewText: "world",
StartPos: Position{
Line: 0,
Column: 8,
Index: 8,
},
EndPos: Position{
Line: 0,
Column: 13,
Index: 13,
},
})

if editableDoc.String() != " world = 1" {
t.Errorf("Expected contents to be \" world = 1\", got %q", editableDoc.String())
}
})

t.Run("EditableDocument.ReplaceMultipleLines", func(t *testing.T) {
editableDoc := doc.Editable()

Expand Down

0 comments on commit 76c02d4

Please sign in to comment.