Files
Claude 1435d9c909 ui: links open, and Copy text and Quote on every message
Links in chat did nothing. classify_link (vm/bbcode.rs) sorts an address
into a web page, a TeamSpeak server, a channel file or no link, and only
those reach TextRun.link. A click on a web link opens it through
App::open_url, the one place a platform without xdg-open can hook; one
whose text is not its address first shows where it goes (LinkDialog).
TeamSpeak links are copied until Voelin opens them. A right-click on a
link opens or copies it.

The hover bar was there only for messages a gateway knows. Every message
now has it, with Quote ("> Author: …" lines at the start of the
composer; TeamSpeak clients show [quote] as it is) and Copy text, and a
right-click menu. After Quote the composer has the focus, its cursor
below the quote, and grows to show the quote's lines: its field is one
line high, so an answer typed after clicking into it went into the
quote's last line. The bar keeps itself shown while the pointer is on
it or on the message's links and reactions: it reaches above its row,
where the row's hover ended, so its buttons could not be clicked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AVRENKftQqGoEeswiR9TDQ
2026-10-07 03:47:03 +00:00

309 lines
11 KiB
Plaintext

// Emoji as images (Twemoji through Rust's image cache): chat text with
// formatting and inline emoji, and the picker.
import { Theme } from "../theme.slint";
import { Icons } from "../icons.slint";
import { Images, Emoji, TextRun, TextBlock, ChatLine, EmojiCell } from "../bridge.slint";
import { Nav } from "../nav.slint";
import { Icon } from "icon.slint";
import { PopupMenu } from "overlay.slint";
import { SearchBox } from "text-field.slint";
import { ListView } from "std-widgets.slint";
// A word in its style, or an emoji. A Text draws no lines, so underline
// (links too) and strike-through are 1 px rectangles over it. A click on a
// link opens it (Nav.open-link); a right-click opens or copies it.
component Run inherits Rectangle {
in property <TextRun> run;
in property <length> font-size;
// The text's own colour.
in property <color> text-color;
in property <length> emoji-size;
property <bool> emoji: run.emoji != "";
property <length> pad: run.code ? 3px : 0px;
property <color> ink: run.link != "" ? Theme.accent-text : run.ink-dark.alpha > 0 ? (Theme.dark ? run.ink-dark : run.ink-light) : root.text-color;
min-width: self.preferred-width;
preferred-width: (root.emoji ? root.emoji-size : label.preferred-width) + 2 * root.pad;
preferred-height: root.emoji ? root.emoji-size : label.preferred-height;
border-radius: Theme.radius-xs;
background: run.code ? Theme.surface-3 : transparent;
label := Text {
x: root.pad;
width: self.preferred-width;
text: root.emoji ? "" : run.text;
font-size: root.font-size;
font-weight: run.bold ? Theme.weight-bold : Theme.weight-regular;
font-italic: run.italic;
color: root.ink;
accessible-role: AccessibleRole.none;
}
if root.emoji: Image {
width: root.emoji-size;
height: root.emoji-size;
source: Images.emoji(run.emoji);
image-fit: contain;
accessible-role: AccessibleRole.image;
accessible-label: run.text;
}
if run.underline || run.link != "": Rectangle {
x: label.x;
y: label.y + root.font-size * 1.1;
width: label.width;
height: 1px;
background: root.ink;
}
if run.strike: Rectangle {
x: label.x;
y: label.y + root.font-size * 0.62;
width: label.width;
height: 1px;
background: root.ink;
}
if run.link != "": TouchArea {
mouse-cursor: MouseCursor.pointer;
clicked => { Nav.open-link(run.link, run.masked); }
pointer-event(e) => {
if e.button == PointerEventButton.right && e.kind == PointerEventKind.up {
menu.show(self.mouse-x, self.mouse-y);
}
}
menu := PopupMenu {
x: 0;
y: 0;
entries: [
{ text: @tr("Open link"), icon: Icons.external-link, enabled: true },
{ text: @tr("Copy link"), icon: Icons.copy, enabled: true },
];
activated(i) => {
if i == 0 {
Nav.open-link(run.link, run.masked);
} else {
Nav.copy(run.link);
}
}
}
}
}
// The words and emoji of a block flow and wrap like text.
component Runs inherits FlexboxLayout {
in property <[TextRun]> runs;
in property <length> font-size;
in property <color> color;
in property <length> emoji-size;
spacing: 0px;
cross-axis-alignment: center;
for run in root.runs: Run {
run: run;
font-size: root.font-size;
text-color: root.color;
emoji-size: root.emoji-size;
}
}
// One block of rich text (`TextBlock`): a line, a quote's line with its bar
// (the first with who said it), a line of code on a background, a list item
// or a rule. A component of its own: Slint measures a component's height at
// its width, but a layout repeated by `for` at a guessed width.
component Block inherits Rectangle {
in property <TextBlock> block;
in property <length> font-size;
in property <color> text-color;
in property <length> emoji-size;
background: block.kind == 2 ? Theme.surface-3 : transparent;
HorizontalLayout {
spacing: Theme.space-3;
padding-left: block.kind == 2 ? Theme.space-3 : 0px;
padding-right: self.padding-left;
padding-top: block.kind == 2 ? 2px : block.kind == 4 ? Theme.space-2 : 0px;
padding-bottom: self.padding-top;
// A quote's bar.
if block.kind == 1: Rectangle {
width: 3px;
border-radius: 1.5px;
background: Theme.border-strong;
}
if block.kind == 3: Text {
text: "•";
font-size: root.font-size;
color: root.text-color;
accessible-role: AccessibleRole.none;
}
VerticalLayout {
if block.caption != "": Text {
text: block.caption;
font-size: Theme.font-sm;
font-weight: Theme.weight-semibold;
color: Theme.text-secondary;
}
Runs {
runs: block.runs;
font-size: root.font-size;
color: root.text-color;
emoji-size: root.emoji-size;
}
}
}
if block.kind == 4: Rectangle {
y: (parent.height - self.height) / 2;
height: 1px;
background: Theme.border-strong;
}
}
// Text with formatting and inline emoji, in blocks (`TextBlock`): lines,
// quotes with a bar, code on a background, list items and rules. Plain text
// needs no blocks: use a Text then (faster).
export component RichText inherits VerticalLayout {
in property <[TextBlock]> blocks;
in property <length> font-size: Theme.font-body;
in property <color> color: Theme.text;
in property <length> emoji-size: font-size * 1.4;
for block in root.blocks: Block {
block: block;
font-size: root.font-size;
text-color: root.color;
emoji-size: root.emoji-size;
}
}
// A message's text: one Text when it has neither formatting nor emoji
// (fast), else its blocks; a note in place of a blocked contact's.
export component MessageText inherits VerticalLayout {
in property <ChatLine> line;
in property <length> font-size: Theme.font-body;
// Emoji alone (`jumbo`) are this large.
in property <length> jumbo-size: 44px;
if line.blocked: Text {
text: @tr("Message from a blocked contact.");
color: Theme.text-disabled;
font-size: Theme.font-sm;
font-italic: true;
}
if !line.blocked && !line.rich && line.text != "": Text {
text: line.text;
color: Theme.text;
font-size: root.font-size;
wrap: word-wrap;
}
if !line.blocked && line.rich: RichText {
blocks: line.blocks;
font-size: root.font-size;
emoji-size: line.jumbo ? root.jumbo-size : root.font-size * 1.4;
}
}
// One emoji of the picker grid.
component EmojiButton inherits Rectangle {
in property <EmojiCell> cell;
in property <length> size: 36px;
callback picked(EmojiCell);
width: size;
height: size;
border-radius: Theme.radius-sm;
background: touch.has-hover ? Theme.surface-4 : transparent;
accessible-role: AccessibleRole.button;
accessible-label: cell.name;
accessible-action-default => { picked(cell); }
touch := TouchArea {
mouse-cursor: MouseCursor.pointer;
clicked => { root.picked(root.cell); }
}
Image {
width: root.size - 10px;
height: root.size - 10px;
source: Images.emoji(root.cell.key);
image-fit: contain;
}
}
// The emoji picker: search, categories, a scrolling grid (only the visible
// rows are built). Rust fills `Emoji.rows` for the category or search.
export component EmojiPicker inherits Rectangle {
callback picked(EmojiCell);
callback close();
property <[image]> category-icons: [
Icons.smile, Icons.hand, Icons.leaf, Icons.coffee, Icons.gamepad-2,
Icons.plane, Icons.lightbulb, Icons.heart, Icons.flag,
];
property <[string]> category-names: [
@tr("Smileys"), @tr("People"), @tr("Nature"), @tr("Food"), @tr("Activities"),
@tr("Travel"), @tr("Objects"), @tr("Symbols"), @tr("Flags"),
];
property <length> cell: 36px;
property <string> hovered;
init => { Emoji.load(); }
width: Emoji.columns * cell + 2 * Theme.space-3 + 14px;
height: 400px;
border-radius: Theme.radius-lg;
background: Theme.surface;
border-width: 1px;
border-color: Theme.border-popup;
accessible-role: AccessibleRole.groupbox;
accessible-label: @tr("Emoji");
FocusScope {
key-pressed(event) => {
if event.text == Key.Escape {
root.close();
return accept;
}
reject
}
}
VerticalLayout {
padding: Theme.space-3;
spacing: Theme.space-3;
search := SearchBox {
placeholder: @tr("Search emoji");
show-shortcut: false;
edited(text) => { Emoji.search(text); }
}
HorizontalLayout {
spacing: 2px;
for icon[i] in root.category-icons: Rectangle {
height: 30px;
horizontal-stretch: 1;
border-radius: Theme.radius-sm;
background: Emoji.category == i ? Theme.accent-soft : cat.has-hover ? Theme.surface-3 : transparent;
accessible-role: AccessibleRole.tab;
accessible-label: root.category-names[i];
accessible-item-selectable: true;
accessible-item-selected: Emoji.category == i;
accessible-action-default => { Emoji.show-category(i); }
cat := TouchArea {
mouse-cursor: MouseCursor.pointer;
clicked => {
search.clear();
Emoji.show-category(i);
}
}
Icon {
source: icon;
size: Theme.icon-sm;
tint: Emoji.category == i ? Theme.accent-text : Theme.icon;
}
}
}
Text {
text: Emoji.category >= 0 ? root.category-names[Emoji.category] : Emoji.rows.length == 0 ? @tr("No emoji found") : @tr("Search results");
font-size: Theme.font-sm;
color: Theme.text-muted;
font-weight: Theme.weight-semibold;
}
ListView {
vertical-stretch: 1;
for row in Emoji.rows: HorizontalLayout {
height: root.cell;
alignment: start;
for cell in row.cells: EmojiButton {
cell: cell;
size: root.cell;
picked(c) => { root.picked(c); }
}
}
}
}
}