Skip to content

Commit

Permalink
fix: add terminal.external.extraLinkModifier
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanSalt committed Oct 17, 2024
1 parent f1cda8a commit 7cd58c1
Show file tree
Hide file tree
Showing 16 changed files with 128 additions and 37 deletions.
2 changes: 1 addition & 1 deletion addons/addon-manager/src/renderer/AddonManagerPane.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function refresh() {
function showInFolder(addon: AddonInfo) {
if (addon.type === 'builtin') return
ipcRenderer.invoke('show-file', addon.entry)
commas.remote.showFileExternally(addon.entry)
}
onMounted(() => {
Expand Down
3 changes: 1 addition & 2 deletions addons/browser/src/renderer/BrowserPane.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script lang="ts" setup>
import type { TerminalTab } from '@commas/types/terminal'
import * as commas from 'commas:api/renderer'
import { shell } from 'electron'
import normalizeURL from 'normalize-url'
import { nextTick, watchEffect } from 'vue'
Expand Down Expand Up @@ -84,7 +83,7 @@ function autoselect(event: FocusEvent) {
function openExternal() {
if (!url) return
shell.openExternal(url)
commas.remote.openURLExternally(url)
}
watchEffect((onInvalidate) => {
Expand Down
6 changes: 3 additions & 3 deletions addons/explorer/src/renderer/FileExplorer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ function goBack() {
function openExternal(file: FileEntity) {
if (file.isDirectory) {
ipcRenderer.invoke('open-path', file.path)
commas.remote.openDirectoryExternally(file.path)
} else {
ipcRenderer.invoke('show-file', file.path)
commas.remote.showFileExternally(file.path)
}
}
Expand All @@ -108,7 +108,7 @@ function openExternalExplorer() {
}
function openDirectory() {
ipcRenderer.invoke('open-path', modelValue)
commas.remote.openDirectoryExternally(modelValue)
}
function openNewTab() {
Expand Down
4 changes: 2 additions & 2 deletions addons/preference/src/renderer/PreferencePane.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ function openCustomCSS() {
commas.remote.openUserFile('custom.css')
}
function openWebsite() {
function openWebsite(event: MouseEvent) {
const manifest = commas.app.getManifest()
commas.remote.openURL(manifest.homepage)
commas.ui.openLink(manifest.homepage, event)
}
</script>

Expand Down
12 changes: 6 additions & 6 deletions addons/proxy/src/renderer/ProxyPane.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const address = $computed(() => {
return `http://${ip}:${port}`
})
function openEditor() {
commas.remote.openURL(`http://localhost:${port}`)
function openEditor(event: MouseEvent) {
commas.ui.openLink(`http://localhost:${port}`, event)
}
function copyAddress() {
Expand All @@ -69,12 +69,12 @@ function openKeychainAccess() {
return ipcRenderer.invoke('execute', `open -a 'Keychain Access'`)
}
function install() {
commas.remote.openURL('https://github.com/avwo/whistle/')
function install(event: MouseEvent) {
commas.ui.openLink('https://github.com/avwo/whistle/', event)
}
function update() {
commas.remote.openURL('https://github.com/avwo/whistle/blob/master/CHANGELOG.md')
function update(event: MouseEvent) {
commas.ui.openLink('https://github.com/avwo/whistle/blob/master/CHANGELOG.md', event)
}
</script>

Expand Down
3 changes: 3 additions & 0 deletions addons/settings/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
"Command for starting remote external file manager#!settings.comments.0.terminal.external.remoteExplorer": "用于启动远程外部文件管理器的命令",
"Use ${directory} or ${remote} to interpolate these variables at runtime#!settings.comments.1.terminal.external.remoteExplorer": "使用 ${directory} 或 ${remote} 以在运行时插入这些变量",
"Skip by default#!settings.comments.2.terminal.external.remoteExplorer": "默认跳过",
"Extra External Link Modifier#!settings.label.terminal.external.extraLinkModifier": "外部链接额外修饰键",
"Extra keyboard modifier for opening external link by click#!settings.comments.0.terminal.external.extraLinkModifier": "点击打开外部链接时的额外键盘修饰键",
"A value like 'no-Shift' means that links will be open externally by default unless Shift is pressed#!settings.comments.1.terminal.external.extraLinkModifier": "'no-Shift' 等值意味着链接默认在外部打开,除非按下 Shift 键",
"Tab#!settings.group.terminal.tab": "标签页",
"Enable Live CWD#!settings.label.terminal.tab.liveCwd": "启用实时工作路径",
"Support dynamic \\w and \\W in formatting#!settings.comments.0.terminal.tab.liveCwd": "在格式中支持动态的 \\w 和 \\W",
Expand Down
8 changes: 3 additions & 5 deletions addons/sync/src/renderer/SyncPane.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { ipcRenderer } from '@commas/electron-ipc'
import type { TerminalTab } from '@commas/types/terminal'
import * as commas from 'commas:api/renderer'
import { shell } from 'electron'
import { toRaw, toRef } from 'vue'
import type { SyncPlan } from '../types/sync'
import { useSyncData } from './compositions'
Expand Down Expand Up @@ -34,8 +33,7 @@ function openGitHubTokenSettings() {
const url = new URL('https://github.com/settings/tokens/new')
url.searchParams.set('description', 'Commas Sync')
url.searchParams.set('scopes', 'gist')
// Do not use `commas.remote.openURL` since authorization required
shell.openExternal(url.href)
commas.remote.openURLExternally(url.href)
}
function confirmToken() {
Expand All @@ -56,7 +54,7 @@ function downloadDefaultSyncPlan() {
}
function openSyncPlanGist(gist: string) {
shell.openExternal(`https://gist.github.com/${gist}`)
commas.remote.openURLExternally(`https://gist.github.com/${gist}`)
}
async function uploadSyncPlan(plan: SyncPlan) {
Expand All @@ -74,7 +72,7 @@ async function downloadSyncPlan(plan: SyncPlan) {
}
function openSyncPlanDirectory(plan: SyncPlan) {
shell.openPath(plan.directory)
commas.remote.openDirectory(plan.directory)
}
function formatTime(time: string | null) {
Expand Down
4 changes: 2 additions & 2 deletions addons/theme/src/renderer/ThemePane.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ function reset() {
ipcRenderer.invoke('reset-theme')
}
function openMarketplace() {
commas.remote.openURL('https://windowsterminalthemes.dev')
function openMarketplace(event: MouseEvent) {
commas.ui.openLink('https://windowsterminalthemes.dev', event)
}
async function applyTheme(item: RemoteTheme) {
Expand Down
13 changes: 13 additions & 0 deletions resources/settings.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,19 @@
"recommendations": ["/usr/local/bin/code --folder-uri \"vscode-remote://ssh-remote+${remote}${directory}\""],
"default": ""
},
{
"key": "terminal.external.extraLinkModifier",
"label": "Extra External Link Modifier",
"comments": [
"Extra keyboard modifier for opening external link by click",
"A value like 'no-Shift' means that links will be open externally by default unless Shift is pressed"
],
"schema": {
"type": "string",
"enum": ["no-Shift", "Shift", "no-Alt", "Alt"]
},
"default": "no-Shift"
},
{
"key": "terminal.tab.liveCwd",
"label": "Enable Live CWD",
Expand Down
5 changes: 4 additions & 1 deletion src/api/modules/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
useSettings,
useSettingsSpecs,
} from '../../renderer/compositions/settings'
import { openDirectory, openFile, openURL, showDirectory } from '../../renderer/compositions/shell'
import { openDirectory, openDirectoryExternally, openFile, openURL, openURLExternally, showDirectory, showFileExternally } from '../../renderer/compositions/shell'
import { useIsLightTheme, useTheme } from '../../renderer/compositions/theme'
import { translate } from '../../renderer/utils/i18n'

Expand Down Expand Up @@ -52,7 +52,10 @@ export {
writeUserFile,
translate,
openFile,
showFileExternally,
openDirectory,
openDirectoryExternally,
showDirectory,
openURL,
openURLExternally,
}
2 changes: 2 additions & 0 deletions src/api/modules/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ObjectEditor from '../../renderer/components/basic/ObjectEditor.vue'
import SwitchControl from '../../renderer/components/basic/SwitchControl.vue'
import ValueSelector from '../../renderer/components/basic/ValueSelector.vue'
import VisualIcon from '../../renderer/components/basic/VisualIcon.vue'
import { openLink } from '../../renderer/compositions/terminal'
import { RendererWebContentsView } from '../../renderer/compositions/web-contents'
import { createContextMenu, openContextMenu, withContextMenuSeparator } from '../../renderer/utils/frame'
import { vI18n } from '../../renderer/utils/i18n'
Expand Down Expand Up @@ -61,4 +62,5 @@ export {
withContextMenuSeparator,
extractClosestEdge,
RendererWebContentsView,
openLink,
}
19 changes: 16 additions & 3 deletions src/renderer/components/TerminalTeletype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { quote } from 'shell-quote'
import { onBeforeUpdate } from 'vue'
import { RecycleScroller } from 'vue-virtual-scroller'
import type { CommandCompletion, TerminalTab } from '@commas/types/terminal'
import { isMatchLinkModifier, useTerminalElement } from '../compositions/terminal'
import { useLinkModifiers, useTerminalElement } from '../compositions/terminal'
import { createContextMenu, openContextMenu, withContextMenuSeparator } from '../utils/frame'
import { escapeHTML } from '../utils/helper'
import TerminalBlock from './TerminalBlock.vue'
Expand All @@ -20,6 +20,10 @@ const { tab } = defineProps<{
const element = $ref<HTMLElement>()
const stickyElement = $ref<HTMLElement>()
const {
linkModifier,
} = $(useLinkModifiers())
function dragFileOver(event: DragEvent) {
if (event.dataTransfer) {
event.dataTransfer.dropEffect = 'link'
Expand Down Expand Up @@ -126,7 +130,7 @@ function selectCompletion(event: MouseEvent, item: CommandCompletion) {
const index = renderableCompletion!.items
.findIndex(completion => completion.value === item.value)
if (index === -1) return
if (isMatchLinkModifier(event)) {
if (linkModifier) {
tab.addons.shellIntegration!.selectCompletion(index)
} else {
tab.addons.shellIntegration!.applyCompletion(index)
Expand All @@ -152,7 +156,10 @@ function scrollToStickyCommand() {
<template>
<TerminalBlock
:tab="tab"
:class="['terminal-teletype', { 'has-shell-integration': tab.addons.shellIntegration }]"
:class="['terminal-teletype', {
'has-shell-integration': tab.addons.shellIntegration,
'is-link-active': linkModifier,
}]"
:style="variables"
@contextmenu="openEditingMenu"
@dragover.prevent="dragFileOver"
Expand Down Expand Up @@ -249,6 +256,12 @@ function scrollToStickyCommand() {
padding-bottom: 0;
}
}
:deep(.xterm-cursor-pointer) {
cursor: text;
}
.terminal-teletype.is-link-active & :deep(.xterm-cursor-pointer) {
cursor: pointer;
}
}
@keyframes fade-out {
from {
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/components/TerminalTitle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ipcRenderer } from '@commas/electron-ipc'
import * as commas from '../../api/core-renderer'
import { omitHome } from '../../shared/terminal'
import { useSettings } from '../compositions/settings'
import { showDirectory } from '../compositions/shell'
import { openDirectoryExternally, showDirectory, showFileExternally } from '../compositions/shell'
import { useCurrentTerminal } from '../compositions/terminal'
import { translate } from '../utils/i18n'
import { getPrompt } from '../utils/terminal'
Expand Down Expand Up @@ -99,12 +99,12 @@ function openDirectory(event: MouseEvent) {
if (isDirectory) {
showDirectory(fileOrDirectory)
} else {
ipcRenderer.invoke('show-file', fileOrDirectory)
showFileExternally(fileOrDirectory)
}
}
function openFile() {
ipcRenderer.invoke('open-path', fileOrDirectory)
openDirectoryExternally(fileOrDirectory)
}
function startDraggingDirectory(event: DragEvent) {
Expand Down
22 changes: 17 additions & 5 deletions src/renderer/compositions/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,18 @@ export function openFile(file: string) {
return globalHandler.invoke('global-renderer:open-file', file)
}

export function showFileExternally(file: string) {
return ipcRenderer.invoke('show-file', file)
}

export function openDirectory(directory: string) {
return globalHandler.invoke('global-renderer:open-directory', directory)
}

export function openDirectoryExternally(directory: string) {
return ipcRenderer.invoke('open-path', directory)
}

export function showDirectory(file: string) {
return globalHandler.invoke('global-renderer:show-directory', file)
}
Expand All @@ -78,6 +86,10 @@ export function openURL(url: string) {
return globalHandler.invoke('global-renderer:open-url', url)
}

export function openURLExternally(url: string) {
return ipcRenderer.invoke('open-url', url)
}

export function handleShellMessages() {
ipcRenderer.on('uncaught-error', (event, error) => {
console.error(`Uncaught error in main process: ${error}`)
Expand All @@ -92,15 +104,15 @@ export function handleShellMessages() {
willQuit = true
})
globalHandler.handle('global-renderer:open-file', (file) => {
ipcRenderer.invoke('show-file', file)
return showFileExternally(file)
})
globalHandler.handle('global-renderer:open-directory', (directory) => {
ipcRenderer.invoke('open-path', directory)
return openDirectoryExternally(directory)
})
globalHandler.handle('global-renderer:show-directory', (directory) => {
ipcRenderer.invoke('open-path', directory)
return openDirectoryExternally(directory)
})
globalHandler.handle('global-renderer:open-url', (directory) => {
ipcRenderer.invoke('open-url', directory)
globalHandler.handle('global-renderer:open-url', (url) => {
return openURLExternally(url)
})
}
Loading

0 comments on commit 7cd58c1

Please sign in to comment.