diff --git a/spec/text-editor-spec.coffee b/spec/text-editor-spec.coffee index 63b01a178..9cf5d783b 100644 --- a/spec/text-editor-spec.coffee +++ b/spec/text-editor-spec.coffee @@ -916,6 +916,12 @@ describe "TextEditor", -> editor.setCursorBufferPosition([3, 1]) expect(editor.getCurrentParagraphBufferRange()).toBeUndefined() + describe "getCursorAtScreenPosition(screenPosition)", -> + it "returns the cursor at the given screenPosition", -> + cursor1 = editor.addCursorAtScreenPosition([0, 2]) + cursor2 = editor.getCursorAtScreenPosition(cursor1.getScreenPosition()) + expect(cursor2.marker).toBe cursor1.marker + describe "::getCursorScreenPositions()", -> it "returns the cursor positions in the order they were added", -> editor.foldBufferRow(4) diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 977b94ed1..8c6bc0104 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -1561,6 +1561,17 @@ class TextEditor extends Model setCursorBufferPosition: (position, options) -> @moveCursors (cursor) -> cursor.setBufferPosition(position, options) + # Essential: Get a {Cursor} at given screen coordinates {Point} + # + #* `position` A {Point} + # + # Returns the first matched {Cursor} or undefined + getCursorAtScreenPosition: (position) -> + cursorsAtPoint = @cursors.filter (cursor) -> + cursorPosition = cursor.getScreenPosition() + cursorPosition.row is position.row and cursorPosition.column is position.column + if cursorsAtPoint.length > 0 then cursorsAtPoint[0] else undefined + # Essential: Get the position of the most recently added cursor in screen # coordinates. #