From 8ea937b15befb32b1b6a6bf12fb28ec2ea83a48c Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 25 Jan 2012 18:39:56 -0800 Subject: [PATCH] When possible, re-assign line element text instead of replacing. Slight speculative optimization but it's pretty simple. --- src/atom/editor.coffee | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/atom/editor.coffee b/src/atom/editor.coffee index a873cf78c..cbb89022d 100644 --- a/src/atom/editor.coffee +++ b/src/atom/editor.coffee @@ -41,8 +41,8 @@ class Editor extends Template @on 'move-left', => @moveLeft() @on 'move-down', => @moveDown() @on 'move-up', => @moveUp() - @on 'newline', => @buffer.change({ start: @getPosition(), end: @getPosition() }, "\n") - @on 'backspace', => @buffer.backspace @getPosition() + @on 'newline', => @bench = @buffer.change({ start: @getPosition(), end: @getPosition() }, "\n") + @on 'backspace', => @benrch = @buffer.backspace @getPosition() handleEvents: -> @on 'focus', => @@ -69,13 +69,6 @@ class Editor extends Template @setPosition(row: 0, col: 0) - # @buffer.on 'insert', (e) => - # {row} = e.range.start - # updatedLine = @buildLineElement(@buffer.getLine(row)) - # @lines.find('pre').eq(row).replaceWith(updatedLine) - # if e.string == '\n' - # updatedLine.after @buildLineElement(@buffer.getLine(row + 1)) - @buffer.on 'change', (e) => { preRange, postRange } = e @@ -94,7 +87,12 @@ class Editor extends Template @cursor.bufferChanged(e) updateLineElement: (row) -> - @getLineElement(row).replaceWith(@buildLineElement(@buffer.getLine(row))) + line = @buffer.getLine(row) + elt = @getLineElement(row) + if line == '' + elt.html(' ') + else + elt.text(line) insertLineElement: (row) -> @getLineElement(row).before(@buildLineElement(@buffer.getLine(row)))