mirror of
https://github.com/atom/atom.git
synced 2026-02-09 14:15:24 -05:00
x command loops over all selected regions
This commit is contained in:
@@ -9,22 +9,19 @@ class SelectAllMatches extends Command
|
||||
@regex = new RegExp(pattern)
|
||||
|
||||
execute: (editor) ->
|
||||
selectedText = editor.getSelectedText()
|
||||
selectionStartIndex = editor.buffer.characterIndexForPosition(editor.getSelection().getBufferRange().start)
|
||||
|
||||
matchingRanges = @findMatchingRanges(editor, selectedText, selectionStartIndex)
|
||||
return unless matchingRanges.length
|
||||
editor.setSelectionBufferRange(matchingRanges[0])
|
||||
editor.addSelectionForBufferRange(range) for range in matchingRanges[1..]
|
||||
rangesToSelect = []
|
||||
for selection in editor.getSelections()
|
||||
selectedText = selection.getText()
|
||||
selectionStartIndex = editor.buffer.characterIndexForPosition(selection.getBufferRange().start)
|
||||
for range in @findMatchingRanges(editor, selectedText, selectionStartIndex)
|
||||
rangesToSelect.push(range)
|
||||
|
||||
editor.clearSelections()
|
||||
editor.addSelectionForBufferRange(range) for range in rangesToSelect
|
||||
|
||||
findMatchingRanges: (editor, text, startIndex) ->
|
||||
console.log text
|
||||
return [] unless match = text.match(@regex)
|
||||
|
||||
console.log match
|
||||
console.log match[0]
|
||||
|
||||
matchStartIndex = startIndex + match.index
|
||||
matchEndIndex = matchStartIndex + match[0].length
|
||||
|
||||
|
||||
@@ -12,17 +12,31 @@ class CompositeSeleciton
|
||||
|
||||
getSelections: -> new Array(@selections...)
|
||||
|
||||
clearSelections: ->
|
||||
for selection in @getSelections()[1..]
|
||||
selection.cursor.remove()
|
||||
|
||||
@getLastSelection().clearSelection()
|
||||
|
||||
addSelectionForCursor: (cursor) ->
|
||||
selection = new Selection({@editor, cursor})
|
||||
@selections.push(selection)
|
||||
@editor.lines.append(selection)
|
||||
|
||||
addSelectionForBufferRange: (bufferRange, options) ->
|
||||
cursor = @editor.compositeCursor.addCursor()
|
||||
selections = @getSelections()
|
||||
cursor = if selections.length == 1 and selections[0].isEmpty()
|
||||
selections[0].cursor
|
||||
else
|
||||
@editor.compositeCursor.addCursor()
|
||||
|
||||
@selectionForCursor(cursor).setBufferRange(bufferRange, options)
|
||||
|
||||
removeSelectionForCursor: (cursor) ->
|
||||
_.remove(@selections, @selectionForCursor(cursor))
|
||||
selection = @selectionForCursor(cursor)
|
||||
selection.cursor = null
|
||||
selection.remove()
|
||||
_.remove(@selections, selection)
|
||||
|
||||
selectionForCursor: (cursor) ->
|
||||
_.find @selections, (selection) -> selection.cursor == cursor
|
||||
|
||||
@@ -33,7 +33,7 @@ class Cursor extends View
|
||||
remove: ->
|
||||
@editor.compositeCursor.removeCursor(this)
|
||||
@editor.compositeSelection.removeSelectionForCursor(this)
|
||||
super()
|
||||
super
|
||||
|
||||
setScreenPosition: (position, options={}) ->
|
||||
position = Point.fromObject(position)
|
||||
|
||||
@@ -365,6 +365,7 @@ class Editor extends View
|
||||
selectUp: -> @compositeSelection.selectUp()
|
||||
selectDown: -> @compositeSelection.selectDown()
|
||||
selectToScreenPosition: (position) -> @compositeSelection.selectToScreenPosition(position)
|
||||
clearSelections: -> @compositeSelection.clearSelections()
|
||||
|
||||
setText: (text) -> @buffer.setText(text)
|
||||
getText: -> @buffer.getText()
|
||||
|
||||
@@ -43,6 +43,8 @@ class Selection extends View
|
||||
@updateAppearance()
|
||||
|
||||
updateAppearance: ->
|
||||
return unless @cursor
|
||||
|
||||
@clearRegions()
|
||||
|
||||
range = @getScreenRange()
|
||||
|
||||
Reference in New Issue
Block a user