Skip to content

Commit 9707da8

Browse files
authored
Merge pull request pterodactyl#2686 from occanowey/feature/command_history
Keep cursor at the end of the line when going through command history
2 parents 085fa8d + 76e3bca commit 9707da8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

resources/scripts/components/server/Console.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,16 @@ export default () => {
8080
TERMINAL_PRELUDE + 'Server marked as ' + state + '...\u001b[0m',
8181
);
8282

83-
const handleCommandKeydown = (e: React.KeyboardEvent<HTMLInputElement>) => {
83+
const handleCommandKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
8484
if (e.key === 'ArrowUp') {
8585
const newIndex = Math.min(historyIndex + 1, history!.length - 1);
8686

8787
setHistoryIndex(newIndex);
8888
e.currentTarget.value = history![newIndex] || '';
89+
90+
// By default up arrow will also bring the cursor to the start of the line,
91+
// so we'll preventDefault to keep it at the end.
92+
e.preventDefault();
8993
}
9094

9195
if (e.key === 'ArrowDown') {
@@ -185,7 +189,7 @@ export default () => {
185189
type={'text'}
186190
disabled={!instance || !connected}
187191
css={tw`bg-transparent text-neutral-100 p-2 pl-0 w-full`}
188-
onKeyDown={e => handleCommandKeydown(e)}
192+
onKeyDown={handleCommandKeyDown}
189193
/>
190194
</div>
191195
</div>

0 commit comments

Comments
 (0)