X-Git-Url: https://arthur.barton.de/gitweb/?p=atom-ax-pipe.git;a=blobdiff_plain;f=lib%2Fcommand-view.coffee;h=0b9e865b82e7b775d5948f5ef3bfed0b54dff338;hp=dd2eebb6a6fef824445ddf62851fd029ecaaa91e;hb=6792e634b736183ad242bd898bc2bbd36363c928;hpb=5b9c1c2b0357ada85a9141a58a32c9f057a14980 diff --git a/lib/command-view.coffee b/lib/command-view.coffee index dd2eebb..0b9e865 100644 --- a/lib/command-view.coffee +++ b/lib/command-view.coffee @@ -1,4 +1,5 @@ -{View, EditorView} = require 'atom' +{View, TextEditorView} = require 'atom-space-pen-views' + module.exports = class CommandView extends View @@ -12,7 +13,7 @@ class CommandView extends View @content: -> @div class: 'pipe-command', => - @subview 'commandLine', new EditorView( + @subview 'commandLine', new TextEditorView( mini: true placeholderText: @samplePlaceholder() ) @@ -20,13 +21,36 @@ class CommandView extends View @samplePlaceholder: -> @placeholders[Math.floor(Math.random()*@placeholders.length)] - initialize: (callback) -> + initialize: (history, callback) -> + historyPos = history.length + cur = '' + @on 'core:cancel core:close', => callback(null) @detach() @on 'core:confirm', => callback(@commandLine.getText()) @detach() + @commandLine.on 'keydown', (e) => + if history.length is 0 then return + + switch e.keyCode + when 38 # up + unless historyPos <= 0 + historyPos-- + @commandLine.setText history[historyPos] + + when 40 # down + if historyPos >= history.length-1 + historyPos = history.length + @commandLine.setText cur + else + historyPos++ + @commandLine.setText history[historyPos] + + else + if historyPos >= history.length + cur = @commandLine.getText() atom.workspaceView.append(this) @commandLine.focus()