Cursor scrolls editor as it moves

This commit is contained in:
Corey Johnson & Nathan Sobo 2012-01-23 16:45:00 -08:00
parent 81fc69120f
commit 1a52890d19
6 changed files with 47 additions and 3 deletions

View File

@ -378,6 +378,7 @@
GCC_PREFIX_HEADER = "Atom/Atom-Prefix.pch";
INFOPLIST_FILE = "Atom/Atom-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
STRINGS_FILE_OUTPUT_ENCODING = "UTF-8";
WRAPPER_EXTENSION = app;
};
name = Debug;
@ -389,6 +390,7 @@
GCC_PREFIX_HEADER = "Atom/Atom-Prefix.pch";
INFOPLIST_FILE = "Atom/Atom-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
STRINGS_FILE_OUTPUT_ENCODING = "UTF-8";
WRAPPER_EXTENSION = app;
};
name = Release;

View File

@ -1,6 +1,7 @@
Buffer = require 'buffer'
Editor = require 'editor'
$ = require 'jquery'
_ = require 'underscore'
fs = require 'fs'
describe "Editor", ->
@ -43,6 +44,30 @@ describe "Editor", ->
expect(editor.getPosition()).toEqual(row: 0, col: 0)
describe "vertical movement", ->
fit "scrolls the buffer with the specified scroll margin when cursor approaches the end of the screen", ->
editor.attachToDom()
editor.focus()
editor.scrollMargin = 3
editor.height(editor.lineHeight * 10)
_.times 6, -> editor.moveDown()
expect(editor.scrollTop()).toBe(0)
editor.moveDown()
expect(editor.scrollTop()).toBe(editor.lineHeight)
editor.moveDown()
expect(editor.scrollTop()).toBe(editor.lineHeight * 2)
_.times 3, -> editor.moveUp()
expect(editor.scrollTop()).toBe(editor.lineHeight * 2)
editor.moveUp()
expect(editor.scrollTop()).toBe(editor.lineHeight)
editor.moveUp()
expect(editor.scrollTop()).toBe(0)
describe "when up is pressed on the first line", ->
it "moves the cursor to the beginning of the line, but retains the goal column", ->
editor.setPosition(row: 0, col: 4)
@ -65,7 +90,7 @@ describe "Editor", ->
editor.moveUp()
expect(editor.getPosition().col).toBe 1
fit "retains a goal column of 0", ->
it "retains a goal column of 0", ->
lastLineIndex = buffer.getLines().length - 1
lastLine = buffer.getLine(lastLineIndex)
expect(lastLine.length).toBeGreaterThan(0)

View File

@ -7,8 +7,8 @@ require 'window'
afterEach ->
(new Native).resetMainMenu()
atom.globalKeymap.reset()
$('#jasmine-content').empty()
# atom.globalKeymap.reset()
# $('#jasmine-content').empty()
window.atom = new (require 'app')

View File

@ -68,3 +68,12 @@ class Cursor extends Template
position = @parentView.pixelPositionFromPoint(@point)
@css(position)
margin = @parentView.scrollMargin * @height()
desiredTop = position.top - margin
desiredBottom = position.top + @height() + margin
if desiredBottom > @parentView.scrollBottom()
@parentView.scrollBottom(desiredBottom)
else if desiredTop < @parentView.scrollTop()
@parentView.scrollTop(desiredTop)

View File

@ -14,6 +14,7 @@ class Editor extends Template
viewProperties:
buffer: null
scrollMargin: 2
initialize: () ->
requireStylesheet 'editor.css'
@ -57,6 +58,12 @@ class Editor extends Template
fragment.remove()
@cursor.updateAbsolutePosition()
scrollBottom: (newValue) ->
if newValue?
@scrollTop(newValue - @height())
else
@scrollTop() + @height()
moveUp: -> @cursor.moveUp()
moveDown: -> @cursor.moveDown()
moveRight: -> @cursor.moveRight()

View File

@ -5,6 +5,7 @@
height: 100%;
background: #333;
color: white;
overflow-y: scroll;
}
.editor pre {