mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-21 07:58:04 +03:00
Positioning the cursor beyond the bottom of the buffer will clip it to the last column of the last row
This commit is contained in:
parent
b45c00d90e
commit
88cf574bc6
@ -632,7 +632,7 @@ describe "Editor", ->
|
||||
|
||||
describe ".clipPosition(point)", ->
|
||||
it "selects the nearest valid position to the given point", ->
|
||||
expect(editor.clipPosition(row: 1000, column: 0)).toEqual(row: buffer.numLines() - 1, column: 0)
|
||||
expect(editor.clipPosition(row: 1000, column: 0)).toEqual(row: buffer.lastRow(), column: buffer.getLine(buffer.lastRow()).length)
|
||||
expect(editor.clipPosition(row: -5, column: 0)).toEqual(row: 0, column: 0)
|
||||
expect(editor.clipPosition(row: 1, column: 10000)).toEqual(row: 1, column: buffer.getLine(1).length)
|
||||
expect(editor.clipPosition(row: 1, column: -5)).toEqual(row: 1, column: 0)
|
||||
|
@ -161,8 +161,13 @@ class Editor extends Template
|
||||
@lines.find("pre.line:eq(#{row})")
|
||||
|
||||
clipPosition: ({row, column}) ->
|
||||
row = Math.min(Math.max(0, row), @buffer.numLines() - 1)
|
||||
column = Math.min(Math.max(0, column), @buffer.getLine(row).length)
|
||||
if row > @buffer.lastRow()
|
||||
row = @buffer.lastRow()
|
||||
column = @buffer.getLine(row).length
|
||||
else
|
||||
row = Math.min(Math.max(0, row), @buffer.numLines() - 1)
|
||||
column = Math.min(Math.max(0, column), @buffer.getLine(row).length)
|
||||
|
||||
new Point(row, column)
|
||||
|
||||
pixelPositionFromPoint: ({row, column}) ->
|
||||
|
Loading…
Reference in New Issue
Block a user