feat: composer block fits its content, keeps a height the person dragged to
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
1 parent
360d93f589
commit
406f00f0e4
6 files changed
+260
-14
No files matched your search
+122
-13
@@ -94,6 +94,9 @@ import {
|
||||
shortPath,
|
||||
stillSameAgent,
|
||||
directSendBlocked,
|
||||
blockTargetPx,
|
||||
shouldResize,
|
||||
isManualResize,
|
||||
statusText,
|
||||
targetAgent,
|
||||
} from "./view.js";
|
||||
@@ -113,6 +116,16 @@ const PANEL_MIN_BLOCK = 320;
|
||||
/** ...to this. */
|
||||
const PANEL_BLOCK_PX = 360;
|
||||
|
||||
/** The padding of the root, per side (px) - the block is the content plus two of them. */
|
||||
const ROOT_PADDING = 8;
|
||||
|
||||
/** The range the layout gives the composer block (`layouts/ovis-composer.json`), px. */
|
||||
const BLOCK_MIN_PX = 120;
|
||||
const BLOCK_MAX_PX = 520;
|
||||
|
||||
/** The block is resized once the content has been quiet for this long, ms. */
|
||||
const FIT_DELAY_MS = 120;
|
||||
|
||||
/** How many rows the menu of the suggestions shows at most. */
|
||||
const MENU_LIMIT = 20;
|
||||
|
||||
@@ -199,6 +212,15 @@ export default class Composer extends View {
|
||||
// to give back when a panel that made the block taller closes.
|
||||
this.blockHeight = null;
|
||||
this.panelRestorePx = null;
|
||||
// The block is as tall as its content: the height of the content, the
|
||||
// height this copy ordered last (what it did not order is the person's
|
||||
// drag), the floor the person dragged to, and the timer that waits for the
|
||||
// content to settle before the block is resized.
|
||||
this.contentHeight = null;
|
||||
this.orderedPx = null;
|
||||
this.ignoreSizeUntil = 0;
|
||||
this.fitTimer = null;
|
||||
this.userMin = storage.loadUserMin(this.store);
|
||||
this.panelInputs = {
|
||||
history: InputState.new({ placeholder: "Szukaj w historii…" }),
|
||||
favorites: InputState.new({ placeholder: "Szukaj w ulubionych…" }),
|
||||
@@ -700,18 +722,26 @@ export default class Composer extends View {
|
||||
*/
|
||||
layoutPx() {
|
||||
if (!Number.isFinite(this.blockHeight)) return null;
|
||||
let zoom = 1;
|
||||
return Math.round(this.blockHeight / this.zoomFactor());
|
||||
}
|
||||
|
||||
/** The zoom of the app (1 when it is not known): logical px = layout px times this. */
|
||||
zoomFactor() {
|
||||
try {
|
||||
const value = Number(settings()?.zoom);
|
||||
if (Number.isFinite(value) && value > 0) zoom = value;
|
||||
if (Number.isFinite(value) && value > 0) return value;
|
||||
} catch {
|
||||
// Unknown zoom: 1, the reported height is taken as it is.
|
||||
}
|
||||
return Math.round(this.blockHeight / zoom);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** The composer block gets another height (`layout.resize`); a refusal is said, not worked around. */
|
||||
resizeBlock(px) {
|
||||
// What is reported in the next moments is the answer to this order, not a
|
||||
// drag of the border.
|
||||
this.orderedPx = px;
|
||||
this.ignoreSizeUntil = Date.now() + 400;
|
||||
try {
|
||||
run("layout.resize", { id: "composer", px });
|
||||
} catch (err) {
|
||||
@@ -719,6 +749,75 @@ export default class Composer extends View {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The root reported its size (logical px).
|
||||
*
|
||||
* A height this copy did not order is the person dragging the border: it
|
||||
* becomes the floor (`userMin`, kept across restarts). While the panel is
|
||||
* open its own logic owns the height.
|
||||
*/
|
||||
rootSized(size, cx) {
|
||||
this.blockHeight = size.height;
|
||||
if (this.panel) return;
|
||||
|
||||
const px = this.layoutPx();
|
||||
if (px === null) return;
|
||||
if (this.orderedPx === null) {
|
||||
// The first height is the layout's own - the point to start from.
|
||||
this.orderedPx = px;
|
||||
} else if (Date.now() >= this.ignoreSizeUntil && isManualResize({ reportedPx: px, orderedPx: this.orderedPx })) {
|
||||
this.userMin = px;
|
||||
this.orderedPx = px;
|
||||
try {
|
||||
storage.saveUserMin(this.store, px);
|
||||
} catch {
|
||||
// The floor is not kept across a restart; it still holds for now.
|
||||
}
|
||||
}
|
||||
this.scheduleFit(cx);
|
||||
}
|
||||
|
||||
/** The content (everything but the layers) reported its size. */
|
||||
contentSized(size, cx) {
|
||||
this.contentHeight = size.height;
|
||||
this.scheduleFit(cx);
|
||||
}
|
||||
|
||||
/** The block is fitted once the content has been quiet for 120 ms. */
|
||||
scheduleFit(cx) {
|
||||
if (this.fitTimer) {
|
||||
this.fitTimer.cancel();
|
||||
this.fitTimer = null;
|
||||
}
|
||||
this.fitTimer = cx.timer.after(FIT_DELAY_MS, () => {
|
||||
this.fitTimer = null;
|
||||
this.fitBlock();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The block takes the height of its content (never below what the person
|
||||
* dragged it to), when that differs by more than 4 px from what it has. The
|
||||
* height last ordered is not ordered again, so a resize that comes back as a
|
||||
* size change does not start another one.
|
||||
*/
|
||||
fitBlock() {
|
||||
if (this.panel || !Number.isFinite(this.contentHeight)) return;
|
||||
const current = this.layoutPx();
|
||||
if (current === null) return;
|
||||
|
||||
const target = blockTargetPx({
|
||||
contentHeight: this.contentHeight,
|
||||
padding: ROOT_PADDING * 2,
|
||||
zoom: this.zoomFactor(),
|
||||
userMin: this.userMin,
|
||||
min: BLOCK_MIN_PX,
|
||||
max: BLOCK_MAX_PX,
|
||||
});
|
||||
if (!shouldResize(current, target) || target === this.orderedPx) return;
|
||||
this.resizeBlock(target);
|
||||
}
|
||||
|
||||
/** The selection (or the caret) of the field. */
|
||||
restoreSelection(range) {
|
||||
try {
|
||||
@@ -2012,9 +2111,7 @@ export default class Composer extends View {
|
||||
return v_flex()
|
||||
.id("ovis-composer")
|
||||
.relative()
|
||||
.on_size_change((size) => {
|
||||
this.blockHeight = size.height;
|
||||
})
|
||||
.on_size_change((size, cx) => this.rootSized(size, cx))
|
||||
.track_focus(this.handle)
|
||||
.key_context(CONTEXT)
|
||||
.on_key_down((event, cx) => this.key(event, cx))
|
||||
@@ -2029,7 +2126,7 @@ export default class Composer extends View {
|
||||
.on_action("ovis-composer.hold", (e, cx) => this.runAction("hold", cx))
|
||||
.on_action("ovis-composer.escape", (e, cx) => this.runAction("escape", cx))
|
||||
.size_full()
|
||||
.p(8)
|
||||
.p(ROOT_PADDING)
|
||||
.gap(6)
|
||||
// The card and the context strip sit at the bottom edge of the block,
|
||||
// right above the status bar; the menu, the queue and the notices stay
|
||||
@@ -2039,12 +2136,24 @@ export default class Composer extends View {
|
||||
.text_color(t.foreground)
|
||||
.children(
|
||||
[
|
||||
this.renderMenu(t),
|
||||
this.renderQueue(t, agent, key),
|
||||
this.renderImageConfirm(t),
|
||||
this.renderNotice(t),
|
||||
this.renderCard(t, agent, key, status),
|
||||
this.renderContext(t, agent),
|
||||
// The content is measured as it is - `flex_none`, so a block that is
|
||||
// too low does not squeeze it and hide how much room it needs.
|
||||
v_flex()
|
||||
.id("composer-content")
|
||||
.flex_none()
|
||||
.w_full()
|
||||
.gap(6)
|
||||
.on_size_change((size, cx) => this.contentSized(size, cx))
|
||||
.children(
|
||||
[
|
||||
this.renderMenu(t),
|
||||
this.renderQueue(t, agent, key),
|
||||
this.renderImageConfirm(t),
|
||||
this.renderNotice(t),
|
||||
this.renderCard(t, agent, key, status),
|
||||
this.renderContext(t, agent),
|
||||
].filter(Boolean),
|
||||
),
|
||||
this.renderPanelLayer(t),
|
||||
this.renderPreviewLayer(t),
|
||||
].filter(Boolean),
|
||||
|
||||
Reference in new issue
Block a user