Desktop: Add terminal context menu (text) (#5563)

* Add text context menu to terminal on right-click

Enable single right-click context menu in BaseTerminal for desktop app users.  Previously required two right clicks.

* Use useEventListener for context menu

* Fix overzealous tab-complete

* nit
This commit is contained in:
filtered
2025-09-15 18:10:02 +10:00
committed by GitHub
parent 6349ceee6c
commit bbff9c8217

View File

@@ -7,9 +7,11 @@
</template>
<script setup lang="ts">
import { useEventListener } from '@vueuse/core'
import { Ref, onUnmounted, ref } from 'vue'
import { useTerminal } from '@/composables/bottomPanelTabs/useTerminal'
import { electronAPI, isElectron } from '@/utils/envUtil'
const emit = defineEmits<{
created: [ReturnType<typeof useTerminal>, Ref<HTMLElement | undefined>]
@@ -19,6 +21,15 @@ const terminalEl = ref<HTMLElement | undefined>()
const rootEl = ref<HTMLElement | undefined>()
emit('created', useTerminal(terminalEl), rootEl)
const showContextMenu = (event: MouseEvent) => {
event.preventDefault()
electronAPI()?.showContextMenu({ type: 'text' })
}
if (isElectron()) {
useEventListener(terminalEl, 'contextmenu', showContextMenu)
}
onUnmounted(() => emit('unmounted'))
</script>