Skip to content
This repository was archived by the owner on Apr 6, 2018. It is now read-only.

Commit 72b5896

Browse files
committed
refactor #785
1 parent a58b602 commit 72b5896

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

lib/motions/general-motions.coffee

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,9 @@ class MoveRight extends Motion
161161
cursor.moveRight() if wrapToNextLine and cursor.isAtEndOfLine()
162162
@ensureCursorIsWithinLine(cursor)
163163

164-
class MoveUp extends Motion
164+
class MoveUpDown extends Motion
165165
operatesLinewise: true
166+
direction: null
166167

167168
getScreenRowCount: (cursor) ->
168169
unless (@isLinewise() and @editor.isSoftWrapped())
@@ -176,26 +177,16 @@ class MoveUp extends Motion
176177
moveCursor: (cursor, count=1) ->
177178
_.times count, =>
178179
unless cursor.getScreenRow() is 0
179-
cursor.moveUp(@getScreenRowCount(cursor))
180+
cursor["move#{@direction}"](@getScreenRowCount(cursor))
180181
@ensureCursorIsWithinLine(cursor)
181182

182-
class MoveDown extends Motion
183+
class MoveUp extends MoveUpDown
183184
operatesLinewise: true
185+
direction: 'Up'
184186

185-
getScreenRowCount: (cursor) ->
186-
unless (@isLinewise() and @editor.isSoftWrapped())
187-
return 1
188-
else
189-
cursorBufferRow = cursor.getBufferRow()
190-
cursorLineBufferRange = [[cursorBufferRow, 0], [cursorBufferRow, Infinity]]
191-
cursorLineScreenRange = @editor.screenRangeForBufferRange(cursorLineBufferRange)
192-
cursorLineScreenRange.getRowCount()
193-
194-
moveCursor: (cursor, count=1) ->
195-
_.times count, =>
196-
unless cursor.getScreenRow() is @editor.getLastScreenRow()
197-
cursor.moveDown(@getScreenRowCount(cursor))
198-
@ensureCursorIsWithinLine(cursor)
187+
class MoveDown extends MoveUpDown
188+
operatesLinewise: true
189+
direction: 'Down'
199190

200191
class MoveToPreviousWord extends Motion
201192
operatesInclusively: false

0 commit comments

Comments
 (0)