mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Serialized Editor state no longer contains Buffer objects
This commit is contained in:
@@ -11,6 +11,14 @@ class Buffer
|
||||
lines: null
|
||||
path: null
|
||||
|
||||
@deserialize: (state, project) ->
|
||||
if state.path
|
||||
project.open(state.path)
|
||||
else
|
||||
buffer = project.bufferWithId(state.id) ? project.open()
|
||||
buffer.setText(state.text)
|
||||
buffer
|
||||
|
||||
constructor: (path) ->
|
||||
@id = @constructor.idCounter++
|
||||
@setPath(path)
|
||||
@@ -21,6 +29,12 @@ class Buffer
|
||||
@setText('')
|
||||
@undoManager = new UndoManager(this)
|
||||
|
||||
serialize: ->
|
||||
if @getPath()
|
||||
{ path: @path }
|
||||
else
|
||||
{ text: @getText(), id: @id }
|
||||
|
||||
getPath: ->
|
||||
@path
|
||||
|
||||
|
||||
@@ -40,7 +40,12 @@ class Editor extends View
|
||||
tabText: ' '
|
||||
editSessions: null
|
||||
|
||||
@deserialize: (viewState) ->
|
||||
@deserialize: (viewState, rootView) ->
|
||||
viewState.editSessions = viewState.editSessions.map (editSession) ->
|
||||
editSession = _.clone(editSession)
|
||||
editSession.buffer = Buffer.deserialize(editSession.buffer, rootView.project)
|
||||
editSession
|
||||
|
||||
new Editor(viewState)
|
||||
|
||||
initialize: ({editSessions, activeEditSessionIndex, buffer, isFocused}) ->
|
||||
@@ -68,16 +73,19 @@ class Editor extends View
|
||||
{ viewClass: "Editor", editSessions: @serializeEditSessions(), @activeEditSessionIndex, @isFocused }
|
||||
|
||||
serializeEditSessions: ->
|
||||
@editSessions.map (session) -> _.clone(session)
|
||||
@editSessions.map (session) ->
|
||||
session = _.clone(session)
|
||||
session.buffer = session.buffer.serialize()
|
||||
session
|
||||
|
||||
copy: ->
|
||||
Editor.deserialize(@serialize())
|
||||
Editor.deserialize(@serialize(), @rootView())
|
||||
|
||||
bindKeys: ->
|
||||
@on 'save', => @save()
|
||||
@on 'move-right', => @moveCursorRight()
|
||||
@on 'move-left', => @moveCursorLeft()
|
||||
@on 'move-down', => @moveCursorDown()
|
||||
@on 'move-down', (e) => @moveCursorDown()
|
||||
@on 'move-up', => @moveCursorUp()
|
||||
@on 'move-to-next-word', => @moveCursorToNextWord()
|
||||
@on 'move-to-previous-word', => @moveCursorToPreviousWord()
|
||||
|
||||
@@ -5,11 +5,9 @@ EventEmitter = require 'event-emitter'
|
||||
|
||||
module.exports =
|
||||
class Project
|
||||
buffersByPath: null
|
||||
buffers: null
|
||||
|
||||
constructor: (@path) ->
|
||||
@buffersByPath = {}
|
||||
@buffers = []
|
||||
|
||||
getFilePaths: ->
|
||||
@@ -20,7 +18,7 @@ class Project
|
||||
open: (filePath) ->
|
||||
if filePath?
|
||||
filePath = @resolve(filePath)
|
||||
@buffersByPath[filePath] ?= @buildBuffer(filePath)
|
||||
@bufferWithPath(filePath) ? @buildBuffer(filePath)
|
||||
else
|
||||
@buildBuffer()
|
||||
|
||||
@@ -34,4 +32,10 @@ class Project
|
||||
filePath = fs.join(@path, filePath) unless filePath[0] == '/'
|
||||
fs.absolute filePath
|
||||
|
||||
bufferWithId: (id) ->
|
||||
return buffer for buffer in @buffers when buffer.id == id
|
||||
|
||||
bufferWithPath: (path) ->
|
||||
return buffer for buffer in @buffers when buffer.path == path
|
||||
|
||||
_.extend Project.prototype, EventEmitter
|
||||
|
||||
@@ -36,14 +36,12 @@ class RootView extends View
|
||||
|
||||
@commandPanel = new CommandPanel({rootView: this})
|
||||
|
||||
if projectPath?
|
||||
@project = new Project(projectPath)
|
||||
else if pathToOpen?
|
||||
if pathToOpen?
|
||||
@project = new Project(fs.directory(pathToOpen))
|
||||
@open(pathToOpen) if fs.isFile(pathToOpen)
|
||||
else if not panesViewState?
|
||||
@project = new Project
|
||||
@open()
|
||||
else
|
||||
@project = new Project(projectPath)
|
||||
@open() unless panesViewState?
|
||||
|
||||
@deserializePanes(panesViewState) if panesViewState
|
||||
|
||||
@@ -63,7 +61,7 @@ class RootView extends View
|
||||
when 'Pane' then Pane.deserialize(viewState, this)
|
||||
when 'PaneRow' then PaneRow.deserialize(viewState, this)
|
||||
when 'PaneColumn' then PaneColumn.deserialize(viewState, this)
|
||||
when 'Editor' then Editor.deserialize(viewState)
|
||||
when 'Editor' then Editor.deserialize(viewState, this)
|
||||
|
||||
open: (path) ->
|
||||
buffer = @project.open(path)
|
||||
|
||||
Reference in New Issue
Block a user