mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-22 00:19:24 +03:00
Bugfix: Don't clear selections after running an x
command w/ no matches
Operations now return a range to select rather than actually performing a selection in `execute`. This allows the composite command to aggregate all ranges to select and only change the selection if it's non empty. Before we had to clear the selections ahead of time and then rely on each operation to imperatively add its selection. This is easier to control. It also ensures that when we execute a previewed operation, we don't add a selection but instead change the selection.
This commit is contained in:
parent
40c4373629
commit
8b743b90a2
@ -232,6 +232,16 @@ describe "CommandInterpreter", ->
|
||||
expect(selections[2].getBufferRange()).toEqual [[6,34], [6,41]]
|
||||
expect(selections[3].getBufferRange()).toEqual [[6,56], [6,63]]
|
||||
|
||||
describe "when nothing is matched", ->
|
||||
it "preserves the existing selection", ->
|
||||
previousSelections = null
|
||||
waitsForPromise ->
|
||||
previousSelections = editSession.getSelectedBufferRanges()
|
||||
interpreter.eval(',x/this will match nothing', editSession)
|
||||
|
||||
runs ->
|
||||
expect(editSession.getSelectedBufferRanges()).toEqual previousSelections
|
||||
|
||||
describe "substitution", ->
|
||||
it "does nothing if there are no matches", ->
|
||||
waitsForPromise ->
|
||||
@ -333,7 +343,7 @@ describe "CommandInterpreter", ->
|
||||
expect(operations.length).toBeGreaterThan 3
|
||||
for operation in operations
|
||||
editSession = project.buildEditSessionForPath(operation.getPath())
|
||||
operation.execute(editSession)
|
||||
editSession.setSelectedBufferRange(operation.execute(editSession))
|
||||
expect(editSession.getSelectedText()).toMatch /a+/
|
||||
editSession.destroy()
|
||||
operation.destroy()
|
||||
|
@ -24,10 +24,13 @@ class CompositeCommand
|
||||
if currentCommand.previewOperations
|
||||
deferred.resolve(operations)
|
||||
else
|
||||
editSession?.clearAllSelections() unless currentCommand.preserveSelections
|
||||
bufferRanges = []
|
||||
for operation in operations
|
||||
operation.execute(editSession)
|
||||
bufferRange = operation.execute(editSession)
|
||||
bufferRanges.push(bufferRange) if bufferRange
|
||||
operation.destroy()
|
||||
if bufferRanges.length and not currentCommand.preserveSelections
|
||||
editSession.setSelectedBufferRanges(bufferRanges)
|
||||
deferred.resolve()
|
||||
|
||||
deferred.promise()
|
||||
|
@ -14,7 +14,7 @@ class Operation
|
||||
|
||||
execute: (editSession) ->
|
||||
@buffer.change(@getBufferRange(), @newText) if @newText
|
||||
editSession.addSelectionForBufferRange(@getBufferRange()) unless @preserveSelection
|
||||
@getBufferRange() unless @preserveSelection
|
||||
|
||||
preview: ->
|
||||
range = @anchorRange.getBufferRange()
|
||||
|
@ -58,7 +58,8 @@ class PreviewList extends View
|
||||
executeSelectedOperation: ->
|
||||
operation = @getSelectedOperation()
|
||||
editSession = @rootView.open(operation.getPath())
|
||||
operation.execute(editSession)
|
||||
bufferRange = operation.execute(editSession)
|
||||
editSession.setSelectedBufferRange(bufferRange) if bufferRange
|
||||
@rootView.focus()
|
||||
false
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user