Skip to content

Instantly share code, notes, and snippets.

View Fanoflix's full-sized avatar
🌏
Its hustlin' time

Muhammad Ammar Fanoflix

🌏
Its hustlin' time
View GitHub Profile
@Fanoflix
Fanoflix / ctrl-enter.ts
Last active October 14, 2024 08:10
Ctrl + Enter to submit Form (Typescript)
document.body.addEventListener("keydown", (e: KeyboardEvent) => {
if (!(e.key === "Enter" && (e.metaKey || e.ctrlKey))) return
if ('form' in e.target) {
const formElement = e.target.form as HTMLFormElement;
formElement?.submit(); // or formElement?.requestSubmit() depending on your usecase
}
})
@Fanoflix
Fanoflix / getHighlightedText.ts
Last active June 22, 2023 09:33
Method to get highlighted/selection text
const getSelectionText = () => {
const selectionText = window.getSelection()?.toString()
if (selectionText?.length) return selectionText
}