Skip to content

Commit b221512

Browse files
committed
[frontend] omnibox tweaks
1 parent f1e99ab commit b221512

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

frontend/src/components/Omnibox.tsx

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ export const focusOmnibox = createDelegate<void>();
1818

1919
export function trimUrl(v: URL) {
2020
return (
21-
(v.protocol === "puter:" ? v.protocol : "") + v.host + v.pathname + v.search
21+
(v.protocol === "puter:" ? v.protocol : "") +
22+
v.host +
23+
(v.search ? v.pathname : v.pathname.replace(/\/$/, "")) +
24+
v.search
2225
);
2326
}
2427

@@ -58,7 +61,6 @@ export const UrlInput: Component<
5861
this.value = "";
5962

6063
focusOmnibox.listen(() => {
61-
console.log("WH");
6264
setTimeout(() => {
6365
activate();
6466
}, 10);
@@ -149,7 +151,11 @@ export const UrlInput: Component<
149151
browser.unfocusframes = false;
150152
e.stopPropagation();
151153
});
152-
this.value = this.tabUrl.href;
154+
if (this.tabUrl.href == "puter://newtab") {
155+
this.value = "";
156+
} else {
157+
this.value = trimUrl(this.tabUrl);
158+
}
153159
this.input.focus();
154160
this.input.select();
155161

@@ -254,17 +260,40 @@ export const UrlInput: Component<
254260
this.input.blur();
255261
}
256262
}}
263+
// keyup, we want this to happen after the input has been processed (so the user can delete the whole thing)
264+
on:keyup={(e: KeyboardEvent) => {
265+
// if the user didn't modify anything
266+
if (this.input.value == trimUrl(this.tabUrl)) {
267+
// insert the untrimmed version
268+
this.input.value = this.tabUrl.href;
269+
}
270+
271+
if (e.key == "ArrowLeft") {
272+
// move the cursor to the start
273+
if (this.tabUrl.protocol == "puter:") {
274+
this.input.setSelectionRange(0, 0);
275+
} else {
276+
let schemelen = this.tabUrl.protocol.length + 2;
277+
this.input.setSelectionRange(schemelen, schemelen);
278+
}
279+
}
280+
}}
257281
on:input={(e: InputEvent) => {
258282
this.value = this.input.value;
259283
this.focusindex = 0;
260284
}}
261285
></input>
262286
)}
263-
{use(this.active)
264-
.map((a) => !a)
287+
{use(this.active, this.tabUrl)
288+
.map(([active, url]) => !active && url.href != "puter://newtab")
265289
.andThen(
266290
<span class="inactiveurl">{use(this.tabUrl).map(trimUrl)}</span>
267291
)}
292+
{use(this.active, this.tabUrl)
293+
.map(([active, url]) => !active && url.href == "puter://newtab")
294+
.andThen(
295+
<span class="placeholder">Search with Google or enter address</span>
296+
)}
268297

269298
<IconButton icon={iconStar}></IconButton>
270299
</div>
@@ -332,7 +361,8 @@ UrlInput.style = css`
332361
margin: 0.25em;
333362
}
334363
input,
335-
.inactiveurl {
364+
.inactiveurl,
365+
.placeholder {
336366
background: none;
337367
border: none;
338368
outline: none;
@@ -344,11 +374,17 @@ UrlInput.style = css`
344374
345375
text-wrap: nowrap;
346376
overflow: hidden;
377+
font-family: Noto Sans;
347378
}
348379
.inactiveurl {
349380
display: flex;
350381
align-items: center;
351382
}
383+
.placeholder {
384+
color: grey;
385+
display: flex;
386+
align-items: center;
387+
}
352388
353389
.realbar {
354390
position: absolute;

0 commit comments

Comments
 (0)