Skip to content

Commit

Permalink
fix(browser): url interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanSalt committed Dec 3, 2024
1 parent c9cd812 commit de2d1d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 27 deletions.
1 change: 1 addition & 0 deletions addons/browser/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"New Page#!browser.1": "新页面",
"Open Web Page#!browser.2": "打开网页",
"Web Page#!browser.3": "网页",
"Enter URL...#!browser.4": "输入 URL...",
"Browse URL#!cli.description.browse": "访问 URL",
"<url>#!cli.usage.browse": "<url>"
}
32 changes: 5 additions & 27 deletions addons/browser/src/renderer/BrowserPane.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import type { TerminalTab } from '@commas/types/terminal'
import * as commas from 'commas:api/renderer'
import normalizeURL from 'normalize-url'
import { nextTick, watchEffect } from 'vue'
import { watchEffect } from 'vue'
const { tab } = defineProps<{
tab: TerminalTab,
}>()
const { TerminalPane, WebContents, VisualIcon } = commas.ui.vueAssets
const { TerminalPane, WebContents, VisualIcon, vI18n } = commas.ui.vueAssets
let url = $computed({
get: () => tab.command,
Expand Down Expand Up @@ -41,22 +41,13 @@ function goBack() {
view.goToOffset(-1)
}
let isCustomizing = $ref(false)
let customURL: string | undefined = $ref<string>()
let customURLElement = $ref<HTMLInputElement>()
watchEffect(() => {
customURL = url
})
async function startCustomization() {
isCustomizing = true
await nextTick()
if (customURLElement) {
customURLElement.select()
}
}
async function customize() {
if (customURL && customURL !== url) {
url = normalizeURL(customURL, {
Expand All @@ -69,12 +60,10 @@ async function customize() {
sortQueryParameters: false,
})
}
isCustomizing = false
}
function resetCustomization() {
customURL = url
isCustomizing = false
}
function autoselect(event: FocusEvent) {
Expand Down Expand Up @@ -107,18 +96,18 @@ watchEffect((onInvalidate) => {
<button type="button" data-commas :class="['browser-action', { disabled: !view?.canGoBack }]" @click="goBack">
<VisualIcon name="lucide-undo-2" />
</button>
<form v-if="isCustomizing" class="custom-url-form" @submit.prevent="customize">
<form class="custom-url-form" @submit.prevent="customize">
<input
ref="customURLElement"
v-model="customURL"
v-i18n:placeholder
class="custom-url"
placeholder="Enter URL...#!browser.4"
autofocus
@focus="autoselect"
@blur="resetCustomization"
@keydown.esc="resetCustomization"
>
</form>
<span v-else class="page-url" @click="startCustomization">{{ url }}</span>
<button type="button" data-commas :class="['browser-action', { disabled: !url }]" @click="openExternal">
<VisualIcon name="lucide-square-arrow-out-up-right" />
</button>
Expand Down Expand Up @@ -176,17 +165,6 @@ watchEffect((onInvalidate) => {
background: transparent;
outline: none;
}
.page-url {
display: flex;
flex: 1;
align-self: stretch;
align-items: center;
min-width: 0;
font-size: 12px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.web-page {
flex: 1;
min-height: 0;
Expand Down

0 comments on commit de2d1d1

Please sign in to comment.