mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-14 04:29:04 +03:00
Cursor screen position is updated when lines are rewrapped.
This commit is contained in:
parent
77f448accc
commit
98defa865c
@ -83,12 +83,14 @@ describe "Editor", ->
|
||||
expect(editor.lines.find('.line:eq(8)').text()).toBe ': right.push(current);'
|
||||
expect(editor.lines.find('.line:eq(9)').text()).toBe ' }'
|
||||
|
||||
it "changes the max line length when the window size changes", ->
|
||||
it "changes the max line length and repositions the cursor when the window size changes", ->
|
||||
editor.setCursorBufferPosition([3, 60])
|
||||
editor.width(editor.charWidth * 40)
|
||||
$(window).trigger 'resize'
|
||||
expect(editor.lines.find('.line').length).toBe 19
|
||||
expect(editor.lines.find('.line:eq(4)').text()).toBe "left = [], right = [];"
|
||||
expect(editor.lines.find('.line:eq(5)').text()).toBe " while(items.length > 0) {"
|
||||
expect(editor.bufferPositionForScreenPosition(editor.getCursorScreenPosition())).toEqual [3, 60]
|
||||
|
||||
it "unwraps lines and cancels window resize listener when softwrap is disabled", ->
|
||||
editor.toggleSoftWrap()
|
||||
|
@ -8,6 +8,8 @@ class Cursor extends View
|
||||
@pre class: 'cursor idle', style: 'position: absolute;', => @raw ' '
|
||||
|
||||
editor: null
|
||||
screenPosition: null
|
||||
bufferPosition: null
|
||||
|
||||
initialize: (@editor) ->
|
||||
@one 'attach', => @updateAppearance()
|
||||
@ -18,6 +20,7 @@ class Cursor extends View
|
||||
setScreenPosition: (position) ->
|
||||
position = Point.fromObject(position)
|
||||
@screenPosition = @editor.clipScreenPosition(position)
|
||||
@bufferPosition = @editor.bufferPositionForScreenPosition(position)
|
||||
@goalColumn = null
|
||||
@updateAppearance()
|
||||
@trigger 'cursor:position-changed'
|
||||
@ -29,9 +32,10 @@ class Cursor extends View
|
||||
setBufferPosition: (bufferPosition) ->
|
||||
@setScreenPosition(@editor.screenPositionForBufferPosition(bufferPosition))
|
||||
|
||||
getBufferPosition: ->
|
||||
@editor.bufferPositionForScreenPosition(@getScreenPosition())
|
||||
refreshScreenPosition: ->
|
||||
@setBufferPosition(@bufferPosition)
|
||||
|
||||
getBufferPosition: -> _.clone(@bufferPosition)
|
||||
getScreenPosition: -> _.clone(@screenPosition)
|
||||
|
||||
getColumn: ->
|
||||
|
@ -170,6 +170,7 @@ class Editor extends View
|
||||
@cursor.bufferChanged(e)
|
||||
|
||||
@lineWrapper.on 'change', (e) =>
|
||||
@cursor.refreshScreenPosition()
|
||||
{ oldRange, newRange } = e
|
||||
screenLines = @linesForScreenRows(newRange.start.row, newRange.end.row)
|
||||
if newRange.end.row > oldRange.end.row
|
||||
|
Loading…
Reference in New Issue
Block a user