feat: clickable star in the history panel, + form for the dock

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
FactorandClaude Sonnet 5.5 committed 2026-11-19 17:29:28 +01:00
1 parent f880f7ef06
commit 7e23b8a79c
5 files changed
+212 -10

No files matched your search

@@ -258,3 +258,22 @@ export function menuTransition(current, { kind, id, open }) {
export function applyDock(stored, operation) {
return normalize(operation(normalize(stored)));
}
/**
* Add a button made by hand (the "+" form): the text, a name (empty gives the
* default label) and a mode. The same dock comes back when the text is empty,
* already pinned, or the dock is full.
*
* @param {DockButton[]} dock
* @param {{id: string, text: string, label?: string, mode?: string}} button
* @returns {DockButton[]}
*/
export function add(dock, { id, text, label, mode }) {
const clean = String(text).trim();
if (clean === "" || isPinned(dock, clean) || dock.length >= DOCK_LIMIT) return dock;
const name = String(label ?? "").trim();
return [
...dock,
{ id, label: name === "" ? defaultLabel(clean) : name, text: clean, mode: mode === "insert" ? "insert" : "send" },
];
}
@@ -66,7 +66,7 @@ import {
} from "./clipboard.js";
import * as storage from "./storage.js";
import { record, panelState, moveIndex, otherTab, toggleFavorite, isFavorite } from "./history.js";
import { renderPanel, renderPreview } from "./panel.js";
import { renderPanel, renderPreview, STAR_ZONE } from "./panel.js";
import {
dockAction,
dockMenu,
@@ -81,6 +81,7 @@ import {
toggleMode,
menuTransition,
applyDock,
add as addButton,
DOCK_LIMIT,
} from "./dock.js";
import {
@@ -279,6 +280,11 @@ export default class Composer extends View {
this.escSwallowUntil = 0;
this.renameInput = InputState.new({ placeholder: "Nazwa" });
this.renameInput.on("submit", (event, cx) => this.renameCommit(cx));
// The form of the "+" button: a name, the text and the mode of a new button.
this.addLabel = InputState.new({ placeholder: "Nazwa (puste = z tekstu)" });
this.addText = TextareaState.new({ value: "", placeholder: "Tekst przycisku", rows: 3 });
this.addMode = "send";
this.addLabel.on("submit", (event, cx) => this.addCommit(cx));
this.renameEndedAt = 0;
this.renameFocused = false;
this.rowMenuClosedAt = 0;
@@ -1015,11 +1021,29 @@ export default class Composer extends View {
cx.notify();
}
/**
* A left press on the list, before the click of the row. A row cannot carry
* its own handlers, so where the press landed is kept here: the star is the
* right edge of the row (see STAR_ZONE in panel.js).
*/
panelPress(event) {
const x = event?.local_position?.x;
const width = event?.bounds?.width;
this.panelStarPress = typeof x === "number" && typeof width === "number" && x >= width - STAR_ZONE;
}
/** A row was clicked: it is named by its key (the id of the entry). */
panelPickKey(key, cx) {
if (!this.panel) return;
// The click that closed the menu of a row is not a pick.
if (Date.now() - this.rowMenuClosedAt < 250) return;
// The click on the star of a row toggles the favourite and inserts nothing.
if (this.panelStarPress) {
this.panelStarPress = false;
const text = this.panelRowText(key);
if (text) this.toggleFavoriteText(text, cx);
return;
}
const index = this.panelView().state.hits.findIndex((hit) => String(hit.item.id) === key);
if (index >= 0) this.panelPick(index, cx);
}
@@ -1120,6 +1144,7 @@ export default class Composer extends View {
this.menuOpenedAt = now;
// Another copy may have changed the dock: the menu shows the fresh one.
this.refreshDock(cx);
if (kind === "add") this.startAdd(cx);
} else if (before && !this.contextMenu) {
this.menuClosedAt = now;
// The Popover took Esc itself: the same press must not reach the agent.
@@ -1229,6 +1254,141 @@ export default class Composer extends View {
}
}
/** The "+" form opens: the text of the field is the first guess for the text of the button. */
startAdd(cx) {
this.addLabel.set_value("");
this.addText.set_value(this.value.trim());
this.addMode = "send";
cx.timer.after(60, () => {
if (this.contextMenu?.kind !== "add") return;
try {
this.addText.focus();
} catch {
// The form stays; the person clicks into it.
}
});
}
/** "Dodaj" in the form: the button goes to the end of the dock. */
addCommit(cx) {
const text = this.addText.value();
const label = this.addLabel.value();
const stored = storage.loadDock(this.store);
if (text.trim() === "") {
this.notice("Wpisz tekst przycisku.", "problem", cx);
return;
}
if (isPinned(stored, text)) {
this.notice("Taki przycisk już jest w docku.", "problem", cx);
return;
}
if (stored.length >= DOCK_LIMIT) {
this.notice(`Dock jest pełny (${DOCK_LIMIT} przycisków).`, "problem", cx);
return;
}
const id = this.newId();
const mode = this.addMode;
this.dropContextMenu();
this.escSwallowUntil = Date.now() + 80;
this.setDock((dock) => addButton(dock, { id, text, label, mode }), cx);
this.focusField();
cx.notify();
}
/** "Anuluj" in the form. */
addCancel(cx) {
this.dropContextMenu();
this.escSwallowUntil = Date.now() + 80;
this.focusField();
cx.notify();
}
/** The form of the "+" button: name, text, mode, and the two buttons. */
renderAddForm(t) {
const insert = this.addMode === "insert";
const button = (id, label, fill, action) =>
div()
.id(id)
.h(28)
.px(12)
.flex()
.items_center()
.rounded(6)
.text_size(12.5)
.text_color(fill ? t.foreground : t.muted)
.when(fill, (el) => el.bg(t.accent))
.cursor_pointer()
.hover((s) => s.bg(t.hover))
.on_click((event, cx) => action(cx))
.child(label);
return v_flex()
.id("composer-add-form")
.w(320)
.p(10)
.gap(8)
.rounded(8)
.border(1)
.border_color(t.border)
.bg(t.raised)
.child(div().text_size(12).text_color(t.dim).child("Nowy przycisk docka"))
.child(Input.new(this.addLabel).w_full().h(28).text_size(12.5))
.child(Textarea.new(this.addText).w_full().px(8).py(6).rounded(6).bg(t.background).text_size(12.5))
.child(
div()
.id("composer-add-mode")
.h(28)
.px(10)
.flex()
.items_center()
.rounded(6)
.bg(t.chrome)
.text_size(12.5)
.text_color(t.muted)
.cursor_pointer()
.hover((s) => s.bg(t.hover))
.on_click((event, cx) => {
this.addMode = insert ? "send" : "insert";
cx.notify();
})
.child(insert ? "Tryb: tylko wstawia (✎)" : "Tryb: wysyła od razu"),
)
.child(
h_flex()
.gap(8)
.justify_end()
.child(button("composer-add-cancel", "Anuluj", false, (cx) => this.addCancel(cx)))
.child(button("composer-add-ok", "Dodaj", true, (cx) => this.addCommit(cx))),
);
}
/** The "+" of the dock: it opens the form. */
renderAddButton(t, active) {
const icon = div()
.id("composer-dock-add")
.size(28)
.rounded(999)
.flex_none()
.flex()
.items_center()
.justify_center()
.bg(t.chrome)
.text_size(15)
.text_color(active ? t.muted : t.dim)
.cursor_pointer()
.hover((s) => s.bg(t.hover).text_color(t.foreground))
.tooltip("Dodaj przycisk do docka")
.child("+");
if (!active) return icon;
const open = this.contextMenu?.kind === "add";
return Popover.new("composer-dock-add-menu")
.anchor("bottom_left")
.open(open)
.on_open_change((value, cx) => this.popoverChanged("add", "add", value, cx))
.trigger(icon)
.content(open ? this.renderAddForm(t) : div());
}
/** The button becomes a small input with its name. */
startRename(button, cx) {
this.renaming = button.id;
@@ -2497,6 +2657,7 @@ export default class Composer extends View {
tab: (tab, cx) => this.panelTab(tab, cx),
pick: (key, cx) => this.panelPickKey(key, cx),
rowMenu: (key, cx) => this.panelRowMenu(key, cx),
press: (event) => this.panelPress(event),
clear: (cx) => this.panelClear(cx),
// The close button: what Esc does - the field gets the keyboard, the
// caret and the height of the block back.
@@ -2877,12 +3038,13 @@ export default class Composer extends View {
.items_center()
.overflow_x_scroll();
const add = this.renderAddButton(t, active);
if (this.dock.length === 0) {
return row.child(
div().flex_none().text_size(12).text_color(t.dim).child("Prawy klik w Ulubionych → Przypnij do docka"),
);
return row
.child(add)
.child(div().flex_none().text_size(12).text_color(t.dim).child("Plus lub prawy klik w Ulubionych → Przypnij do docka"));
}
return row.children(this.dock.map((button) => this.renderDockButton(t, button, active)));
return row.children([add, ...this.dock.map((button) => this.renderDockButton(t, button, active))]);
}
/** One button of the dock: `send` has a fill, `insert` a frame and the ✎ mark. */
@@ -9,9 +9,10 @@
// Limit of the list: rows of a `v_virtual_list` cannot carry their own click
// handlers (the host refuses a handler inside the item renderer) - one
// `on_item_click` serves the whole list and names the row by its key. So a row
// click inserts the text; the star of a row is a sign, not a button (the
// favourites are toggled with Ctrl+D or from the menu a right click opens -
// `on_item_secondary_click`).
// click inserts the text. The star of a row is not an element with a handler
// either: `on_mouse_down` on the list says where the press landed, and a press
// in the STAR_ZONE at the right edge makes the click toggle the favourite
// (main.js). Ctrl+D and the right-click menu do the same.
import { div, image } from "gpui-kit";
import { v_flex, h_flex, Input, Scrollbar, v_virtual_list } from "gpui-base";
@@ -26,6 +27,12 @@ import { segments, entryMeta } from "./history.js";
*/
export const ROW_HEIGHT = 76;
/**
* The right edge of a row that counts as its star: 10 px of padding, the
* 24 px star and a little room (a click lands next to a small target).
*/
export const STAR_ZONE = 48;
/** Two lines of the text of a row, at about 20 px a line (the rest is cut). */
const TEXT_HEIGHT = 40;
@@ -49,6 +56,7 @@ const TEXT_HEIGHT = 40;
* tab: (tab:string, cx:any) => void,
* pick: (key:string, cx:any) => void,
* rowMenu: (key:string, cx:any) => void,
* press: (event:any) => void,
* clear: (cx:any) => void,
* close: (cx:any) => void,
* }} on
@@ -165,6 +173,7 @@ function renderList(t, view, on) {
return v_flex()
.size_full()
.relative()
.on_mouse_down("left", (event, cx) => on.press(event))
.child(
v_virtual_list(
"composer-panel-list",