From e5eaa2538189ad2424fc13e6b204c10460026be5 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 18 Feb 2015 18:58:43 +0100 Subject: [PATCH] Wrap at phantom tokens only when moving cursor left This prevents a weird behavior that affects selection. Before this commit, when moving the cursor down, if it was inside a real (soft|hard)-tab of a soft wrapped line, it would reach the end of the line rather than the beginning of the next wrapped line. /cc: @nathansobo --- src/cursor.coffee | 2 +- src/display-buffer.coffee | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cursor.coffee b/src/cursor.coffee index bfd6de536..e62f3a472 100644 --- a/src/cursor.coffee +++ b/src/cursor.coffee @@ -310,7 +310,7 @@ class Cursor extends Model columnCount-- # subtract 1 for the row move column = column - columnCount - @setScreenPosition({row, column}) + @setScreenPosition({row, column}, wrapAtPhantomTokens: true) # Public: Moves the cursor right one screen column. # diff --git a/src/display-buffer.coffee b/src/display-buffer.coffee index a092d2c8d..39a54326c 100644 --- a/src/display-buffer.coffee +++ b/src/display-buffer.coffee @@ -819,11 +819,12 @@ class DisplayBuffer extends Model # options - A hash with the following values: # wrapBeyondNewlines: if `true`, continues wrapping past newlines # wrapAtSoftNewlines: if `true`, continues wrapping past soft newlines + # wrapAtPhantomTokens: if `true`, continues wrapping before phantom tokens # screenLine: if `true`, indicates that you're using a line number, not a row number # # Returns the new, clipped {Point}. Note that this could be the same as `position` if no clipping was performed. clipScreenPosition: (screenPosition, options={}) -> - { wrapBeyondNewlines, wrapAtSoftNewlines } = options + { wrapBeyondNewlines, wrapAtSoftNewlines, wrapAtPhantomTokens } = options { row, column } = Point.fromObject(screenPosition) if row < 0 @@ -845,8 +846,11 @@ class DisplayBuffer extends Model else column = screenLine.clipScreenColumn(maxScreenColumn - 1) else if screenLine.isColumnInsidePhantomToken(column) - row-- - column = @screenLines[row].getMaxScreenColumn() + if wrapAtPhantomTokens + row-- + column = @screenLines[row].getMaxScreenColumn() + else + column = screenLine.clipScreenColumn(0) else if wrapBeyondNewlines and column > maxScreenColumn and row < @getLastRow() row++ column = 0