X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=atom-ax-pipe.git;a=blobdiff_plain;f=lib%2Fcommand-view.coffee;h=8ac7c49e34a59c90696baab07540892494e05ced;hp=dd2eebb6a6fef824445ddf62851fd029ecaaa91e;hb=7e645d70db173f5d30991bc2e998bd1eb832fce4;hpb=d364e3bf38055fc6672bfac8ace5eb3051210ea0 diff --git a/lib/command-view.coffee b/lib/command-view.coffee index dd2eebb..8ac7c49 100644 --- a/lib/command-view.coffee +++ b/lib/command-view.coffee @@ -20,13 +20,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()