diff --git a/Assets/Scripts/UI/terminal/terminal_controls.gd b/Assets/Scripts/UI/terminal/terminal_controls.gd index 879b9e9..57100d1 100644 --- a/Assets/Scripts/UI/terminal/terminal_controls.gd +++ b/Assets/Scripts/UI/terminal/terminal_controls.gd @@ -8,7 +8,7 @@ class_name TerminalControls @onready var scroll: ScrollContainer = $MarginContainer/ScrollContainer @export var terminalLine: RichTextLabel -var terminalHistory: Array[String] = [""] +var terminalHistory: Array[String] = [] var historyIndex: int = -1 var cursorIndexFromEnd: int = 0 @@ -89,7 +89,7 @@ func EnterCommand() -> void: if userInput != "": terminalHistory.append(userInput) - historyIndex = 0 + historyIndex = terminalHistory.size() cursorIndexFromEnd = 0 match parts[0]: @@ -176,13 +176,17 @@ func MoveCursorRight(): func NavigateHistory(direction: int): if terminalHistory.is_empty(): return - - historyIndex += direction - historyIndex = clamp(historyIndex, 0, terminalHistory.size() - 1) - var historyCommand = terminalHistory[historyIndex] + historyIndex -= direction + + if historyIndex >= terminalHistory.size(): + historyIndex = terminalHistory.size() + terminalLine.text = "user@work "+ directory + " " + else: + historyIndex = clamp(historyIndex, 0, terminalHistory.size() - 1) + var historyCommand = terminalHistory[historyIndex] + terminalLine.text = "user@work "+ directory + " " + historyCommand - terminalLine.text = "user@work "+ directory + " " + historyCommand UpdateCaretPos() func CreateHistoryEntry(content: String) -> void: