Skip to content

Commit

Permalink
Suggestions are now updated if cursor is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro270707 committed Apr 15, 2024
1 parent a756a63 commit 52917dd
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class GuiChatSuggestions extends Gui {
private List<Suggestion> suggestions = new ArrayList<>();
private int scroll = 0;
GuiTooltip tooltip;
private int oldCursor;

public boolean hidden = false;

Expand All @@ -72,6 +73,7 @@ public GuiChatSuggestions(Minecraft mc, TextFieldEditor textFieldEditor, ITextFi
this.tablessMessage = this.textField.getText();
this.tablessCursor = this.editor.getCursor();
this.tooltip = new GuiTooltip(this.mc);
this.oldCursor = this.editor.getCursor();
Commander.serverSuggestions = new JsonObject();
}

Expand Down Expand Up @@ -270,6 +272,10 @@ private void finishUpdatingSuggestions() {
}

public void updateScreen(int dWheel) {
if (this.oldCursor != this.editor.getCursor()) {
this.oldCursor = this.editor.getCursor();
this.updateSuggestions();
}
this.finishUpdatingSuggestions();
int cursorX = GuiHelper.getScaledMouseX(this.mc);
int cursorY = GuiHelper.getScaledMouseY(this.mc);
Expand Down Expand Up @@ -345,6 +351,7 @@ public void cycleToSuggestion(int index) {
Suggestion suggestion = this.suggestions.get(this.commandIndex);
this.editor.setText(suggestion.apply(this.tablessMessage));
this.editor.setCursor(suggestion.getRange().getStart() + suggestion.getText().length());
this.oldCursor = this.editor.getCursor();
if (this.commandIndex >= this.scroll + Commander.maxSuggestions) {
this.scroll = this.commandIndex - Commander.maxSuggestions + 1;
} else if (this.commandIndex < this.scroll) {
Expand Down

0 comments on commit 52917dd

Please sign in to comment.