Set modified flag to true when there is a buffer change.

This commit is contained in:
Corey Johnson
2012-06-11 17:34:53 -07:00
parent 869df0bbc6
commit 9339791260
2 changed files with 39 additions and 12 deletions

View File

@@ -8,16 +8,19 @@ UndoManager = require 'undo-manager'
module.exports =
class Buffer
@idCounter = 1
modified: null
lines: null
path: null
@deserialize: (state, project) ->
if state.path
project.open(state.path)
buffer = project.open(state.path)
else
buffer = project.bufferWithId(state.id) ? project.open()
buffer.setText(state.text)
buffer
buffer.modified = state.modified
buffer
constructor: (path) ->
@id = @constructor.idCounter++
@@ -28,12 +31,13 @@ class Buffer
else
@setText('')
@undoManager = new UndoManager(this)
@modified = false
serialize: ->
if @getPath()
{ path: @path }
else
{ text: @getText(), id: @id }
{ text: @getText(), id: @id , modified: @modified}
getPath: ->
@path
@@ -139,6 +143,8 @@ class Buffer
newTextLines[lastLineIndex] += suffix
@lines[oldRange.start.row..oldRange.end.row] = newTextLines
@modified = true
@trigger 'change', { oldRange, newRange, oldText, newText }
newRange
@@ -164,6 +170,9 @@ class Buffer
@setPath(path)
@save()
isModified: ->
@modified
getMode: ->
return @mode if @mode
extension = if @getPath() then @getPath().split('/').pop().split('.').pop() else null