mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Show preview list when X x operation completes
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
CommandInterpreter = require 'command-panel/command-interpreter'
|
||||
RegexAddress = require 'command-panel/commands/regex-address'
|
||||
CompositeCommand = require 'command-panel/commands/composite-command'
|
||||
PreviewItem = require 'command-panel/preview-item'
|
||||
Editor = require 'editor'
|
||||
{SyntaxError} = require('pegjs').parser
|
||||
|
||||
@@ -16,6 +17,9 @@ class CommandPanel extends View
|
||||
else
|
||||
@instance = new CommandPanel(rootView)
|
||||
|
||||
@deactivate: ->
|
||||
@instance.detach()
|
||||
|
||||
@serialize: ->
|
||||
text: @instance.miniEditor.getText()
|
||||
visible: @instance.hasParent()
|
||||
@@ -27,8 +31,10 @@ class CommandPanel extends View
|
||||
|
||||
@content: ->
|
||||
@div class: 'command-panel', =>
|
||||
@div ':', class: 'prompt', outlet: 'prompt'
|
||||
@subview 'miniEditor', new Editor(mini: true)
|
||||
@ol class: 'preview-list', outlet: 'previewList'
|
||||
@div class: 'prompt-and-editor', =>
|
||||
@div ':', class: 'prompt', outlet: 'prompt'
|
||||
@subview 'miniEditor', new Editor(mini: true)
|
||||
|
||||
commandInterpreter: null
|
||||
history: null
|
||||
@@ -54,16 +60,25 @@ class CommandPanel extends View
|
||||
|
||||
attach: (text='') ->
|
||||
@rootView.append(this)
|
||||
@previewList.hide()
|
||||
@miniEditor.focus()
|
||||
@miniEditor.setText(text)
|
||||
|
||||
detach: ->
|
||||
@rootView.focus()
|
||||
if @previewedOperations
|
||||
operation.destroy() for operation in @previewedOperations
|
||||
super
|
||||
|
||||
execute: (command = @miniEditor.getText()) ->
|
||||
try
|
||||
@commandInterpreter.eval(command, @rootView.getActiveEditSession())
|
||||
@commandInterpreter.eval(command, @rootView.getActiveEditSession()).done (operations) =>
|
||||
@history.push(command)
|
||||
@historyIndex = @history.length
|
||||
if operations?.length
|
||||
@populatePreviewList(operations)
|
||||
else
|
||||
@detach()
|
||||
catch error
|
||||
if error instanceof SyntaxError
|
||||
@flashError()
|
||||
@@ -71,9 +86,12 @@ class CommandPanel extends View
|
||||
else
|
||||
throw error
|
||||
|
||||
@history.push(command)
|
||||
@historyIndex = @history.length
|
||||
@detach()
|
||||
populatePreviewList: (operations) ->
|
||||
@previewedOperations = operations
|
||||
@previewList.empty()
|
||||
for operation in operations
|
||||
@previewList.append(new PreviewItem(operation))
|
||||
@previewList.show()
|
||||
|
||||
navigateBackwardInHistory: ->
|
||||
return if @historyIndex == 0
|
||||
|
||||
@@ -21,10 +21,10 @@ class CompositeCommand
|
||||
@executeCommands(remainingCommands, project, editSession, nextRanges).done ->
|
||||
deferred.resolve()
|
||||
else
|
||||
editSession?.clearAllSelections() unless currentCommand.preserveSelections
|
||||
if currentCommand.previewOperations
|
||||
deferred.resolve(operations)
|
||||
else
|
||||
editSession?.clearAllSelections() unless currentCommand.preserveSelections
|
||||
for operation in operations
|
||||
operation.execute(editSession)
|
||||
operation.destroy()
|
||||
|
||||
@@ -14,6 +14,9 @@ class Operation
|
||||
@buffer.change(@getBufferRange(), @newText) if @newText
|
||||
editSession.addSelectionForBufferRange(@getBufferRange()) unless @preserveSelection
|
||||
|
||||
preview: ->
|
||||
"sad :-("
|
||||
|
||||
destroy: ->
|
||||
@buffer.release()
|
||||
@anchorRange.destroy()
|
||||
8
src/extensions/command-panel/preview-item.coffee
Normal file
8
src/extensions/command-panel/preview-item.coffee
Normal file
@@ -0,0 +1,8 @@
|
||||
{View} = require 'space-pen'
|
||||
|
||||
module.exports =
|
||||
class PreviewItem extends View
|
||||
@content: (operation) ->
|
||||
@li =>
|
||||
@span operation.getPath()
|
||||
@span operation.preview()
|
||||
Reference in New Issue
Block a user