Skip to content

Commit

Permalink
chat up and down arrow message history scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimo-s committed Dec 2, 2023
1 parent edbbef8 commit 65e94b7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public abstract class AbstractChatTabController extends TabController {
private static final String ACTION_CSS_CLASS = "action";
private static final String MESSAGE_CSS_CLASS = "message";

protected final List<String> messageHistory = new ArrayList<>();;
protected final LoginService loginService;
protected final ChatService chatService;
protected final PlayerService playerService;
Expand Down Expand Up @@ -379,6 +380,8 @@ public void onSendMessage() {
sendMessage();
}

messageHistory.add(text);

hideEmoticonsWindow();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javafx.collections.ListChangeListener;
import javafx.collections.ListChangeListener.Change;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Hyperlink;
Expand Down Expand Up @@ -64,6 +65,8 @@ public class ChannelTabController extends AbstractChatTabController {
private static final int TOPIC_CHARACTERS_LIMIT = 350;

private final PlatformService platformService;
private final AudioService audioService;
private int curMessageHistoryIndex = 0;

public Tab root;
public SplitPane splitPane;
Expand Down Expand Up @@ -132,7 +135,10 @@ protected void onInitialize() {
.or(topicTextField.visibleProperty())
.when(showing));

root.textProperty().bind(channelName.map(name -> name.replaceFirst("^#", "")).when(attached));
messageTextField.setOnKeyPressed(this::onUpOrDownArrowKeyClick);

root.idProperty().bind(channelName.when(showing));
root.textProperty().bind(channelName.map(name -> name.replaceFirst("^#", "")).when(showing));

chatUserListController.chatChannelProperty().bind(chatChannel.when(showing));

Expand Down Expand Up @@ -189,6 +195,22 @@ public AutoCompletionHelper getAutoCompletionHelper() {
.collect(Collectors.toList()));
}

private void onUpOrDownArrowKeyClick(KeyEvent event){
if(event.getCode() == KeyCode.UP){
if(curMessageHistoryIndex+1 <= messageHistory.size()){
messageTextField.setText(messageHistory.get(messageHistory.size() - curMessageHistoryIndex - 1));
curMessageHistoryIndex++;
}
} else if(event.getCode() == KeyCode.DOWN){
if(curMessageHistoryIndex-1 >= 0){
curMessageHistoryIndex--;
messageTextField.setText(messageHistory.get(messageHistory.size() - curMessageHistoryIndex - 1));
}
} else {
curMessageHistoryIndex = 0;
}
}

private void highlightText(String newValue) {
if (StringUtils.isBlank(newValue)) {
callJsMethod("removeHighlight");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public class ChatUserItemController extends NodeController<Node> {
protected void onInitialize() {
initializeTooltips();
bindProperties();


}

private void initializeTooltips() {
Expand Down

0 comments on commit 65e94b7

Please sign in to comment.