Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
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
59 changes: 58 additions & 1 deletion spec/text-buffer-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe "TextBuffer", ->
buffer.setTextInRange([[0, 10], [0, 100]], "w", {undo: 'skip'})
expect(buffer.lineForRow(0)).toBe "yellow"

buffer.undo()
expect(buffer.undo()).toBe true
expect(buffer.lineForRow(0)).toBe "hellow"

describe "when the normalizeLineEndings argument is true (the default)", ->
Expand Down Expand Up @@ -493,6 +493,44 @@ describe "TextBuffer", ->
buffer.redo()
expect(buffer.getText()).toBe "heyyyyy!!\nworms\r\nhow are you doing?"

it "allows undo/redo within transactions, but not beyond the start of the containing transaction", ->
buffer.setText("")
buffer.markPosition([0, 0])

buffer.append("a")

buffer.transact ->
buffer.append("b")
buffer.transact -> buffer.append("c")
buffer.append("d")

expect(buffer.undo()).toBe true
expect(buffer.getText()).toBe "abc"

expect(buffer.undo()).toBe true
expect(buffer.getText()).toBe "ab"

expect(buffer.undo()).toBe true
expect(buffer.getText()).toBe "a"

expect(buffer.undo()).toBe false
expect(buffer.getText()).toBe "a"

expect(buffer.redo()).toBe true
expect(buffer.getText()).toBe "ab"

expect(buffer.redo()).toBe true
expect(buffer.getText()).toBe "abc"

expect(buffer.redo()).toBe true
expect(buffer.getText()).toBe "abcd"

expect(buffer.redo()).toBe false
expect(buffer.getText()).toBe "abcd"

expect(buffer.undo()).toBe true
expect(buffer.getText()).toBe "a"

describe "checkpoints", ->
beforeEach ->
buffer = new TextBuffer
Expand Down Expand Up @@ -525,6 +563,7 @@ describe "TextBuffer", ->
buffer.append("three\n")
buffer.append("four")

marker = buffer.markRange([[0, 1], [2, 3]])
result = buffer.groupChangesSinceCheckpoint(checkpoint)

expect(result).toBe true
Expand All @@ -546,6 +585,8 @@ describe "TextBuffer", ->
four
"""

expect(marker.getRange()).toEqual [[0, 1], [2, 3]]

it "skips any later checkpoints when grouping changes", ->
buffer.append("one\n")
checkpoint = buffer.createCheckpoint()
Expand Down Expand Up @@ -633,6 +674,22 @@ describe "TextBuffer", ->
expect(buffer.revertToCheckpoint(checkpoint)).toBe(false)
expect(buffer.getText()).toBe("world")

it "does not allow changes based on checkpoints outside of the current transaction", ->
checkpoint = buffer.createCheckpoint()

buffer.append("a")

buffer.transact ->
expect(buffer.revertToCheckpoint(checkpoint)).toBe false
expect(buffer.getText()).toBe "a"

buffer.append("b")

expect(buffer.groupChangesSinceCheckpoint(checkpoint)).toBe false

buffer.undo()
expect(buffer.getText()).toBe "a"

describe "::getTextInRange(range)", ->
it "returns the text in a given range", ->
buffer = new TextBuffer(text: "hello\nworld\r\nhow are you doing?")
Expand Down
Loading