Skip to content

Commit 2a168fd

Browse files
authored
Merge pull request #252 from StAmourD/ConsoleHistory
Console history
2 parents 39325f6 + f39f4b9 commit 2a168fd

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

keymaps/php-debug.cson

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@
3434
'alt-f6': 'php-debug:stepOver'
3535
'alt-f7': 'php-debug:stepIn'
3636
'alt-f8': 'php-debug:stepOut'
37+
38+
'atom-workspace .php-debug-console atom-text-editor':
39+
'alt-up': 'php-debug:navigatePreviousConsoleCommand'
40+
'alt-down': 'php-debug:navigateNextConsoleCommand'
41+
'up': 'php-debug:navigatePreviousConsoleCommand'
42+
'down': 'php-debug:navigateNextConsoleCommand'

lib/console/php-debug-console-view.coffee

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class PhpDebugConsoleView extends ScrollView
2323
super
2424
@GlobalContext = params.context
2525
@visible = false
26+
@stack = []
27+
@curCommand = -1
2628
curHeight = atom.config.get('php-debug.currentConsoleHeight')
2729
if (curHeight)
2830
this.element.style.height = curHeight
@@ -86,7 +88,6 @@ class PhpDebugConsoleView extends ScrollView
8688
@visible
8789

8890
setVisible: (@visible) =>
89-
9091
if @visible
9192
@panel.show()
9293
else
@@ -97,13 +98,27 @@ class PhpDebugConsoleView extends ScrollView
9798
expression = @consoleCommandLine
9899
.getModel()
99100
.getText()
101+
# enqueue entered command, limit stack size and update index
102+
@stack.push expression
103+
@stack.shift() if @stack.length > 20
104+
@curCommand = @stack.length
100105
@GlobalContext.notifyConsoleMessage(">" + expression)
101106
@GlobalContext.getCurrentDebugContext()?.evalExpression(expression)
102-
103107
@consoleCommandLine
104108
.getModel()
105109
.setText('')
106110
event.cancel()
107111

108112
isEqual: (other) ->
109113
other instanceof PhpDebugConsoleView
114+
115+
prevCommand: () ->
116+
return unless @stack.length
117+
@curCommand -= 1 if @curCommand > 0
118+
@consoleCommandLine.getModel().setText(@stack[@curCommand])
119+
120+
nextCommand: () ->
121+
return unless @stack.length
122+
len = @stack.length
123+
@curCommand += 1 if @curCommand < len
124+
@consoleCommandLine.getModel().setText(if @curCommand < len then @stack[@curCommand] else '')

lib/php-debug.coffee

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ module.exports = PhpDebug =
157157
@subscriptions.add atom.commands.add 'atom-workspace', 'php-debug:stepOut': => @stepOut()
158158
@subscriptions.add atom.commands.add 'atom-workspace', 'php-debug:clearAllBreakpoints': => @clearAllBreakpoints()
159159
@subscriptions.add atom.commands.add 'atom-workspace', 'php-debug:clearAllWatchpoints': => @clearAllWatchpoints()
160+
@subscriptions.add atom.commands.add 'atom-workspace', 'php-debug:navigatePreviousConsoleCommand': => @navigatePreviousConsoleCommand()
161+
@subscriptions.add atom.commands.add 'atom-workspace', 'php-debug:navigateNextConsoleCommand': => @navigateNextConsoleCommand()
160162
@subscriptions.add atom.workspace.addOpener (filePath) =>
161163
switch filePath
162164
when PhpDebugContextUri
@@ -480,3 +482,9 @@ module.exports = PhpDebug =
480482
marker = @addBreakpointMarker(line, editor)
481483
breakpoint.setMarker(marker)
482484
@GlobalContext.addBreakpoint breakpoint
485+
486+
navigatePreviousConsoleCommand: ->
487+
@consoleView.prevCommand()
488+
489+
navigateNextConsoleCommand: ->
490+
@consoleView.nextCommand()

0 commit comments

Comments
 (0)