Skip to content
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

web: selecting the programming language by pressing Enter key #7484

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

KYash03
Copy link

@KYash03 KYash03 commented Feb 5, 2025

Fixes: #7284

This PR adds support for selecting the programming language by pressing the Enter key.

@KYash03 KYash03 closed this Feb 5, 2025
@KYash03 KYash03 reopened this Feb 5, 2025
@KYash03 KYash03 changed the title Selecting the programming language by pressing Enter key web: selecting the programming language by pressing Enter key Feb 5, 2025
@thecodrr
Copy link
Contributor

thecodrr commented Feb 7, 2025

Thank you!

@@ -236,6 +236,20 @@ type LanguageSelectorProps = {
function LanguageSelector(props: LanguageSelectorProps) {
const { onLanguageSelected, selectedLanguage, onClose } = props;
const [languages, setLanguages] = useState(Languages);
const [searchQuery, setSearchQuery] = useState("");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This state is unnecessary.

@@ -258,9 +272,15 @@ function LanguageSelector(props: LanguageSelectorProps) {
zIndex: 999,
mt: 1
}}
value={searchQuery}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary.

const query = e.target.value.toLowerCase();
setSearchQuery(query);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary.

onChange={(e) => {
if (!e.target.value) return setLanguages(Languages);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this?

Comment on lines +241 to +252
const onKeyDown = useCallback(
(e: React.KeyboardEvent) => {
if (e.key === "Enter" && languages.length > 0) {
onLanguageSelected(languages[0].filename);
e.preventDefault();
} else if (e.key === "Escape") {
onClose();
e.preventDefault();
}
},
[languages, onLanguageSelected, onClose]
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be inline. No need for useCallback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Selecting the programming language by pressing Enter key
2 participants