Browse Source

fix(nc-gui): open docs link in new tab

pull/7490/head
Ramesh Mane 10 months ago
parent
commit
af262632cf
  1. 2
      packages/nc-gui/app.vue
  2. 53
      packages/nc-gui/plugins/tele.ts

2
packages/nc-gui/app.vue

@ -1,5 +1,5 @@
<script setup lang="ts">
import { applyNonSelectable, computed, isEeUI, useCommandPalette, useRouter, useTheme, isMac } from '#imports'
import { applyNonSelectable, computed, isEeUI, isMac, useCommandPalette, useRouter, useTheme } from '#imports'
import type { CommandPaletteType } from '~/lib'
const router = useRouter()

53
packages/nc-gui/plugins/tele.ts

@ -95,4 +95,57 @@ export default defineNuxtPlugin(async (nuxtApp) => {
nuxtApp.provide('tele', tele)
nuxtApp.provide('e', (e: string, data?: Record<string, any>) => tele.emit(e, { data }))
}
document.body.removeEventListener('click', clickListener, true)
document.body.addEventListener('click', clickListener, true)
document.body.removeEventListener('keydown', keydownListener, true)
document.body.addEventListener('keydown', keydownListener, true)
})
function clickListener(e) {
if (e.nc_handled) return
e.nc_handled = true
let target = e.target
while (target && !target.classList.contains('DocSearch-Hit')) {
target = target.parentElement
}
if (target) {
const searchInput = document.querySelector('.DocSearch-Input')
const selectedElement = target.querySelector('a')
const url = new URL(selectedElement.href)
e.preventDefault()
e.stopPropagation()
url.searchParams.append('search', searchInput.value)
url.searchParams.append('origin', location.hostname)
window.open(url.toString(), '_blank', 'noopener,noreferrer')
}
}
function keydownListener(e) {
if (e.nc_handled || e.which !== 13) return
e.nc_handled = true
let target = e.target
while (target && !target.classList.contains('DocSearch-Input')) {
target = target.parentElement
}
if (target) {
const selectedElement = document.querySelector('.DocSearch-Hit[aria-selected=true] a')
if (selectedElement) {
const url = new URL(selectedElement.href)
url.searchParams.append('search', target.value)
url.searchParams.append('origin', location.hostname)
e.preventDefault()
e.stopPropagation()
window.open(url.toString(), '_blank', 'noopener,noreferrer')
}
}
}

Loading…
Cancel
Save