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:
1 parent
44521e478d
commit
02d579c8b8
4 files changed
+87
No files matched your search
@@ -94,6 +94,7 @@ import {
|
|||||||
shortPath,
|
shortPath,
|
||||||
stillSameAgent,
|
stillSameAgent,
|
||||||
directSendBlocked,
|
directSendBlocked,
|
||||||
|
fieldBackground,
|
||||||
blockTargetPx,
|
blockTargetPx,
|
||||||
shouldResize,
|
shouldResize,
|
||||||
isManualResize,
|
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
|
// 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.
|
// read then. Each tab has a search field of its own.
|
||||||
this.panel = null;
|
this.panel = null;
|
||||||
|
this.panelSearchFocused = false;
|
||||||
// The height of the composer block (reported by its root) and the height
|
// 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.
|
// to give back when a panel that made the block taller closes.
|
||||||
this.blockHeight = null;
|
this.blockHeight = null;
|
||||||
@@ -233,6 +235,15 @@ export default class Composer extends View {
|
|||||||
cx.notify();
|
cx.notify();
|
||||||
});
|
});
|
||||||
input.on("submit", (event, cx) => this.panelPick(this.panel?.index ?? 0, cx));
|
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.panelScroll = VirtualListScrollHandle.new();
|
||||||
this.favorites = storage.loadFavorites(this.store);
|
this.favorites = storage.loadFavorites(this.store);
|
||||||
@@ -702,6 +713,7 @@ export default class Composer extends View {
|
|||||||
if (!this.panel) return;
|
if (!this.panel) return;
|
||||||
const { caret } = this.panel;
|
const { caret } = this.panel;
|
||||||
this.panel = null;
|
this.panel = null;
|
||||||
|
this.panelSearchFocused = false;
|
||||||
if (this.panelRestorePx !== null) {
|
if (this.panelRestorePx !== null) {
|
||||||
this.resizeBlock(this.panelRestorePx);
|
this.resizeBlock(this.panelRestorePx);
|
||||||
this.panelRestorePx = null;
|
this.panelRestorePx = null;
|
||||||
@@ -848,6 +860,8 @@ export default class Composer extends View {
|
|||||||
query,
|
query,
|
||||||
index,
|
index,
|
||||||
input: this.panelInputs[tab],
|
input: this.panelInputs[tab],
|
||||||
|
searchFocused: this.panelSearchFocused,
|
||||||
|
fieldBackground: fieldBackground(theme(), theme().popover),
|
||||||
scroll: this.panelScroll,
|
scroll: this.panelScroll,
|
||||||
isFavorite: (text) => isFavorite(this.favorites, text),
|
isFavorite: (text) => isFavorite(this.favorites, text),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ const TEXT_HEIGHT = 34;
|
|||||||
* query: string,
|
* query: string,
|
||||||
* index: number,
|
* index: number,
|
||||||
* input: object,
|
* input: object,
|
||||||
|
* searchFocused: boolean,
|
||||||
|
* fieldBackground: string,
|
||||||
* scroll: object,
|
* scroll: object,
|
||||||
* isFavorite: (text:string) => boolean,
|
* isFavorite: (text:string) => boolean,
|
||||||
* }} view
|
* }} view
|
||||||
@@ -83,12 +85,21 @@ function renderTop(t, view, on) {
|
|||||||
.children([
|
.children([
|
||||||
renderTab(t, "history", `Historia ${counts.history}`, view.tab === "history", on),
|
renderTab(t, "history", `Historia ${counts.history}`, view.tab === "history", on),
|
||||||
renderTab(t, "favorites", `Ulubione ${counts.favorites}`, view.tab === "favorites", 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()
|
h_flex()
|
||||||
.id("composer-panel-search")
|
.id("composer-panel-search")
|
||||||
.flex_1()
|
.flex_1()
|
||||||
.min_w(0)
|
.min_w(0)
|
||||||
|
.h(30)
|
||||||
|
.px(10)
|
||||||
.items_center()
|
.items_center()
|
||||||
.gap(6)
|
.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))
|
.child(Input.new(view.input).flex_1().min_w(0).text_size(12.5))
|
||||||
.when(view.query !== "", (el) =>
|
.when(view.query !== "", (el) =>
|
||||||
el.child(
|
el.child(
|
||||||
|
|||||||
@@ -568,3 +568,44 @@ export function isManualResize({ reportedPx, orderedPx, tolerance = 3 }) {
|
|||||||
if (!Number.isFinite(reportedPx) || !Number.isFinite(orderedPx)) return false;
|
if (!Number.isFinite(reportedPx) || !Number.isFinite(orderedPx)) return false;
|
||||||
return Math.abs(reportedPx - orderedPx) > tolerance;
|
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;
|
||||||
|
}
|
||||||
@@ -144,3 +144,24 @@ test("isManualResize: a height nobody ordered is the person's drag", () => {
|
|||||||
assert.equal(isManualResize({ reportedPx: 150, orderedPx: null }), false);
|
assert.equal(isManualResize({ reportedPx: 150, orderedPx: null }), false);
|
||||||
assert.equal(isManualResize({ reportedPx: NaN, orderedPx: 200 }), false);
|
assert.equal(isManualResize({ reportedPx: NaN, orderedPx: 200 }), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
import { luminance, fieldBackground } from "../mod/ovis-composer/view.js";
|
||||||
|
|
||||||
|
test("luminance: black is darker than grey is darker than white; alpha and rubbish are tolerated", () => {
|
||||||
|
assert.ok(luminance("#000000") < luminance("#808080"));
|
||||||
|
assert.ok(luminance("#808080") < luminance("#ffffff"));
|
||||||
|
assert.equal(luminance("#000000ff"), luminance("#000000"));
|
||||||
|
assert.equal(luminance("#fff"), luminance("#ffffff"));
|
||||||
|
assert.equal(luminance("red"), null);
|
||||||
|
assert.equal(luminance(undefined), null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("fieldBackground: the darkest color the theme has, darker than the panel", () => {
|
||||||
|
const theme = { popover: "#2a2c31", background: "#101114", canvas: "#16171a", raised: "#202226", chrome: "#1b1c20" };
|
||||||
|
assert.equal(fieldBackground(theme, theme.popover), "#101114");
|
||||||
|
// a theme where the background is lighter than another color: that one wins
|
||||||
|
assert.equal(fieldBackground({ ...theme, background: "#3a3c41", canvas: "#0c0d0f" }, theme.popover), "#0c0d0f");
|
||||||
|
// nothing valid: the panel's own color
|
||||||
|
assert.equal(fieldBackground({}, "#2a2c31"), "#2a2c31");
|
||||||
|
assert.equal(fieldBackground({ background: "nope" }, "#2a2c31"), "#2a2c31");
|
||||||
|
});
|
||||||
Reference in new issue
Block a user