Merge pull request #3420 from atom/bo-update-cursor-selection-apis

Update cursor and selection APIs
This commit is contained in:
Ben Ogle
2014-09-02 16:41:42 -07:00
10 changed files with 813 additions and 610 deletions

View File

@@ -53,7 +53,7 @@ describe "editorView.", ->
describe "at-end.", ->
beforeEach ->
editorView.moveCursorToBottom()
editorView.moveToBottom()
benchmark "insert-delete", ->
editorView.insertText('"')
@@ -178,7 +178,7 @@ describe "editorView.", ->
atom.workspaceView.openSync('huge.js')
benchmark "moving-to-eof.", 1, ->
editorView.moveCursorToBottom()
editorView.moveToBottom()
describe "on-first-line.", ->
benchmark "inserting-newline", 5, ->
@@ -195,11 +195,11 @@ describe "editorView.", ->
endPosition = null
beforeEach ->
editorView.moveCursorToBottom()
editorView.moveToBottom()
endPosition = editorView.getCursorScreenPosition()
benchmark "move-to-beginning-of-word", ->
editorView.moveCursorToBeginningOfWord()
editorView.moveToBeginningOfWord()
editorView.setCursorScreenPosition(endPosition)
benchmark "insert", ->

View File

@@ -56,7 +56,7 @@ character of the current line:
class EditorView
listenForEvents: ->
@command 'editor:move-to-first-character-of-line', =>
@editor.moveCursorToFirstCharacterOfLine()
@editor.moveToFirstCharacterOfLine()
```
The `::command` method is basically an enhanced version of jQuery's `::on`

View File

@@ -132,7 +132,7 @@ inserting 'Hello, World!' convert the selected text to ASCII art.
convert: ->
# This assumes the active pane item is an editor
editor = atom.workspace.activePaneItem
selection = editor.getSelection()
selection = editor.getLastSelection()
figlet = require 'figlet'
figlet selection.getText(), {font: "Larry 3D 2"}, (error, asciiArt) ->

View File

@@ -82,7 +82,7 @@
"dev-live-reload": "0.34.0",
"exception-reporting": "0.20.0",
"feedback": "0.33.0",
"find-and-replace": "0.131.1",
"find-and-replace": "0.132.0",
"fuzzy-finder": "0.57.0",
"git-diff": "0.39.0",
"go-to-line": "0.25.0",

View File

@@ -601,7 +601,7 @@ describe "EditorComponent", ->
describe "cursor rendering", ->
it "renders the currently visible cursors, translated relative to the scroll position", ->
cursor1 = editor.getCursor()
cursor1 = editor.getLastCursor()
cursor1.setScreenPosition([0, 5])
wrapperNode.style.height = 4.5 * lineHeightInPixels + 'px'
@@ -710,7 +710,7 @@ describe "EditorComponent", ->
expect(cursorsNode.classList.contains('blink-off')).toBe false
# Stop blinking after moving the cursor
editor.moveCursorRight()
editor.moveRight()
expect(cursorsNode.classList.contains('blink-off')).toBe false
advanceClock(component.props.cursorBlinkResumeDelay)
@@ -814,8 +814,8 @@ describe "EditorComponent", ->
it "does not render empty selections", ->
editor.addSelectionForBufferRange([[2, 2], [2, 2]])
nextAnimationFrame()
expect(editor.getSelection(0).isEmpty()).toBe true
expect(editor.getSelection(1).isEmpty()).toBe true
expect(editor.getSelections()[0].isEmpty()).toBe true
expect(editor.getSelections()[1].isEmpty()).toBe true
expect(componentNode.querySelectorAll('.selection').length).toBe 0
@@ -1437,7 +1437,7 @@ describe "EditorComponent", ->
cursor = null
beforeEach ->
cursor = editor.getCursor()
cursor = editor.getLastCursor()
cursor.setScreenPosition([0, 0])
it "adds the 'has-selection' class to the editor when there is a selection", ->

File diff suppressed because it is too large Load Diff

View File

@@ -6,7 +6,7 @@ describe "Selection", ->
beforeEach ->
buffer = atom.project.bufferForPathSync('sample.js')
editor = new Editor(buffer: buffer, tabLength: 2)
selection = editor.getSelection()
selection = editor.getLastSelection()
afterEach ->
buffer.destroy()

View File

@@ -157,7 +157,7 @@ class Cursor extends Model
#
# Returns a {Boolean}.
isLastCursor: ->
this == @editor.getCursor()
this == @editor.getLastCursor()
# Public: Identifies if the cursor is surrounded by whitespace.
#
@@ -225,7 +225,7 @@ class Cursor extends Model
@editor.lineForBufferRow(@getBufferRow())
# Public: Moves the cursor up one screen row.
moveUp: (rowCount = 1, {moveToEndOfSelection}={}) ->
moveUp: (rowCount=1, {moveToEndOfSelection}={}) ->
range = @marker.getScreenRange()
if moveToEndOfSelection and not range.isEmpty()
{ row, column } = range.start
@@ -309,17 +309,6 @@ class Cursor extends Model
@setBufferPosition([lineBufferRange.start.row, targetBufferColumn])
# Public: Moves the cursor to the beginning of the buffer line, skipping all
# whitespace.
skipLeadingWhitespace: ->
position = @getBufferPosition()
scanRange = @getCurrentLineBufferRange()
endOfLeadingWhitespace = null
@editor.scanInBufferRange /^[ \t]*/, scanRange, ({range}) ->
endOfLeadingWhitespace = range.end
@setBufferPosition(endOfLeadingWhitespace) if endOfLeadingWhitespace.isGreaterThan(position)
# Public: Moves the cursor to the end of the line.
moveToEndOfScreenLine: ->
@setScreenPosition([@getScreenRow(), Infinity])
@@ -352,6 +341,17 @@ class Cursor extends Model
if position = @getMoveNextWordBoundaryBufferPosition()
@setBufferPosition(position)
# Public: Moves the cursor to the beginning of the buffer line, skipping all
# whitespace.
skipLeadingWhitespace: ->
position = @getBufferPosition()
scanRange = @getCurrentLineBufferRange()
endOfLeadingWhitespace = null
@editor.scanInBufferRange /^[ \t]*/, scanRange, ({range}) ->
endOfLeadingWhitespace = range.end
@setBufferPosition(endOfLeadingWhitespace) if endOfLeadingWhitespace.isGreaterThan(position)
# Public: Retrieves the buffer position of where the current word starts.
#
# * `options` (optional) An {Object} with the following keys:
@@ -569,3 +569,11 @@ class Cursor extends Model
false
else
bufferPosition.column > firstCharacterColumn
# Public: Compare this cursor's buffer position to another cursor's buffer position.
#
# See {Point::compare} for more details.
#
# * `otherCursor`{Cursor} to compare against
compare: (otherCursor) ->
@getBufferPosition().compare(otherCursor.getBufferPosition())

View File

@@ -51,7 +51,7 @@ EditorComponent = React.createClass
{focused, showIndentGuide, showLineNumbers, visible} = @state
{editor, mini, cursorBlinkPeriod, cursorBlinkResumeDelay} = @props
maxLineNumberDigits = editor.getLineCount().toString().length
hasSelection = editor.getSelection()? and !editor.getSelection().isEmpty()
hasSelection = editor.getLastSelection()? and !editor.getLastSelection().isEmpty()
style = {}
if @performedInitialMeasurement
@@ -258,9 +258,9 @@ EditorComponent = React.createClass
getHiddenInputPosition: ->
{editor} = @props
{focused} = @state
return {top: 0, left: 0} unless @isMounted() and focused and editor.getCursor()?
return {top: 0, left: 0} unless @isMounted() and focused and editor.getLastCursor()?
{top, left, height, width} = editor.getCursor().getPixelRect()
{top, left, height, width} = editor.getLastCursor().getPixelRect()
width = 2 if width is 0 # Prevent autoscroll at the end of longest line
top -= editor.getScrollTop()
left -= editor.getScrollLeft()
@@ -403,8 +403,8 @@ EditorComponent = React.createClass
{parentView, editor, mini} = @props
@addCommandListeners
'core:move-left': -> editor.moveCursorLeft()
'core:move-right': -> editor.moveCursorRight()
'core:move-left': -> editor.moveLeft()
'core:move-right': -> editor.moveRight()
'core:select-left': -> editor.selectLeft()
'core:select-right': -> editor.selectRight()
'core:select-all': -> editor.selectAll()
@@ -415,8 +415,8 @@ EditorComponent = React.createClass
'core:cut': -> editor.cutSelectedText()
'core:copy': -> editor.copySelectedText()
'core:paste': -> editor.pasteText()
'editor:move-to-previous-word': -> editor.moveCursorToPreviousWord()
'editor:select-word': -> editor.selectWord()
'editor:move-to-previous-word': -> editor.moveToPreviousWord()
'editor:select-word': -> editor.selectWordsContainingCursors()
'editor:consolidate-selections': @consolidateSelections
'editor:delete-to-beginning-of-word': -> editor.deleteToBeginningOfWord()
'editor:delete-to-beginning-of-line': -> editor.deleteToBeginningOfLine()
@@ -424,18 +424,18 @@ EditorComponent = React.createClass
'editor:delete-to-end-of-word': -> editor.deleteToEndOfWord()
'editor:delete-line': -> editor.deleteLine()
'editor:cut-to-end-of-line': -> editor.cutToEndOfLine()
'editor:move-to-beginning-of-next-paragraph': -> editor.moveCursorToBeginningOfNextParagraph()
'editor:move-to-beginning-of-previous-paragraph': -> editor.moveCursorToBeginningOfPreviousParagraph()
'editor:move-to-beginning-of-screen-line': -> editor.moveCursorToBeginningOfScreenLine()
'editor:move-to-beginning-of-line': -> editor.moveCursorToBeginningOfLine()
'editor:move-to-end-of-screen-line': -> editor.moveCursorToEndOfScreenLine()
'editor:move-to-end-of-line': -> editor.moveCursorToEndOfLine()
'editor:move-to-first-character-of-line': -> editor.moveCursorToFirstCharacterOfLine()
'editor:move-to-beginning-of-word': -> editor.moveCursorToBeginningOfWord()
'editor:move-to-end-of-word': -> editor.moveCursorToEndOfWord()
'editor:move-to-beginning-of-next-word': -> editor.moveCursorToBeginningOfNextWord()
'editor:move-to-previous-word-boundary': -> editor.moveCursorToPreviousWordBoundary()
'editor:move-to-next-word-boundary': -> editor.moveCursorToNextWordBoundary()
'editor:move-to-beginning-of-next-paragraph': -> editor.moveToBeginningOfNextParagraph()
'editor:move-to-beginning-of-previous-paragraph': -> editor.moveToBeginningOfPreviousParagraph()
'editor:move-to-beginning-of-screen-line': -> editor.moveToBeginningOfScreenLine()
'editor:move-to-beginning-of-line': -> editor.moveToBeginningOfLine()
'editor:move-to-end-of-screen-line': -> editor.moveToEndOfScreenLine()
'editor:move-to-end-of-line': -> editor.moveToEndOfLine()
'editor:move-to-first-character-of-line': -> editor.moveToFirstCharacterOfLine()
'editor:move-to-beginning-of-word': -> editor.moveToBeginningOfWord()
'editor:move-to-end-of-word': -> editor.moveToEndOfWord()
'editor:move-to-beginning-of-next-word': -> editor.moveToBeginningOfNextWord()
'editor:move-to-previous-word-boundary': -> editor.moveToPreviousWordBoundary()
'editor:move-to-next-word-boundary': -> editor.moveToNextWordBoundary()
'editor:select-to-beginning-of-next-paragraph': -> editor.selectToBeginningOfNextParagraph()
'editor:select-to-beginning-of-previous-paragraph': -> editor.selectToBeginningOfPreviousParagraph()
'editor:select-to-end-of-line': -> editor.selectToEndOfLine()
@@ -446,17 +446,17 @@ EditorComponent = React.createClass
'editor:select-to-next-word-boundary': -> editor.selectToNextWordBoundary()
'editor:select-to-previous-word-boundary': -> editor.selectToPreviousWordBoundary()
'editor:select-to-first-character-of-line': -> editor.selectToFirstCharacterOfLine()
'editor:select-line': -> editor.selectLine()
'editor:select-line': -> editor.selectLinesContainingCursors()
'editor:transpose': -> editor.transpose()
'editor:upper-case': -> editor.upperCase()
'editor:lower-case': -> editor.lowerCase()
unless mini
@addCommandListeners
'core:move-up': -> editor.moveCursorUp()
'core:move-down': -> editor.moveCursorDown()
'core:move-to-top': -> editor.moveCursorToTop()
'core:move-to-bottom': -> editor.moveCursorToBottom()
'core:move-up': -> editor.moveUp()
'core:move-down': -> editor.moveDown()
'core:move-to-top': -> editor.moveToTop()
'core:move-to-bottom': -> editor.moveToBottom()
'core:page-up': -> editor.pageUp()
'core:page-down': -> editor.pageDown()
'core:select-up': -> editor.selectUp()
@@ -664,7 +664,7 @@ EditorComponent = React.createClass
onGutterShiftClick: (event) ->
{editor} = @props
clickedRow = @screenPositionForMouseEvent(event).row
tailPosition = editor.getSelection().getTailScreenPosition()
tailPosition = editor.getLastSelection().getTailScreenPosition()
if clickedRow < tailPosition.row
editor.selectToScreenPosition([clickedRow, 0])

File diff suppressed because it is too large Load Diff