feat: search field of the history panel stands out (recess, focus border, magnifier)

Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
FactorandOvis Fast committed 2026-11-19 12:34:00 +01:00
1 parent 44521e478d
commit 02d579c8b8
4 files changed
+87

No files matched your search

+14
View File
@@ -94,6 +94,7 @@ import {
shortPath,
stillSameAgent,
directSendBlocked,
fieldBackground,
blockTargetPx,
shouldResize,
isManualResize,
@@ -208,6 +209,7 @@ export default class Composer extends View {
// is picked, where the caret was when it opened, and the history as it was
// read then. Each tab has a search field of its own.
this.panel = null;
this.panelSearchFocused = false;
// The height of the composer block (reported by its root) and the height
// to give back when a panel that made the block taller closes.
this.blockHeight = null;
@@ -233,6 +235,15 @@ export default class Composer extends View {
cx.notify();
});
input.on("submit", (event, cx) => this.panelPick(this.panel?.index ?? 0, cx));
// The border of the search field lights up while it has the keyboard.
input.on("focus", (event, cx) => {
this.panelSearchFocused = true;
cx.notify();
});
input.on("blur", (event, cx) => {
this.panelSearchFocused = false;
cx.notify();
});
}
this.panelScroll = VirtualListScrollHandle.new();
this.favorites = storage.loadFavorites(this.store);
@@ -702,6 +713,7 @@ export default class Composer extends View {
if (!this.panel) return;
const { caret } = this.panel;
this.panel = null;
this.panelSearchFocused = false;
if (this.panelRestorePx !== null) {
this.resizeBlock(this.panelRestorePx);
this.panelRestorePx = null;
@@ -848,6 +860,8 @@ export default class Composer extends View {
query,
index,
input: this.panelInputs[tab],
searchFocused: this.panelSearchFocused,
fieldBackground: fieldBackground(theme(), theme().popover),
scroll: this.panelScroll,
isFavorite: (text) => isFavorite(this.favorites, text),
};
+11
View File
@@ -32,6 +32,8 @@ const TEXT_HEIGHT = 34;
* query: string,
* index: number,
* input: object,
* searchFocused: boolean,
* fieldBackground: string,
* scroll: object,
* isFavorite: (text:string) => boolean,
* }} view
@@ -83,12 +85,21 @@ function renderTop(t, view, on) {
.children([
renderTab(t, "history", `Historia ${counts.history}`, view.tab === "history", on),
renderTab(t, "favorites", `Ulubione ${counts.favorites}`, view.tab === "favorites", on),
// The search field: a darker recess with a border that lights up while
// the field has the keyboard (the `.hsearch` of the mockup).
h_flex()
.id("composer-panel-search")
.flex_1()
.min_w(0)
.h(30)
.px(10)
.items_center()
.gap(6)
.rounded(8)
.bg(view.fieldBackground)
.border_1()
.border_color(view.searchFocused ? t.accent : t.input)
.child(div().flex_none().text_size(13).text_color(t.dim).child("⌕"))
.child(Input.new(view.input).flex_1().min_w(0).text_size(12.5))
.when(view.query !== "", (el) =>
el.child(
+41
View File
@@ -568,3 +568,44 @@ export function isManualResize({ reportedPx, orderedPx, tolerance = 3 }) {
if (!Number.isFinite(reportedPx) || !Number.isFinite(orderedPx)) return false;
return Math.abs(reportedPx - orderedPx) > tolerance;
}
// --- colors from the theme -----------------------------------------------------
/**
* How light a color is (0 dark .. 1 light), from `#rgb`, `#rrggbb` or
* `#rrggbbaa`; nothing for what is not such a color.
*
* @param {unknown} color
* @returns {number|null}
*/
export function luminance(color) {
if (typeof color !== "string") return null;
let hex = color.trim();
if (!/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(hex)) return null;
hex = hex.slice(1);
if (hex.length === 3) hex = hex.replace(/./g, "$&$&");
const channel = (at) => parseInt(hex.slice(at, at + 2), 16) / 255;
return 0.2126 * channel(0) + 0.7152 * channel(2) + 0.0722 * channel(4);
}
/**
* The background of an input field set into a panel: the darkest color the
* theme names among the usual surfaces, so the field reads as a recess in the
* panel whatever the theme. A theme with none to offer leaves the panel's own.
*
* @param {Record<string,string>} theme - `theme()`
* @param {string} panelBackground - the background of the panel
* @returns {string}
*/
export function fieldBackground(theme, panelBackground) {
let best = null;
let bestLight = Infinity;
for (const key of ["background", "canvas", "pane", "surface", "chrome"]) {
const light = luminance(theme?.[key]);
if (light !== null && light < bestLight) {
best = theme[key];
bestLight = light;
}
}
return best ?? panelBackground;
}