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

Commit 7791f5e

Browse files
committed
Refactoring. much better for now #785
Other motion now can use getScreenRowCount().
1 parent 1f99b6e commit 7791f5e

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

lib/motions/general-motions.coffee

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ class Motion
110110
isInclusive: ->
111111
@vimState.mode is 'visual' or @operatesInclusively
112112

113+
getScreenRowCount: (cursor) ->
114+
return 1 unless (@editor.isSoftWrapped() and @isLinewise())
115+
116+
bufferRow = cursor.getBufferRow()
117+
bufferRowRange = new Range([bufferRow, 0], [bufferRow, Infinity])
118+
@editor.screenRangeForBufferRange(bufferRowRange).getRowCount()
119+
113120
class CurrentSelection extends Motion
114121
constructor: (@editor, @vimState) ->
115122
super(@editor, @vimState)
@@ -161,36 +168,23 @@ class MoveRight extends Motion
161168
cursor.moveRight() if wrapToNextLine and cursor.isAtEndOfLine()
162169
@ensureCursorIsWithinLine(cursor)
163170

164-
class MoveUpDown extends Motion
171+
class MoveUp extends Motion
165172
operatesLinewise: true
166-
direction: null
167-
168-
getScreenRowCount: (cursor) ->
169-
return 1 unless (@isLinewise() and @editor.isSoftWrapped())
170-
171-
cursorBufferRow = cursor.getBufferRow()
172-
cursorLineBufferRange = [[cursorBufferRow, 0], [cursorBufferRow, Infinity]]
173-
cursorLineScreenRange = @editor.screenRangeForBufferRange(cursorLineBufferRange)
174-
cursorLineScreenRange.getRowCount()
175173

176174
moveCursor: (cursor, count=1) ->
177175
_.times count, =>
178-
screenRowCount = @getScreenRowCount(cursor)
179-
180-
if (@direction is 'Up') and not (cursor.getScreenRow() is 0)
181-
cursor.moveUp(screenRowCount)
182-
@ensureCursorIsWithinLine(cursor)
183-
else if (@direction is 'Down') and not (cursor.getScreenRow() is @editor.getLastScreenRow())
184-
cursor.moveDown(screenRowCount)
176+
unless cursor.getScreenRow() is 0
177+
cursor.moveUp(@getScreenRowCount(cursor))
185178
@ensureCursorIsWithinLine(cursor)
186179

187-
class MoveUp extends MoveUpDown
180+
class MoveDown extends Motion
188181
operatesLinewise: true
189-
direction: 'Up'
190182

191-
class MoveDown extends MoveUpDown
192-
operatesLinewise: true
193-
direction: 'Down'
183+
moveCursor: (cursor, count=1) ->
184+
_.times count, =>
185+
unless cursor.getScreenRow() is @editor.getLastScreenRow()
186+
cursor.moveDown(@getScreenRowCount(cursor))
187+
@ensureCursorIsWithinLine(cursor)
194188

195189
class MoveToPreviousWord extends Motion
196190
operatesInclusively: false

0 commit comments

Comments
 (0)