Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 2c56bda

Browse files
committed
Fix notification of display layers and decoration layers when reloading
1 parent 8d4d8a0 commit 2c56bda

File tree

3 files changed

+48
-12
lines changed

3 files changed

+48
-12
lines changed

spec/text-buffer-io-spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,27 @@ describe('TextBuffer IO', () => {
159159
})
160160
})
161161

162+
it('notifies decoration layers and display layers of the change', (done) => {
163+
fs.writeFileSync(filePath, 'abcdefghijk', 'utf8')
164+
165+
const events = []
166+
167+
const displayLayer = buffer.addDisplayLayer()
168+
displayLayer.onDidChangeSync((event) => events.push(['display-layer', event]))
169+
170+
buffer.registerTextDecorationLayer({
171+
bufferDidChange ({oldRange, newRange}) { events.push(['decoration-layer', {oldRange, newRange}]) }
172+
})
173+
174+
buffer.reload().then(() => {
175+
expect(events).toEqual([
176+
['decoration-layer', {oldRange: Range(Point(0, 7), Point(0, 7)), newRange: Range(Point(0, 7), Point(0, 11))}],
177+
['display-layer', [{start: Point(0, 0), oldExtent: Point(1, 0), newExtent: Point(1, 0)}]]
178+
])
179+
done()
180+
})
181+
})
182+
162183
it('clears the contents of the buffer when the file doesn\t exist', (done) => {
163184
buffer.delete([[0, 0], [0, 2]])
164185

src/helpers.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,36 @@ class TextChange {
105105
}
106106

107107
Object.defineProperty(TextChange.prototype, 'start', {
108-
get: function () {
109-
return this.newRange.start
110-
},
108+
get () { return this.newRange.start },
109+
enumerable: false
110+
})
111+
112+
Object.defineProperty(TextChange.prototype, 'oldStart', {
113+
get () { return this.oldRange.start },
114+
enumerable: false
115+
})
116+
117+
Object.defineProperty(TextChange.prototype, 'newStart', {
118+
get () { return this.newRange.start },
119+
enumerable: false
120+
})
121+
122+
Object.defineProperty(TextChange.prototype, 'oldEnd', {
123+
get () { return this.oldRange.end },
124+
enumerable: false
125+
})
126+
127+
Object.defineProperty(TextChange.prototype, 'newEnd', {
128+
get () { return this.newRange.end },
111129
enumerable: false
112130
})
113131

114132
Object.defineProperty(TextChange.prototype, 'oldExtent', {
115-
get: function () {
116-
return this.oldRange.getExtent()
117-
},
133+
get () { return this.oldRange.getExtent() },
118134
enumerable: false
119135
})
120136

121137
Object.defineProperty(TextChange.prototype, 'newExtent', {
122-
get: function () {
123-
return this.newRange.getExtent()
124-
},
138+
get () { return this.newRange.getExtent() },
125139
enumerable: false
126140
})

src/text-buffer.coffee

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class ChangeEvent
2424
constructor: (buffer, changes) ->
2525
@changes = changes
2626

27-
start = changes[0].oldRange.start
28-
oldEnd = changes[changes.length - 1].oldRange.end
29-
newEnd = changes[changes.length - 1].newRange.end
27+
start = changes[0].oldStart
28+
oldEnd = changes[changes.length - 1].oldEnd
29+
newEnd = changes[changes.length - 1].newEnd
3030
@oldRange = new Range(start, oldEnd).freeze()
3131
@newRange = new Range(start, newEnd).freeze()
3232

@@ -1792,6 +1792,7 @@ class TextBuffer
17921792
markersSnapshot = @createMarkerSnapshot()
17931793
@historyProvider.groupChangesSinceCheckpoint(checkpoint, {markers: markersSnapshot, deleteCheckpoint: true})
17941794

1795+
@emitDidChangeEvent(new ChangeEvent(this, changes))
17951796
@emitDidChangeTextEvent()
17961797
@emitMarkerChangeEvents(markersSnapshot)
17971798
@emitModifiedStatusChanged(@isModified())

0 commit comments

Comments
 (0)