Don't nuke goalColumn when moving down on last line

This commit is contained in:
Corey Johnson & Nathan Sobo 2012-01-23 14:37:03 -08:00
parent 713615d515
commit 101d20692d
2 changed files with 16 additions and 8 deletions

View File

@ -3,7 +3,7 @@ Editor = require 'editor'
$ = require 'jquery'
fs = require 'fs'
fdescribe "Editor", ->
describe "Editor", ->
buffer = null
editor = null
@ -98,15 +98,19 @@ fdescribe "Editor", ->
describe "down", ->
describe "when on the last line", ->
it "moves the cursor to the end of line", ->
it "moves the cursor to the end of line, but retains the goal column", ->
lastLineIndex = buffer.getLines().length - 1
lastLine = buffer.getLine(lastLineIndex)
expect(lastLine.length).toBeGreaterThan(0)
editor.setPosition(row: lastLineIndex, col: 0)
editor.setPosition(row: lastLineIndex, col: 1)
editor.moveDown()
expect(editor.getPosition()).toEqual(row: lastLineIndex, col: lastLine.length)
editor.moveUp()
expect(editor.getPosition().col).toBe 1
describe "when left is pressed on the first column", ->
describe "when there is a previous line", ->
it "wraps to the end of the previous line", ->
@ -127,7 +131,7 @@ fdescribe "Editor", ->
editor.moveRight()
expect(editor.getPosition()).toEqual(row: 1, col: 0)
fdescribe "when the cursor is on the last line", ->
describe "when the cursor is on the last line", ->
it "remains in the same position", ->
lastLineIndex = buffer.getLines().length - 1
lastLine = buffer.getLine(lastLineIndex)

View File

@ -31,14 +31,18 @@ class Cursor extends Template
moveDown: ->
{ row, col } = @getPosition()
col = @goalColumn if @goalColumn
if row < @parentView.buffer.numLines() - 1
row++
@setPosition({row, col})
else
col = @parentView.buffer.getLine(row).length
@moveToEndOfLine()
col = @goalColumn if @goalColumn
@setPosition({row, col})
@goalColumn ?= col
@goalColumn = col
moveToEndOfLine: ->
{ row } = @getPosition()
@setPosition({ row, col: @parentView.buffer.getLine(row).length })
moveRight: ->
{ row, col } = @getPosition()