Skip to content

Commit

Permalink
Merge pull request #56 from jeffsieu/branch-slash-focus
Browse files Browse the repository at this point in the history
Add slash to focus on command input
  • Loading branch information
koh-jx authored Oct 18, 2021
2 parents 279cab7 + eb59ba8 commit 0764256
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/ui/CommandBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public CommandBox(CommandExecutor commandExecutor) {
commandTextField.textProperty().addListener((unused1, unused2, unused3) -> setStyleToDefault());
}

public void focus() {
commandTextField.requestFocus();
}

/**
* Handles the Enter button pressed event.
*/
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import javafx.fxml.FXML;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextInputControl;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.StackPane;
Expand Down Expand Up @@ -37,6 +38,7 @@ public class MainWindow extends UiPart<Stage> {
private PersonListPanel personListPanel;
private ResultDisplay resultDisplay;
private HelpWindow helpWindow;
private CommandBox commandBox;

@FXML
private StackPane commandBoxPlaceholder;
Expand Down Expand Up @@ -110,6 +112,14 @@ private void setAccelerator(MenuItem menuItem, KeyCombination keyCombination) {
event.consume();
}
});

getRoot().addEventFilter(KeyEvent.KEY_RELEASED, event -> {
if (!(event.getTarget() instanceof TextInputControl) && event.getCode().equals(KeyCode.SLASH)) {
event.consume();

commandBox.focus();
}
});
}

/**
Expand All @@ -134,7 +144,7 @@ void fillInnerParts() {
StatusBarFooter statusBarFooter = new StatusBarFooter(logic.getAddressBookFilePath());
statusBarPlaceholder.getChildren().add(statusBarFooter.getRoot());

CommandBox commandBox = new CommandBox(this::executeCommand);
commandBox = new CommandBox(this::executeCommand);
commandBoxPlaceholder.getChildren().add(commandBox.getRoot());
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/view/CommandBox.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
<?import javafx.scene.layout.StackPane?>

<StackPane styleClass="stack-pane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<TextField fx:id="commandTextField" onAction="#handleCommandEntered" promptText="Enter command here..."/>
<TextField fx:id="commandTextField" onAction="#handleCommandEntered" promptText="Enter command here... (Press / to focus)"/>
</StackPane>

0 comments on commit 0764256

Please sign in to comment.