Skip to content

Commit

Permalink
Merge pull request #55 from UCSDOalads/commandModeBranch
Browse files Browse the repository at this point in the history
fix a bug in command mode
  • Loading branch information
UltimatePea authored Mar 30, 2017
2 parents eab7825 + 7fce8af commit cf75a20
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/ui/KeyHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class KeyHandler implements KeyListener {
private PaintPanel paintPanel;
private boolean inCommandMode;
Interpreter interpreter ;
private boolean isCurrentDirectionNext;


JTextField textField;
Expand Down Expand Up @@ -81,9 +82,10 @@ public void keyTyped(KeyEvent e) {

//record command

while(commandHistoryIter.hasNext())
while(commandHistoryIter.hasNext()){
this.commandHistoryIter.next();

}
isCurrentDirectionNext = true;
commandHistoryIter.add(textField.getText());

executeCommand(textField.getText().substring(PROMPT.length()));
Expand All @@ -102,12 +104,20 @@ public void keyPressed(KeyEvent e) {
exitCommandMode();

//if it is up arrow, go back in history
} else if (e.getKeyCode() == KeyEvent.VK_UP){
} else if (e.getKeyCode() == KeyEvent.VK_UP ){
if(commandHistoryIter.hasPrevious()){
if(isCurrentDirectionNext){
commandHistoryIter.previous();
}
isCurrentDirectionNext = false;
this.textField.setText(commandHistoryIter.previous());
}
} else if (e.getKeyCode() == KeyEvent.VK_DOWN){
} else if (e.getKeyCode() == KeyEvent.VK_DOWN ){
if(commandHistoryIter.hasNext()){
if(!isCurrentDirectionNext){
commandHistoryIter.next();
}
isCurrentDirectionNext = true;
this.textField.setText(commandHistoryIter.next());
}
}
Expand Down

0 comments on commit cf75a20

Please sign in to comment.