-
Notifications
You must be signed in to change notification settings - Fork 10
Edited the teminal movements #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -97,6 +97,8 @@ const Terminal = ({ isOpen, onClose }) => { | |||||
|
|
||||||
| let input = ''; | ||||||
| let currentDir = 'home'; | ||||||
| let cursorPos = 0; | ||||||
|
|
||||||
| term.onKey(({ key, domEvent }) => { | ||||||
| if (domEvent.key === 'Enter') { | ||||||
| term.write('\r\n'); | ||||||
|
|
@@ -107,10 +109,18 @@ const Terminal = ({ isOpen, onClose }) => { | |||||
| input = ''; | ||||||
| setTimeout(() => printPrompt(term, currentDir), 10); | ||||||
| } else if (domEvent.key === 'Backspace') { | ||||||
| if (input.length > 0) { | ||||||
| input = input.slice(0, -1); | ||||||
| term.write('\b \b'); | ||||||
| } | ||||||
| if (cursorPos > 0) { | ||||||
| input = input.slice(0, cursorPos - 1) + input.slice(cursorPos); | ||||||
| cursorPos--; | ||||||
|
|
||||||
| term.write('\x1b[2K\r'); | ||||||
| printPrompt(term, currentDir); | ||||||
| term.write(input); | ||||||
| const moveLeft = input.length - cursorPos; | ||||||
| if (moveLeft > 0) { | ||||||
| term.write(`\x1b[${moveLeft}D`); | ||||||
| } | ||||||
| } | ||||||
| } else if (domEvent.key === 'Tab') { | ||||||
| domEvent.preventDefault(); | ||||||
| const completed = handleTabCompletion(input, currentDir); | ||||||
|
|
@@ -121,10 +131,45 @@ const Terminal = ({ isOpen, onClose }) => { | |||||
| input = completed; | ||||||
| term.write(input); | ||||||
| } | ||||||
| } else if (domEvent.key.length === 1) { | ||||||
| input += key; | ||||||
| term.write(key); | ||||||
| } | ||||||
| else if (domEvent.key.length === 1) { | ||||||
| input = input.slice(0, cursorPos) + key + input.slice(cursorPos); | ||||||
| cursorPos++; | ||||||
|
|
||||||
| term.write('\x1b[K'); | ||||||
| term.write(input.slice(cursorPos - 1)); | ||||||
|
|
||||||
| const charsToMoveBack = input.length - cursorPos; | ||||||
| if (charsToMoveBack > 0) { | ||||||
| term.write(`\x1b[${charsToMoveBack}D`); | ||||||
| } | ||||||
| } | ||||||
| else if(domEvent.key == 'ArrowLeft'){ | ||||||
|
||||||
| else if(domEvent.key == 'ArrowLeft'){ | |
| else if(domEvent.key === 'ArrowLeft'){ |
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use strict equality (===) instead of loose equality (==) for comparison. This prevents type coercion issues and follows JavaScript best practices.
| else if(domEvent.key == 'ArrowRight'){ | |
| else if(domEvent.key === 'ArrowRight'){ |
Copilot
AI
Sep 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent spacing around parentheses and braces. Add spaces after 'if' and around parentheses for consistency with the rest of the codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cursorPos variable should be reset to 0 when input is cleared (after Enter key is pressed) to maintain proper cursor positioning for new commands.