mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Introduce EditSession class, which replaces edit session hashes
This commit is contained in:
38
src/app/edit-session.coffee
Normal file
38
src/app/edit-session.coffee
Normal file
@@ -0,0 +1,38 @@
|
||||
Point = require 'point'
|
||||
Buffer = require 'buffer'
|
||||
|
||||
module.exports =
|
||||
class EditSession
|
||||
@deserialize: (state, rootView) ->
|
||||
buffer = Buffer.deserialize(state.buffer, rootView.project)
|
||||
session = new EditSession(buffer)
|
||||
session.setScrollTop(state.scrollTop)
|
||||
session.setScrollLeft(state.scrollLeft)
|
||||
session.setCursorScreenPosition(state.cursorScreenPosition)
|
||||
session
|
||||
|
||||
scrollTop: 0
|
||||
scrollLeft: 0
|
||||
cursorScreenPosition: null
|
||||
|
||||
constructor: (@buffer) ->
|
||||
@setCursorScreenPosition([0, 0])
|
||||
|
||||
serialize: ->
|
||||
buffer: @buffer.serialize()
|
||||
scrollTop: @getScrollTop()
|
||||
scrollLeft: @getScrollLeft()
|
||||
cursorScreenPosition: @getCursorScreenPosition().serialize()
|
||||
|
||||
setScrollTop: (@scrollTop) ->
|
||||
getScrollTop: -> @scrollTop
|
||||
|
||||
setScrollLeft: (@scrollLeft) ->
|
||||
getScrollLeft: -> @scrollLeft
|
||||
|
||||
setCursorScreenPosition: (position) ->
|
||||
@cursorScreenPosition = Point.fromObject(position)
|
||||
|
||||
getCursorScreenPosition: ->
|
||||
@cursorScreenPosition
|
||||
|
||||
@@ -6,6 +6,7 @@ Gutter = require 'gutter'
|
||||
Renderer = require 'renderer'
|
||||
Point = require 'point'
|
||||
Range = require 'range'
|
||||
EditSession = require 'edit-session'
|
||||
|
||||
$ = require 'jquery'
|
||||
_ = require 'underscore'
|
||||
@@ -50,11 +51,7 @@ class Editor extends View
|
||||
|
||||
@deserialize: (viewState, rootView) ->
|
||||
viewState = _.clone(viewState)
|
||||
viewState.editSessions = viewState.editSessions.map (editSession) ->
|
||||
editSession = _.clone(editSession)
|
||||
editSession.buffer = Buffer.deserialize(editSession.buffer, rootView.project)
|
||||
editSession
|
||||
|
||||
viewState.editSessions = viewState.editSessions.map (state) -> EditSession.deserialize(state, rootView)
|
||||
new Editor(viewState)
|
||||
|
||||
initialize: ({editSessions, activeEditSessionIndex, buffer, isFocused, @mini} = {}) ->
|
||||
@@ -83,10 +80,7 @@ class Editor extends View
|
||||
{ viewClass: "Editor", editSessions: @serializeEditSessions(), @activeEditSessionIndex, @isFocused }
|
||||
|
||||
serializeEditSessions: ->
|
||||
@editSessions.map (session) ->
|
||||
session = _.clone(session)
|
||||
session.buffer = session.buffer.serialize()
|
||||
session
|
||||
@editSessions.map (session) -> session.serialize()
|
||||
|
||||
copy: ->
|
||||
Editor.deserialize(@serialize(), @rootView())
|
||||
@@ -351,7 +345,7 @@ class Editor extends View
|
||||
if editSession
|
||||
@activeEditSessionIndex = index
|
||||
else
|
||||
@editSessions.push({ buffer })
|
||||
@editSessions.push(new EditSession(buffer))
|
||||
@activeEditSessionIndex = @editSessions.length - 1
|
||||
@loadEditSession()
|
||||
|
||||
@@ -381,11 +375,10 @@ class Editor extends View
|
||||
@scrollView.scrollLeft(editSession.scrollLeft ? 0)
|
||||
|
||||
saveCurrentEditSession: ->
|
||||
@editSessions[@activeEditSessionIndex] =
|
||||
buffer: @buffer
|
||||
cursorScreenPosition: @getCursorScreenPosition()
|
||||
scrollTop: @scrollTop()
|
||||
scrollLeft: @scrollView.scrollLeft()
|
||||
session = @getActiveEditSession()
|
||||
session.setCursorScreenPosition(@getCursorScreenPosition())
|
||||
session.setScrollTop(@scrollTop())
|
||||
session.setScrollLeft(@scrollView.scrollLeft())
|
||||
|
||||
renderLines: ->
|
||||
@clearRenderedLines()
|
||||
|
||||
@@ -79,3 +79,6 @@ class Point
|
||||
|
||||
toArray: ->
|
||||
[@row, @column]
|
||||
|
||||
serialize: ->
|
||||
@toArray()
|
||||
|
||||
Reference in New Issue
Block a user