mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Every Buffer gets its own UndoManager.
This commit is contained in:
@@ -935,6 +935,26 @@ describe "Editor", ->
|
||||
expect(editor.scrollTop()).toBe previousScrollTop
|
||||
expect(editor.horizontalScroller.scrollLeft()).toBe previousScrollLeft
|
||||
|
||||
it "recalls the undo history of the buffer when it is re-assigned", ->
|
||||
editor.insertText('xyz')
|
||||
|
||||
otherBuffer = new Buffer
|
||||
editor.setBuffer(otherBuffer)
|
||||
editor.insertText('abc')
|
||||
expect(otherBuffer.lineForRow(0)).toBe 'abc'
|
||||
editor.undo()
|
||||
expect(otherBuffer.lineForRow(0)).toBe ''
|
||||
|
||||
editor.setBuffer(buffer)
|
||||
editor.undo()
|
||||
expect(buffer.lineForRow(0)).toBe 'var quicksort = function () {'
|
||||
editor.redo()
|
||||
expect(buffer.lineForRow(0)).toBe 'xyzvar quicksort = function () {'
|
||||
|
||||
editor.setBuffer(otherBuffer)
|
||||
editor.redo()
|
||||
expect(otherBuffer.lineForRow(0)).toBe 'abc'
|
||||
|
||||
describe ".clipScreenPosition(point)", ->
|
||||
it "selects the nearest valid position to the given point", ->
|
||||
expect(editor.clipScreenPosition(row: 1000, column: 0)).toEqual(row: buffer.lastRow(), column: buffer.lineForRow(buffer.lastRow()).length)
|
||||
|
||||
@@ -2,6 +2,7 @@ _ = require 'underscore'
|
||||
fs = require 'fs'
|
||||
Range = require 'range'
|
||||
EventEmitter = require 'event-emitter'
|
||||
UndoManager = require 'undo-manager'
|
||||
|
||||
module.exports =
|
||||
class Buffer
|
||||
@@ -16,6 +17,7 @@ class Buffer
|
||||
@setText(fs.read(@path))
|
||||
else
|
||||
@setText('')
|
||||
@undoManager = new UndoManager(this)
|
||||
|
||||
getText: ->
|
||||
@lines.join('\n')
|
||||
@@ -94,6 +96,12 @@ class Buffer
|
||||
@lines[oldRange.start.row..oldRange.end.row] = newTextLines
|
||||
@trigger 'change', { oldRange, newRange, oldText, newText }
|
||||
|
||||
undo: ->
|
||||
@undoManager.undo()
|
||||
|
||||
redo: ->
|
||||
@undoManager.redo()
|
||||
|
||||
save: ->
|
||||
if not @path then throw new Error("Tried to save buffer with no url")
|
||||
fs.write @path, @getText()
|
||||
|
||||
@@ -7,7 +7,6 @@ Renderer = require 'renderer'
|
||||
Point = require 'point'
|
||||
Range = require 'range'
|
||||
Selection = require 'selection'
|
||||
UndoManager = require 'undo-manager'
|
||||
EditSession = require 'edit-session'
|
||||
|
||||
$ = require 'jquery'
|
||||
@@ -34,7 +33,6 @@ class Editor extends View
|
||||
buffer: null
|
||||
highlighter: null
|
||||
renderer: null
|
||||
undoManager: null
|
||||
autoIndent: null
|
||||
lineCache: null
|
||||
|
||||
@@ -165,7 +163,6 @@ class Editor extends View
|
||||
@saveEditSession() if @editSession
|
||||
document.title = @buffer.path
|
||||
@renderer = new Renderer(@buffer)
|
||||
@undoManager = new UndoManager(@buffer)
|
||||
@renderLines()
|
||||
@gutter.renderLineNumbers()
|
||||
|
||||
@@ -379,10 +376,10 @@ class Editor extends View
|
||||
@selection.delete()
|
||||
|
||||
undo: ->
|
||||
@undoManager.undo()
|
||||
@buffer.undo()
|
||||
|
||||
redo: ->
|
||||
@undoManager.redo()
|
||||
@buffer.redo()
|
||||
|
||||
destroyFold: (foldId) ->
|
||||
fold = @renderer.foldsById[foldId]
|
||||
|
||||
Reference in New Issue
Block a user