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

feat: added a shortcut Ctrl/Cmd+Enter to import cURL #3933

Draft
wants to merge 4 commits into
base: release/2024.3.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 27 additions & 2 deletions packages/hoppscotch-common/src/components/http/ImportCurl.vue
Expand Up @@ -53,12 +53,18 @@
<span class="flex space-x-2">
<HoppButtonPrimary
ref="importButton"
v-tippy="{ theme: 'tooltip', delay: [500, 20], allowHTML: true }"
:label="`${t('import.title')}`"
:title="`${t(
'import.title'
)} <kbd>${getSpecialKey()}</kbd><kbd>↩</kbd>`"
outline
@click="handleImport"
/>
<HoppButtonSecondary
:label="`${t('action.cancel')}`"
v-tippy="{ theme: 'tooltip', delay: [500, 20], allowHTML: true }"
:title="`${t('action.cancel')} <kbd>ESC</kbd>`"
outline
filled
@click="hideModal"
Expand All @@ -78,7 +84,7 @@
</template>

<script setup lang="ts">
import { reactive, ref, watch } from "vue"
import { markRaw, reactive, ref, watch } from "vue"
import { refAutoReset } from "@vueuse/core"
import { useCodemirror } from "@composables/codemirror"
import { useI18n } from "@composables/i18n"
Expand All @@ -93,12 +99,14 @@ import IconWrapText from "~icons/lucide/wrap-text"
import IconClipboard from "~icons/lucide/clipboard"
import IconCheck from "~icons/lucide/check"
import IconTrash2 from "~icons/lucide/trash-2"
import { getPlatformSpecialKey as getSpecialKey } from "~/helpers/platformutils"
import { platform } from "~/platform"
import { RESTTabService } from "~/services/tab/rest"
import { useService } from "dioc/vue"
import { useNestedSetting } from "~/composables/settings"
import { toggleNestedSetting } from "~/newstore/settings"
import { EditorView } from "@codemirror/view"
import { EditorView, keymap } from "@codemirror/view"
import { Prec } from "@codemirror/state"

const t = useI18n()

Expand Down Expand Up @@ -126,6 +134,22 @@ useCodemirror(
completer: null,
environmentHighlights: false,
onInit: (view: EditorView) => view.focus(),
additionalExts: [
markRaw(
Prec.highest(
keymap.of([
{
key: "Mod-Enter", // 'Ctrl-Enter' on Windows, 'Cmd-Enter' on macOS
preventDefault: true,
run: () => {
handleImport()
return true
},
},
])
)
),
],
})
)

Expand Down Expand Up @@ -157,6 +181,7 @@ const handleImport = () => {
})

tabs.currentActiveTab.value.document.request = req
toast.success(`${t("import.success")}`)
} catch (e) {
console.error(e)
toast.error(`${t("error.curl_invalid_format")}`)
Expand Down
6 changes: 5 additions & 1 deletion packages/hoppscotch-common/src/modules/ui.ts
Expand Up @@ -2,14 +2,18 @@ import { HoppModule } from "."
import { plugin as HoppUI, HoppUIPluginOptions } from "@hoppscotch/ui"
import { useKeybindingDisabler } from "~/helpers/keybindings"
import { useI18n } from "vue-i18n"
import { delay } from "lodash-es"
const { disableKeybindings, enableKeybindings } = useKeybindingDisabler()

import "@hoppscotch/ui/style.css"

const HoppUIOptions: HoppUIPluginOptions = {
t: (key: string) => useI18n().t(key).toString(),
onModalOpen: disableKeybindings,
onModalClose: enableKeybindings,
onModalClose: () => {
// Delay the activation of keybindings after closing a modal to prevent unintended execution of keybindings that are meant for the main application context, not the modal.
delay(enableKeybindings, 1000)
},
}

export default <HoppModule>{
Expand Down