mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Make EditSession.copy return a copy with a unique id and markers
We want to be able to use the copy independently, which means we should not use EditSession@deserialize to create it because that will tie us to the same selection markers.
This commit is contained in:
@@ -15,6 +15,18 @@ describe "EditSession", ->
|
||||
buffer = editSession.buffer
|
||||
lineLengths = buffer.getLines().map (line) -> line.length
|
||||
|
||||
describe ".copy()", ->
|
||||
it "returns a different edit session with the same initial state", ->
|
||||
editSession.setSelectedBufferRange([[1, 2], [3, 4]])
|
||||
editSession.addSelectionForBufferRange([[5, 6], [7, 8]], isReversed: true)
|
||||
editSession2 = editSession.copy()
|
||||
expect(editSession2.id).not.toBe editSession.id
|
||||
expect(editSession2.getSelectedBufferRanges()).toEqual editSession.getSelectedBufferRanges()
|
||||
expect(editSession2.getSelection(1).isReversed()).toBeTruthy()
|
||||
|
||||
editSession2.getSelection().setBufferRange([[2, 1], [4, 3]])
|
||||
expect(editSession2.getSelectedBufferRanges()).not.toEqual editSession.getSelectedBufferRanges()
|
||||
|
||||
describe "title", ->
|
||||
describe ".getTitle()", ->
|
||||
it "uses the basename of the buffer's path as its title, or 'untitled' if the path is undefined", ->
|
||||
|
||||
@@ -117,9 +117,18 @@ class EditSession
|
||||
|
||||
getState: -> @serialize()
|
||||
|
||||
# Creates a copy of the current {EditSession}.Returns an identical `EditSession`.
|
||||
# Creates an {EditSession} with the same initial state
|
||||
copy: ->
|
||||
EditSession.deserialize(@serialize())
|
||||
tabLength = @getTabLength()
|
||||
copy = new EditSession({@buffer, tabLength, @softTabs, @softWrap})
|
||||
copy.setScrollTop(@getScrollTop())
|
||||
copy.setScrollLeft(@getScrollLeft())
|
||||
for selection, i in @getSelections()
|
||||
if i is 0
|
||||
copy.setSelectedBufferRange(selection.getBufferRange(), isReversed: selection.isReversed())
|
||||
else
|
||||
copy.addSelectionForBufferRange(selection.getBufferRange(), isReversed: selection.isReversed())
|
||||
copy
|
||||
|
||||
### Public ###
|
||||
|
||||
|
||||
Reference in New Issue
Block a user