Fix exception when auto-indenting after fold placeholder.

Propagate state when splitting and concatenating screen line fragments, because we were passing an undefined state to the auto-indenter.
This commit is contained in:
Nathan Sobo
2012-03-13 15:50:43 -06:00
parent c102711336
commit 06a3f3d376
2 changed files with 15 additions and 6 deletions

View File

@@ -536,13 +536,21 @@ describe "Editor", ->
beforeEach ->
editor.autoIndent = true
describe "when line renders on one screen line", ->
describe "when newline is inserted", ->
describe "when editing a line that spans a single screen line", ->
describe "when a newline is inserted", ->
it "indents cursor based on the indentation of previous buffer line", ->
editor.setCursorBufferPosition([1, 30])
editor.insertText("\n")
expect(editor.buffer.lineForRow(2)).toEqual(" ")
describe "when a newline is inserted following a fold placeholder", ->
it "indents cursor based on the indentation of previous buffer line", ->
editor.createFold([[1, 10], [1, 30]])
editor.setCursorBufferPosition([1, 30])
editor.insertText("\n")
expect(editor.buffer.lineForRow(2)).toEqual(" ")
describe "when text beginning with a newline is inserted", ->
it "indents cursor based on the indentation of previous buffer line", ->
editor.setCursorBufferPosition([4, 29])
editor.insertText("\nvar thisIsCool")
@@ -557,7 +565,7 @@ describe "Editor", ->
expect(editor.buffer.lineForRow(2)).toEqual(" }")
expect(editor.getCursorBufferPosition().column).toBe 3
describe "when line spans multiple screen lines", ->
describe "when editing a line that spans multiple screen lines", ->
beforeEach ->
editor.attachToDom()
editor.setSoftWrap(true)

View File

@@ -4,6 +4,7 @@ Point = require 'point'
module.exports =
class ScreenLineFragment
isAtomic: false
state: null
constructor: (@tokens, @text, screenDelta, bufferDelta, extraFields) ->
@screenDelta = Point.fromObject(screenDelta)
@@ -29,8 +30,8 @@ class ScreenLineFragment
[leftScreenDelta, rightScreenDelta] = @screenDelta.splitAt(column)
[leftBufferDelta, rightBufferDelta] = @bufferDelta.splitAt(column)
leftFragment = new ScreenLineFragment(leftTokens, leftText, leftScreenDelta, leftBufferDelta)
rightFragment = new ScreenLineFragment(rightTokens, rightText, rightScreenDelta, rightBufferDelta)
leftFragment = new ScreenLineFragment(leftTokens, leftText, leftScreenDelta, leftBufferDelta, {@state})
rightFragment = new ScreenLineFragment(rightTokens, rightText, rightScreenDelta, rightBufferDelta, {@state})
[leftFragment, rightFragment]
splitTokenAt: (token, splitIndex) ->
@@ -44,7 +45,7 @@ class ScreenLineFragment
text = @text + other.text
screenDelta = @screenDelta.add(other.screenDelta)
bufferDelta = @bufferDelta.add(other.bufferDelta)
new ScreenLineFragment(tokens, text, screenDelta, bufferDelta)
new ScreenLineFragment(tokens, text, screenDelta, bufferDelta, {state: other.state})
isSoftWrapped: ->
@screenDelta.row == 1 and @bufferDelta.row == 0