imsd-messages/interfaces/ImsdMessages-Edit.cppm

237 lines
10 KiB
Text
Raw Permalink Normal View History

Ui: the compose field and the send bar A text message needs several lines and UTF-8, and the library's InputField is one line edited by byte, so the field is the app's own. Its state and editing are the core's (ImsdMessages:Edit, tested without a window): a plain struct, insertion at the cursor, Backspace and Delete by code point, Home and End within the line, a newline. Ui:Compose turns the keys into those edits and draws the field one to five lines tall — as many as half the area under the header and the banner holds, and one at the least — with the canvas's word wrapper (a longer text shows the lines that end at the caret's, or the first ones while the caret is among them), a placeholder when empty, the caret at the cursor, and a tap placing the cursor at the nearest byte by the widths the glyphs are drawn at, in the text as it is when the tap lands (an edit since the last frame only asked for one; a field no frame has laid out yet takes a tap as one at its text's end; a tap at or past the last line's end asks for the text's end, where a space the wrapper hung off the line may be). The bar under a conversation holds the field and Send, enabled only with text, a sendable status and an address to send to; Send hands the text to Sync with that address and clears the field (a store that refuses the text keeps the draft) (Model's SendAddress: as a link gave it, else the latest message's — the network's form of a received text, the dialled form of ours — never the key, whose completed country code is a guess that groups; a conversation with neither has Send off, and so has one whose address is not international — a national number, a short code; typed, linked or the message's — and was typed or written under another SIM's plan than the one known now, which the plan each row and the view carry tells (the view's is that of the SIM the address was typed under, which Number's AfterStatus keeps; Number's AnotherPlan, its second caller)); Sync's StateChanged moves the bubble's caption. Keys reach the field while a conversation is open (Escape goes back, Ctrl+Enter sends), a held key repeats through a timer since frames are on demand, and the caret blinks on one. A text typed and not sent is its conversation's, not the view's: leaving the conversation (Back, another one opened by a notification or a link) keeps it by the conversation's key for the run, and opening the conversation again takes it up (Edit's Drafts: an empty field keeps nothing and drops nothing; the draft of a typed or linked address follows imsd's status as the open conversation's key does — Number's AfterStatus over the address and the plan kept with it — so one left before the status brought the country code is found under the key the address makes afterwards; and a second text kept under one key — two keys that became one — goes after the first on a line of its own). Tested: tests/Model, the address a text goes to (the typed or linked one, the latest message's, none for an emptied conversation, none under another SIM's plan than it was typed or written under — a national number with or without a trunk prefix under another country's SIM, a short code under another operator's too, though dialled under the same operator, the own number read when it was typed or not; a national number typed before the own number was read, none under another operator — an international one under any — and a typed address judged by its own plan, whatever the latest row's); tests/Edit (code points of one to four bytes, the moves within a line, the edits that change nothing, the first line shown as the caret moves down a long text; the drafts: kept and taken up by key with the cursor, taken once, an empty field keeping and dropping nothing, one per conversation, a second text under one key on a line of its own; a typed address's following the status — moved when the code comes, not while texts are stored under its key, not under another SIM's status, a list conversation's left alone and the store not asked, the learned plan kept, two keys that became one keeping both texts).
2026-10-18 00:35:39 +02:00
// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
/*
ImsdMessages:Edit — the message field's text and its editing, by code
point: a text message is several lines of UTF-8, and an edit that took a
single byte would leave half a character behind. The window draws the
state, places the cursor where a tap lands and turns its keys into
EditKeys. What a field held when its conversation was left is here too
(Drafts).
*/
export module ImsdMessages:Edit;
import std;
import :Number;
import :Wrap;
export namespace ImsdMessages {
struct ComposeState {
std::string value;
std::size_t cursor = 0; // a byte offset on a code point boundary
Ui, main: the input method, the app id, and touch through the pointer path With the Crafter.Graphics branch delivering touch (the first finger as the pointer), zwp_text_input_v3 and xdg app ids, the app: - sets its app id on the window; - tells the compositor which field has the focus and where its caret is, after every frame that changed it: the number field at once (purpose phone), the message field on a tap or a key; a sheet or leaving the screen takes it back; - shows the input method's composing text in the accent colour at the cursor, each run placed at the advance the one before it was drawn with, applies its deletions by code point and leaves the composing text to the input method, and takes its committed text as typed (the composing text and its deletions are the core's Edit, in tests/Edit; a draft kept for a conversation that is left keeps a word still being composed as text); a tap inside the composing text leaves the cursor where it is, a tap elsewhere in the field commits the word where it was typed and resets the input method, as Send does, so the half-typed word does not move to the tap; a sheet, a hide and leaving a screen by Open (over the number screen or over another conversation), by Back or by the + end the composition the same way and at once (EndComposition: the word committed, the input method told), since the input method starts afresh after, and left on until the next frame it would send its next commit to the screen that opens or have it dropped. The message field starts unfocused, as on a phone, and the caret blinks only in a focused field; - sends what the field shows: Send, like Start, reads the shown text once, the composing word included, and clears the field only once the store took it (a field of nothing but spaces and line breaks is cleared with nothing sent); the field keeps the focus while the input method is reset (disabled, enabled again the next frame) — a refused text leaves the field and the composing word as they are; Start reads the shown text once — the key and the address dialled come from it — so a refused number leaves the composing word to the input method; - logs the window's size on every resize, and which conversation was opened — under --headless; a plain start names no correspondent in its log, as the rest of the app does not. Touch takes the mouse's gesture path, and a touch the compositor cancels (a gesture of its own) arrives as a release without the finger's touch-up: it is fed to the gestures as a cancel, so it taps nothing. Tested: tests/Edit (the composing text kept by a deletion, and put into the field's text by ComposeCommitPreedit).
2026-10-18 02:30:01 +02:00
std::string preedit; // the input method's composing text: shown at the cursor, not yet in the value
bool focused = false;
Ui: the compose field and the send bar A text message needs several lines and UTF-8, and the library's InputField is one line edited by byte, so the field is the app's own. Its state and editing are the core's (ImsdMessages:Edit, tested without a window): a plain struct, insertion at the cursor, Backspace and Delete by code point, Home and End within the line, a newline. Ui:Compose turns the keys into those edits and draws the field one to five lines tall — as many as half the area under the header and the banner holds, and one at the least — with the canvas's word wrapper (a longer text shows the lines that end at the caret's, or the first ones while the caret is among them), a placeholder when empty, the caret at the cursor, and a tap placing the cursor at the nearest byte by the widths the glyphs are drawn at, in the text as it is when the tap lands (an edit since the last frame only asked for one; a field no frame has laid out yet takes a tap as one at its text's end; a tap at or past the last line's end asks for the text's end, where a space the wrapper hung off the line may be). The bar under a conversation holds the field and Send, enabled only with text, a sendable status and an address to send to; Send hands the text to Sync with that address and clears the field (a store that refuses the text keeps the draft) (Model's SendAddress: as a link gave it, else the latest message's — the network's form of a received text, the dialled form of ours — never the key, whose completed country code is a guess that groups; a conversation with neither has Send off, and so has one whose address is not international — a national number, a short code; typed, linked or the message's — and was typed or written under another SIM's plan than the one known now, which the plan each row and the view carry tells (the view's is that of the SIM the address was typed under, which Number's AfterStatus keeps; Number's AnotherPlan, its second caller)); Sync's StateChanged moves the bubble's caption. Keys reach the field while a conversation is open (Escape goes back, Ctrl+Enter sends), a held key repeats through a timer since frames are on demand, and the caret blinks on one. A text typed and not sent is its conversation's, not the view's: leaving the conversation (Back, another one opened by a notification or a link) keeps it by the conversation's key for the run, and opening the conversation again takes it up (Edit's Drafts: an empty field keeps nothing and drops nothing; the draft of a typed or linked address follows imsd's status as the open conversation's key does — Number's AfterStatus over the address and the plan kept with it — so one left before the status brought the country code is found under the key the address makes afterwards; and a second text kept under one key — two keys that became one — goes after the first on a line of its own). Tested: tests/Model, the address a text goes to (the typed or linked one, the latest message's, none for an emptied conversation, none under another SIM's plan than it was typed or written under — a national number with or without a trunk prefix under another country's SIM, a short code under another operator's too, though dialled under the same operator, the own number read when it was typed or not; a national number typed before the own number was read, none under another operator — an international one under any — and a typed address judged by its own plan, whatever the latest row's); tests/Edit (code points of one to four bytes, the moves within a line, the edits that change nothing, the first line shown as the caret moves down a long text; the drafts: kept and taken up by key with the cursor, taken once, an empty field keeping and dropping nothing, one per conversation, a second text under one key on a line of its own; a typed address's following the status — moved when the code comes, not while texts are stored under its key, not under another SIM's status, a list conversation's left alone and the store not asked, the learned plan kept, two keys that became one keeping both texts).
2026-10-18 00:35:39 +02:00
};
Ui, main: the input method, the app id, and touch through the pointer path With the Crafter.Graphics branch delivering touch (the first finger as the pointer), zwp_text_input_v3 and xdg app ids, the app: - sets its app id on the window; - tells the compositor which field has the focus and where its caret is, after every frame that changed it: the number field at once (purpose phone), the message field on a tap or a key; a sheet or leaving the screen takes it back; - shows the input method's composing text in the accent colour at the cursor, each run placed at the advance the one before it was drawn with, applies its deletions by code point and leaves the composing text to the input method, and takes its committed text as typed (the composing text and its deletions are the core's Edit, in tests/Edit; a draft kept for a conversation that is left keeps a word still being composed as text); a tap inside the composing text leaves the cursor where it is, a tap elsewhere in the field commits the word where it was typed and resets the input method, as Send does, so the half-typed word does not move to the tap; a sheet, a hide and leaving a screen by Open (over the number screen or over another conversation), by Back or by the + end the composition the same way and at once (EndComposition: the word committed, the input method told), since the input method starts afresh after, and left on until the next frame it would send its next commit to the screen that opens or have it dropped. The message field starts unfocused, as on a phone, and the caret blinks only in a focused field; - sends what the field shows: Send, like Start, reads the shown text once, the composing word included, and clears the field only once the store took it (a field of nothing but spaces and line breaks is cleared with nothing sent); the field keeps the focus while the input method is reset (disabled, enabled again the next frame) — a refused text leaves the field and the composing word as they are; Start reads the shown text once — the key and the address dialled come from it — so a refused number leaves the composing word to the input method; - logs the window's size on every resize, and which conversation was opened — under --headless; a plain start names no correspondent in its log, as the rest of the app does not. Touch takes the mouse's gesture path, and a touch the compositor cancels (a gesture of its own) arrives as a release without the finger's touch-up: it is fed to the gestures as a cancel, so it taps nothing. Tested: tests/Edit (the composing text kept by a deletion, and put into the field's text by ComposeCommitPreedit).
2026-10-18 02:30:01 +02:00
// The text as shown: the value with the composing text at the cursor.
std::string ComposeShown(const ComposeState& s) {
std::string shown = s.value;
shown.insert(s.cursor, s.preedit);
return shown;
}
std::size_t ShownCursor(const ComposeState& s) { return s.cursor + s.preedit.size(); }
Ui: the compose field and the send bar A text message needs several lines and UTF-8, and the library's InputField is one line edited by byte, so the field is the app's own. Its state and editing are the core's (ImsdMessages:Edit, tested without a window): a plain struct, insertion at the cursor, Backspace and Delete by code point, Home and End within the line, a newline. Ui:Compose turns the keys into those edits and draws the field one to five lines tall — as many as half the area under the header and the banner holds, and one at the least — with the canvas's word wrapper (a longer text shows the lines that end at the caret's, or the first ones while the caret is among them), a placeholder when empty, the caret at the cursor, and a tap placing the cursor at the nearest byte by the widths the glyphs are drawn at, in the text as it is when the tap lands (an edit since the last frame only asked for one; a field no frame has laid out yet takes a tap as one at its text's end; a tap at or past the last line's end asks for the text's end, where a space the wrapper hung off the line may be). The bar under a conversation holds the field and Send, enabled only with text, a sendable status and an address to send to; Send hands the text to Sync with that address and clears the field (a store that refuses the text keeps the draft) (Model's SendAddress: as a link gave it, else the latest message's — the network's form of a received text, the dialled form of ours — never the key, whose completed country code is a guess that groups; a conversation with neither has Send off, and so has one whose address is not international — a national number, a short code; typed, linked or the message's — and was typed or written under another SIM's plan than the one known now, which the plan each row and the view carry tells (the view's is that of the SIM the address was typed under, which Number's AfterStatus keeps; Number's AnotherPlan, its second caller)); Sync's StateChanged moves the bubble's caption. Keys reach the field while a conversation is open (Escape goes back, Ctrl+Enter sends), a held key repeats through a timer since frames are on demand, and the caret blinks on one. A text typed and not sent is its conversation's, not the view's: leaving the conversation (Back, another one opened by a notification or a link) keeps it by the conversation's key for the run, and opening the conversation again takes it up (Edit's Drafts: an empty field keeps nothing and drops nothing; the draft of a typed or linked address follows imsd's status as the open conversation's key does — Number's AfterStatus over the address and the plan kept with it — so one left before the status brought the country code is found under the key the address makes afterwards; and a second text kept under one key — two keys that became one — goes after the first on a line of its own). Tested: tests/Model, the address a text goes to (the typed or linked one, the latest message's, none for an emptied conversation, none under another SIM's plan than it was typed or written under — a national number with or without a trunk prefix under another country's SIM, a short code under another operator's too, though dialled under the same operator, the own number read when it was typed or not; a national number typed before the own number was read, none under another operator — an international one under any — and a typed address judged by its own plan, whatever the latest row's); tests/Edit (code points of one to four bytes, the moves within a line, the edits that change nothing, the first line shown as the caret moves down a long text; the drafts: kept and taken up by key with the cursor, taken once, an empty field keeping and dropping nothing, one per conversation, a second text under one key on a line of its own; a typed address's following the status — moved when the code comes, not while texts are stored under its key, not under another SIM's status, a list conversation's left alone and the store not asked, the learned plan kept, two keys that became one keeping both texts).
2026-10-18 00:35:39 +02:00
// The byte offset of the code point before `at`.
std::size_t PreviousCodepoint(std::string_view s, std::size_t at) {
if (at == 0) return 0;
std::size_t i = at - 1;
while (i > 0 && (static_cast<std::uint8_t>(s[i]) & 0xC0) == 0x80) --i;
return i;
}
std::size_t NextCodepoint(std::string_view s, std::size_t at) {
if (at >= s.size()) return s.size();
std::size_t i = at;
DecodeUtf8(s, i);
return i;
}
void ComposeInsert(ComposeState& c, std::string_view utf8) {
c.value.insert(c.cursor, utf8);
c.cursor += utf8.size();
}
Ui, main: the input method, the app id, and touch through the pointer path With the Crafter.Graphics branch delivering touch (the first finger as the pointer), zwp_text_input_v3 and xdg app ids, the app: - sets its app id on the window; - tells the compositor which field has the focus and where its caret is, after every frame that changed it: the number field at once (purpose phone), the message field on a tap or a key; a sheet or leaving the screen takes it back; - shows the input method's composing text in the accent colour at the cursor, each run placed at the advance the one before it was drawn with, applies its deletions by code point and leaves the composing text to the input method, and takes its committed text as typed (the composing text and its deletions are the core's Edit, in tests/Edit; a draft kept for a conversation that is left keeps a word still being composed as text); a tap inside the composing text leaves the cursor where it is, a tap elsewhere in the field commits the word where it was typed and resets the input method, as Send does, so the half-typed word does not move to the tap; a sheet, a hide and leaving a screen by Open (over the number screen or over another conversation), by Back or by the + end the composition the same way and at once (EndComposition: the word committed, the input method told), since the input method starts afresh after, and left on until the next frame it would send its next commit to the screen that opens or have it dropped. The message field starts unfocused, as on a phone, and the caret blinks only in a focused field; - sends what the field shows: Send, like Start, reads the shown text once, the composing word included, and clears the field only once the store took it (a field of nothing but spaces and line breaks is cleared with nothing sent); the field keeps the focus while the input method is reset (disabled, enabled again the next frame) — a refused text leaves the field and the composing word as they are; Start reads the shown text once — the key and the address dialled come from it — so a refused number leaves the composing word to the input method; - logs the window's size on every resize, and which conversation was opened — under --headless; a plain start names no correspondent in its log, as the rest of the app does not. Touch takes the mouse's gesture path, and a touch the compositor cancels (a gesture of its own) arrives as a release without the finger's touch-up: it is fed to the gestures as a cancel, so it taps nothing. Tested: tests/Edit (the composing text kept by a deletion, and put into the field's text by ComposeCommitPreedit).
2026-10-18 02:30:01 +02:00
// The input method's deletion: so many bytes before and after the cursor,
// rounded out to code points. The composing text stays; the input method
// replaces it when it changes.
void ComposeDeleteAround(ComposeState& c, std::size_t beforeBytes, std::size_t afterBytes) {
std::size_t from = c.cursor;
while (from > 0 && c.cursor - from < beforeBytes) from = PreviousCodepoint(c.value, from);
std::size_t to = c.cursor;
while (to < c.value.size() && to - c.cursor < afterBytes) to = NextCodepoint(c.value, to);
c.value.erase(from, to - from);
c.cursor = from;
}
Ui: the compose field and the send bar A text message needs several lines and UTF-8, and the library's InputField is one line edited by byte, so the field is the app's own. Its state and editing are the core's (ImsdMessages:Edit, tested without a window): a plain struct, insertion at the cursor, Backspace and Delete by code point, Home and End within the line, a newline. Ui:Compose turns the keys into those edits and draws the field one to five lines tall — as many as half the area under the header and the banner holds, and one at the least — with the canvas's word wrapper (a longer text shows the lines that end at the caret's, or the first ones while the caret is among them), a placeholder when empty, the caret at the cursor, and a tap placing the cursor at the nearest byte by the widths the glyphs are drawn at, in the text as it is when the tap lands (an edit since the last frame only asked for one; a field no frame has laid out yet takes a tap as one at its text's end; a tap at or past the last line's end asks for the text's end, where a space the wrapper hung off the line may be). The bar under a conversation holds the field and Send, enabled only with text, a sendable status and an address to send to; Send hands the text to Sync with that address and clears the field (a store that refuses the text keeps the draft) (Model's SendAddress: as a link gave it, else the latest message's — the network's form of a received text, the dialled form of ours — never the key, whose completed country code is a guess that groups; a conversation with neither has Send off, and so has one whose address is not international — a national number, a short code; typed, linked or the message's — and was typed or written under another SIM's plan than the one known now, which the plan each row and the view carry tells (the view's is that of the SIM the address was typed under, which Number's AfterStatus keeps; Number's AnotherPlan, its second caller)); Sync's StateChanged moves the bubble's caption. Keys reach the field while a conversation is open (Escape goes back, Ctrl+Enter sends), a held key repeats through a timer since frames are on demand, and the caret blinks on one. A text typed and not sent is its conversation's, not the view's: leaving the conversation (Back, another one opened by a notification or a link) keeps it by the conversation's key for the run, and opening the conversation again takes it up (Edit's Drafts: an empty field keeps nothing and drops nothing; the draft of a typed or linked address follows imsd's status as the open conversation's key does — Number's AfterStatus over the address and the plan kept with it — so one left before the status brought the country code is found under the key the address makes afterwards; and a second text kept under one key — two keys that became one — goes after the first on a line of its own). Tested: tests/Model, the address a text goes to (the typed or linked one, the latest message's, none for an emptied conversation, none under another SIM's plan than it was typed or written under — a national number with or without a trunk prefix under another country's SIM, a short code under another operator's too, though dialled under the same operator, the own number read when it was typed or not; a national number typed before the own number was read, none under another operator — an international one under any — and a typed address judged by its own plan, whatever the latest row's); tests/Edit (code points of one to four bytes, the moves within a line, the edits that change nothing, the first line shown as the caret moves down a long text; the drafts: kept and taken up by key with the cursor, taken once, an empty field keeping and dropping nothing, one per conversation, a second text under one key on a line of its own; a typed address's following the status — moved when the code comes, not while texts are stored under its key, not under another SIM's status, a list conversation's left alone and the store not asked, the learned plan kept, two keys that became one keeping both texts).
2026-10-18 00:35:39 +02:00
enum class EditKey : std::uint8_t { Backspace, Delete, Left, Right, Home, End, Newline };
// Applies one key. False when Backspace or Delete has nothing to delete;
// a move is true even where the cursor cannot go further.
bool ComposeEdit(ComposeState& c, EditKey key) {
if (key == EditKey::Backspace) {
if (c.cursor == 0) return false;
const std::size_t from = PreviousCodepoint(c.value, c.cursor);
c.value.erase(from, c.cursor - from);
c.cursor = from;
return true;
}
if (key == EditKey::Delete) {
if (c.cursor >= c.value.size()) return false;
c.value.erase(c.cursor, NextCodepoint(c.value, c.cursor) - c.cursor);
return true;
}
if (key == EditKey::Left) {
c.cursor = PreviousCodepoint(c.value, c.cursor);
return true;
}
if (key == EditKey::Right) {
c.cursor = NextCodepoint(c.value, c.cursor);
return true;
}
if (key == EditKey::Home) {
const std::size_t nl = c.value.rfind('\n', c.cursor == 0 ? 0 : c.cursor - 1);
c.cursor = (nl == std::string::npos || c.cursor == 0) ? 0 : nl + 1;
return true;
}
if (key == EditKey::End) {
const std::size_t nl = c.value.find('\n', c.cursor);
c.cursor = nl == std::string::npos ? c.value.size() : nl;
return true;
}
if (key == EditKey::Newline) {
ComposeInsert(c, "\n");
return true;
}
return false;
}
// The byte a tap at or past a line's end asks for: the end of the text
// on the last line (the last by index: a text ending in a newline has
// an empty last line, and the line before it ends at that newline);
// before a hard break, the newline — after the space that overflowed
// and hangs off the line with it (Wrap), so a word typed there stays a
// word of its own; at a soft wrap, the line's end.
std::size_t ComposeLineEnd(std::span<const WrappedLine> lines, std::size_t li, std::string_view text) {
if (li + 1 >= lines.size()) return text.size();
const std::size_t next = lines[li + 1].begin;
if (next > lines[li].end && text[next - 1] == '\n') return next - 1;
return lines[li].end;
}
// The first of the `shown` lines a field of that height draws so that the
// caret's line is among them: the text's first lines until the caret
// passes the field's last line, then the caret's line is the last shown.
std::size_t ComposeFirstLine(std::size_t caretLine, std::size_t shown) {
return caretLine + 1 > shown ? caretLine + 1 - shown : 0;
}
Ui, main: the input method, the app id, and touch through the pointer path With the Crafter.Graphics branch delivering touch (the first finger as the pointer), zwp_text_input_v3 and xdg app ids, the app: - sets its app id on the window; - tells the compositor which field has the focus and where its caret is, after every frame that changed it: the number field at once (purpose phone), the message field on a tap or a key; a sheet or leaving the screen takes it back; - shows the input method's composing text in the accent colour at the cursor, each run placed at the advance the one before it was drawn with, applies its deletions by code point and leaves the composing text to the input method, and takes its committed text as typed (the composing text and its deletions are the core's Edit, in tests/Edit; a draft kept for a conversation that is left keeps a word still being composed as text); a tap inside the composing text leaves the cursor where it is, a tap elsewhere in the field commits the word where it was typed and resets the input method, as Send does, so the half-typed word does not move to the tap; a sheet, a hide and leaving a screen by Open (over the number screen or over another conversation), by Back or by the + end the composition the same way and at once (EndComposition: the word committed, the input method told), since the input method starts afresh after, and left on until the next frame it would send its next commit to the screen that opens or have it dropped. The message field starts unfocused, as on a phone, and the caret blinks only in a focused field; - sends what the field shows: Send, like Start, reads the shown text once, the composing word included, and clears the field only once the store took it (a field of nothing but spaces and line breaks is cleared with nothing sent); the field keeps the focus while the input method is reset (disabled, enabled again the next frame) — a refused text leaves the field and the composing word as they are; Start reads the shown text once — the key and the address dialled come from it — so a refused number leaves the composing word to the input method; - logs the window's size on every resize, and which conversation was opened — under --headless; a plain start names no correspondent in its log, as the rest of the app does not. Touch takes the mouse's gesture path, and a touch the compositor cancels (a gesture of its own) arrives as a release without the finger's touch-up: it is fed to the gestures as a cancel, so it taps nothing. Tested: tests/Edit (the composing text kept by a deletion, and put into the field's text by ComposeCommitPreedit).
2026-10-18 02:30:01 +02:00
// Takes the composing text into the value at the cursor, as the input
// method would commit it: what Send and Start read is what the field shows.
void ComposeCommitPreedit(ComposeState& c) {
if (c.preedit.empty()) return;
const std::string preedit = std::move(c.preedit);
c.preedit.clear();
ComposeInsert(c, preedit);
}
Ui, Edit: a keyboard sent away stays away until the field is tapped On Plasma Mobile the on-screen keyboard came straight back after its own hide key. The key makes the compositor give the keyboard's room back: the window grows, the message field moves down with the window's lower edge, and UpdateTextInput told the compositor the caret's new place, as it does after every frame in which the caret moved. No focus had changed and no enable went out again (the library sends one per focus); 120 ms after that state was committed the keyboard was back, nothing else having been sent. A caret that only followed the window's growth is no longer told at once: its box as it was, lower by what the window gained (CaretFollowedGrowth, in Edit with its tests). It is told with the next thing that is — a key that moves the caret, the field's tap — and a window that shrinks back makes the old place true again. The compositor keeps the old place meanwhile, which lies inside the taller window. With that telling gone nothing would bring the keyboard back, so a tap on a field that kept the focus while the window grew asks for it (AskKeyboard): the text input goes off, the composing word going into the field as at any reset, and the next frame turns it on again, which is the request a compositor shows its keyboard for. A tap with the keyboard up places the cursor as before. The number field of the new-conversation screen takes the same tap. Tested: tests/Edit (a caret lower by the window's growth, and one within a pixel of that; and what is still told: a caret that stayed, one that moved along its line or by another amount, a window as tall as it was or lower, a box of another size). On a Fairphone 6 (Plasma Mobile 6.8.2, plasma-keyboard 6.8.2), by the protocol's trace (WAYLAND_DEBUG): before, the hide key's resize is followed by set_cursor_rectangle and commit, and by the keyboard's resize 120 ms after them; with this, nothing is sent after the hide key's resize and the keyboard stays away, and a tap on the field sends disable, then enable with the caret's place, the keyboard is back 85 ms later, and typing goes on. The number field's tap was not tried on the phone, and no bench on the workstation has an on-screen keyboard.
2026-11-18 04:20:42 +01:00
// What the compositor was last told of a field's caret for its text
// input: the caret's box, in a window how tall.
struct CaretReport {
float x = 0;
float y = 0;
float w = 0;
float h = 0;
float windowHeight = 0;
};
// Whether a caret moved only because the window grew under it: its box
// as it was but for its place, which went down by what the window
// gained. That is a field at the window's lower edge after the
// on-screen keyboard gave its room back (the keyboard's own hide key).
// Told at once, the move would be a new text-input state, and a state
// committed while the input is on brings the keyboard back (seen on
// Plasma Mobile: KWin 6.8.2, plasma-keyboard), so it is held until the
// caret moves for another reason. A window that shrank, or a caret that
// moved along its text, is told as ever.
bool CaretFollowedGrowth(const CaretReport& told, const CaretReport& now) {
const float grown = now.windowHeight - told.windowHeight;
if (grown <= 0) return false;
const auto near = [](float a, float b) { return std::abs(a - b) <= 1.0f; };
return near(now.x, told.x) && near(now.w, told.w) && near(now.h, told.h) && near(now.y - told.y, grown);
}
Ui: the compose field and the send bar A text message needs several lines and UTF-8, and the library's InputField is one line edited by byte, so the field is the app's own. Its state and editing are the core's (ImsdMessages:Edit, tested without a window): a plain struct, insertion at the cursor, Backspace and Delete by code point, Home and End within the line, a newline. Ui:Compose turns the keys into those edits and draws the field one to five lines tall — as many as half the area under the header and the banner holds, and one at the least — with the canvas's word wrapper (a longer text shows the lines that end at the caret's, or the first ones while the caret is among them), a placeholder when empty, the caret at the cursor, and a tap placing the cursor at the nearest byte by the widths the glyphs are drawn at, in the text as it is when the tap lands (an edit since the last frame only asked for one; a field no frame has laid out yet takes a tap as one at its text's end; a tap at or past the last line's end asks for the text's end, where a space the wrapper hung off the line may be). The bar under a conversation holds the field and Send, enabled only with text, a sendable status and an address to send to; Send hands the text to Sync with that address and clears the field (a store that refuses the text keeps the draft) (Model's SendAddress: as a link gave it, else the latest message's — the network's form of a received text, the dialled form of ours — never the key, whose completed country code is a guess that groups; a conversation with neither has Send off, and so has one whose address is not international — a national number, a short code; typed, linked or the message's — and was typed or written under another SIM's plan than the one known now, which the plan each row and the view carry tells (the view's is that of the SIM the address was typed under, which Number's AfterStatus keeps; Number's AnotherPlan, its second caller)); Sync's StateChanged moves the bubble's caption. Keys reach the field while a conversation is open (Escape goes back, Ctrl+Enter sends), a held key repeats through a timer since frames are on demand, and the caret blinks on one. A text typed and not sent is its conversation's, not the view's: leaving the conversation (Back, another one opened by a notification or a link) keeps it by the conversation's key for the run, and opening the conversation again takes it up (Edit's Drafts: an empty field keeps nothing and drops nothing; the draft of a typed or linked address follows imsd's status as the open conversation's key does — Number's AfterStatus over the address and the plan kept with it — so one left before the status brought the country code is found under the key the address makes afterwards; and a second text kept under one key — two keys that became one — goes after the first on a line of its own). Tested: tests/Model, the address a text goes to (the typed or linked one, the latest message's, none for an emptied conversation, none under another SIM's plan than it was typed or written under — a national number with or without a trunk prefix under another country's SIM, a short code under another operator's too, though dialled under the same operator, the own number read when it was typed or not; a national number typed before the own number was read, none under another operator — an international one under any — and a typed address judged by its own plan, whatever the latest row's); tests/Edit (code points of one to four bytes, the moves within a line, the edits that change nothing, the first line shown as the caret moves down a long text; the drafts: kept and taken up by key with the cursor, taken once, an empty field keeping and dropping nothing, one per conversation, a second text under one key on a line of its own; a typed address's following the status — moved when the code comes, not while texts are stored under its key, not under another SIM's status, a list conversation's left alone and the store not asked, the learned plan kept, two keys that became one keeping both texts).
2026-10-18 00:35:39 +02:00
// What was typed in the conversations that were left, and not sent, by
// conversation key, for this run. A draft is its conversation's, not
// the view's: leaving the conversation keeps it, opening it again
Ui, main: the new-conversation screen and the long-press sheets The + opens a screen with a number field (its placeholder "Number", a parameter of the compose field now) and Start; the number becomes a conversation key through Number's ConversationKey, as an sms: link's does (E.164 through the country code, a short code as digits), anything else is refused in place. A long press on a conversation row offers to delete the conversation, on a message to copy its text to the clipboard or delete it; only those two have one: App tells the recogniser before each press whether what it lands on has a long press (GestureDetector's longPress), and without one a press held as long — on a button, a field, a sheet's row — stays a tap at its release, so a slow finger presses the button all the same. A sheet draws on the overlay layer over a scrim and pushes its regions last, so they win the hit test, and the wheel scrolls nothing under it; Escape, the back arrow and a tap outside dismiss it. Deleting a conversation also closes its notification and drops its draft; the + keeps the draft of the conversation it leaves, as Back does, and so does a view that closes because its last message was deleted. The deletes go through Sync (Erase, EraseConversation: the commit before, which keeps a deleted text deleted). The number field's box is drawn by its screen, as the send bar's is by the bar: the shared field drawing paints no background of its own. Opening a conversation, from a notification or a link, leaves the new-conversation screen and any sheet, and the + leaves any sheet. A key whose press changed the screen acts once: held, its repeats are not the new screen's — Enter, which started the conversation, would type line breaks into its field, and Escape would go on back, from a sheet through the conversation and its draft. A sheet that asks to delete a conversation goes when a text arrives for it: a yes would delete that text unread. A press on the conversation's row opens no such sheet either while the row it aimed at had not shown the text — the regions are a frame's: the press that is down when the text arrives, and one that comes down before the next frame is drawn, have no long press; a release before the long-press time is still the row's tap, while the row stays under the finger. --new and --bench-sheet put either on screen for the bench (--bench-sheet conversation or message, each on the screen a long press opens it over: another value is refused, and one that finds nothing to press says so in the log), and are window flags as --screenshot is. Tested: the screens and the sheets by the bench (--new, --bench-sheet) and the phone step's screenshots; the deletes' logic with the commit before, in tests/Store and tests/Sync; the press without a long press in tests/Gesture (the timer gives no long press and a move within the slop nothing; the release is the tap, however late; a slide off the control is a drag); a deleted conversation's draft dropped, in tests/Edit. The press on a row a text arrived for has no bench: none holds a finger on a row.
2026-11-01 18:11:40 +01:00
// takes it up, and it goes when it is sent or the conversation is
// deleted.
Ui: the compose field and the send bar A text message needs several lines and UTF-8, and the library's InputField is one line edited by byte, so the field is the app's own. Its state and editing are the core's (ImsdMessages:Edit, tested without a window): a plain struct, insertion at the cursor, Backspace and Delete by code point, Home and End within the line, a newline. Ui:Compose turns the keys into those edits and draws the field one to five lines tall — as many as half the area under the header and the banner holds, and one at the least — with the canvas's word wrapper (a longer text shows the lines that end at the caret's, or the first ones while the caret is among them), a placeholder when empty, the caret at the cursor, and a tap placing the cursor at the nearest byte by the widths the glyphs are drawn at, in the text as it is when the tap lands (an edit since the last frame only asked for one; a field no frame has laid out yet takes a tap as one at its text's end; a tap at or past the last line's end asks for the text's end, where a space the wrapper hung off the line may be). The bar under a conversation holds the field and Send, enabled only with text, a sendable status and an address to send to; Send hands the text to Sync with that address and clears the field (a store that refuses the text keeps the draft) (Model's SendAddress: as a link gave it, else the latest message's — the network's form of a received text, the dialled form of ours — never the key, whose completed country code is a guess that groups; a conversation with neither has Send off, and so has one whose address is not international — a national number, a short code; typed, linked or the message's — and was typed or written under another SIM's plan than the one known now, which the plan each row and the view carry tells (the view's is that of the SIM the address was typed under, which Number's AfterStatus keeps; Number's AnotherPlan, its second caller)); Sync's StateChanged moves the bubble's caption. Keys reach the field while a conversation is open (Escape goes back, Ctrl+Enter sends), a held key repeats through a timer since frames are on demand, and the caret blinks on one. A text typed and not sent is its conversation's, not the view's: leaving the conversation (Back, another one opened by a notification or a link) keeps it by the conversation's key for the run, and opening the conversation again takes it up (Edit's Drafts: an empty field keeps nothing and drops nothing; the draft of a typed or linked address follows imsd's status as the open conversation's key does — Number's AfterStatus over the address and the plan kept with it — so one left before the status brought the country code is found under the key the address makes afterwards; and a second text kept under one key — two keys that became one — goes after the first on a line of its own). Tested: tests/Model, the address a text goes to (the typed or linked one, the latest message's, none for an emptied conversation, none under another SIM's plan than it was typed or written under — a national number with or without a trunk prefix under another country's SIM, a short code under another operator's too, though dialled under the same operator, the own number read when it was typed or not; a national number typed before the own number was read, none under another operator — an international one under any — and a typed address judged by its own plan, whatever the latest row's); tests/Edit (code points of one to four bytes, the moves within a line, the edits that change nothing, the first line shown as the caret moves down a long text; the drafts: kept and taken up by key with the cursor, taken once, an empty field keeping and dropping nothing, one per conversation, a second text under one key on a line of its own; a typed address's following the status — moved when the code comes, not while texts are stored under its key, not under another SIM's status, a list conversation's left alone and the store not asked, the learned plan kept, two keys that became one keeping both texts).
2026-10-18 00:35:39 +02:00
class Drafts {
public:
Ui, main: the input method, the app id, and touch through the pointer path With the Crafter.Graphics branch delivering touch (the first finger as the pointer), zwp_text_input_v3 and xdg app ids, the app: - sets its app id on the window; - tells the compositor which field has the focus and where its caret is, after every frame that changed it: the number field at once (purpose phone), the message field on a tap or a key; a sheet or leaving the screen takes it back; - shows the input method's composing text in the accent colour at the cursor, each run placed at the advance the one before it was drawn with, applies its deletions by code point and leaves the composing text to the input method, and takes its committed text as typed (the composing text and its deletions are the core's Edit, in tests/Edit; a draft kept for a conversation that is left keeps a word still being composed as text); a tap inside the composing text leaves the cursor where it is, a tap elsewhere in the field commits the word where it was typed and resets the input method, as Send does, so the half-typed word does not move to the tap; a sheet, a hide and leaving a screen by Open (over the number screen or over another conversation), by Back or by the + end the composition the same way and at once (EndComposition: the word committed, the input method told), since the input method starts afresh after, and left on until the next frame it would send its next commit to the screen that opens or have it dropped. The message field starts unfocused, as on a phone, and the caret blinks only in a focused field; - sends what the field shows: Send, like Start, reads the shown text once, the composing word included, and clears the field only once the store took it (a field of nothing but spaces and line breaks is cleared with nothing sent); the field keeps the focus while the input method is reset (disabled, enabled again the next frame) — a refused text leaves the field and the composing word as they are; Start reads the shown text once — the key and the address dialled come from it — so a refused number leaves the composing word to the input method; - logs the window's size on every resize, and which conversation was opened — under --headless; a plain start names no correspondent in its log, as the rest of the app does not. Touch takes the mouse's gesture path, and a touch the compositor cancels (a gesture of its own) arrives as a release without the finger's touch-up: it is fed to the gestures as a cancel, so it taps nothing. Tested: tests/Edit (the composing text kept by a deletion, and put into the field's text by ComposeCommitPreedit).
2026-10-18 02:30:01 +02:00
// A conversation is left: what its field holds is kept — a word
// still being composed as text — and comes back as a field is
// opened; an empty field keeps nothing and drops nothing. `dialled`
// and `plan` are the view's: the address as typed or linked — ""
// for a conversation opened from the list, whose draft Status
// leaves where it is — and the plan of the SIM it was opened
// under. A second text kept under one key (two keys that became
// one: Status, and the open conversation's own move) goes after
// the first on a line of its own, so nothing typed is dropped.
Ui: the compose field and the send bar A text message needs several lines and UTF-8, and the library's InputField is one line edited by byte, so the field is the app's own. Its state and editing are the core's (ImsdMessages:Edit, tested without a window): a plain struct, insertion at the cursor, Backspace and Delete by code point, Home and End within the line, a newline. Ui:Compose turns the keys into those edits and draws the field one to five lines tall — as many as half the area under the header and the banner holds, and one at the least — with the canvas's word wrapper (a longer text shows the lines that end at the caret's, or the first ones while the caret is among them), a placeholder when empty, the caret at the cursor, and a tap placing the cursor at the nearest byte by the widths the glyphs are drawn at, in the text as it is when the tap lands (an edit since the last frame only asked for one; a field no frame has laid out yet takes a tap as one at its text's end; a tap at or past the last line's end asks for the text's end, where a space the wrapper hung off the line may be). The bar under a conversation holds the field and Send, enabled only with text, a sendable status and an address to send to; Send hands the text to Sync with that address and clears the field (a store that refuses the text keeps the draft) (Model's SendAddress: as a link gave it, else the latest message's — the network's form of a received text, the dialled form of ours — never the key, whose completed country code is a guess that groups; a conversation with neither has Send off, and so has one whose address is not international — a national number, a short code; typed, linked or the message's — and was typed or written under another SIM's plan than the one known now, which the plan each row and the view carry tells (the view's is that of the SIM the address was typed under, which Number's AfterStatus keeps; Number's AnotherPlan, its second caller)); Sync's StateChanged moves the bubble's caption. Keys reach the field while a conversation is open (Escape goes back, Ctrl+Enter sends), a held key repeats through a timer since frames are on demand, and the caret blinks on one. A text typed and not sent is its conversation's, not the view's: leaving the conversation (Back, another one opened by a notification or a link) keeps it by the conversation's key for the run, and opening the conversation again takes it up (Edit's Drafts: an empty field keeps nothing and drops nothing; the draft of a typed or linked address follows imsd's status as the open conversation's key does — Number's AfterStatus over the address and the plan kept with it — so one left before the status brought the country code is found under the key the address makes afterwards; and a second text kept under one key — two keys that became one — goes after the first on a line of its own). Tested: tests/Model, the address a text goes to (the typed or linked one, the latest message's, none for an emptied conversation, none under another SIM's plan than it was typed or written under — a national number with or without a trunk prefix under another country's SIM, a short code under another operator's too, though dialled under the same operator, the own number read when it was typed or not; a national number typed before the own number was read, none under another operator — an international one under any — and a typed address judged by its own plan, whatever the latest row's); tests/Edit (code points of one to four bytes, the moves within a line, the edits that change nothing, the first line shown as the caret moves down a long text; the drafts: kept and taken up by key with the cursor, taken once, an empty field keeping and dropping nothing, one per conversation, a second text under one key on a line of its own; a typed address's following the status — moved when the code comes, not while texts are stored under its key, not under another SIM's status, a list conversation's left alone and the store not asked, the learned plan kept, two keys that became one keeping both texts).
2026-10-18 00:35:39 +02:00
void Keep(std::string_view key, ComposeState field, std::string_view dialled = {}, SimPlan plan = {}) {
Ui, main: the input method, the app id, and touch through the pointer path With the Crafter.Graphics branch delivering touch (the first finger as the pointer), zwp_text_input_v3 and xdg app ids, the app: - sets its app id on the window; - tells the compositor which field has the focus and where its caret is, after every frame that changed it: the number field at once (purpose phone), the message field on a tap or a key; a sheet or leaving the screen takes it back; - shows the input method's composing text in the accent colour at the cursor, each run placed at the advance the one before it was drawn with, applies its deletions by code point and leaves the composing text to the input method, and takes its committed text as typed (the composing text and its deletions are the core's Edit, in tests/Edit; a draft kept for a conversation that is left keeps a word still being composed as text); a tap inside the composing text leaves the cursor where it is, a tap elsewhere in the field commits the word where it was typed and resets the input method, as Send does, so the half-typed word does not move to the tap; a sheet, a hide and leaving a screen by Open (over the number screen or over another conversation), by Back or by the + end the composition the same way and at once (EndComposition: the word committed, the input method told), since the input method starts afresh after, and left on until the next frame it would send its next commit to the screen that opens or have it dropped. The message field starts unfocused, as on a phone, and the caret blinks only in a focused field; - sends what the field shows: Send, like Start, reads the shown text once, the composing word included, and clears the field only once the store took it (a field of nothing but spaces and line breaks is cleared with nothing sent); the field keeps the focus while the input method is reset (disabled, enabled again the next frame) — a refused text leaves the field and the composing word as they are; Start reads the shown text once — the key and the address dialled come from it — so a refused number leaves the composing word to the input method; - logs the window's size on every resize, and which conversation was opened — under --headless; a plain start names no correspondent in its log, as the rest of the app does not. Touch takes the mouse's gesture path, and a touch the compositor cancels (a gesture of its own) arrives as a release without the finger's touch-up: it is fed to the gestures as a cancel, so it taps nothing. Tested: tests/Edit (the composing text kept by a deletion, and put into the field's text by ComposeCommitPreedit).
2026-10-18 02:30:01 +02:00
ComposeCommitPreedit(field);
Ui: the compose field and the send bar A text message needs several lines and UTF-8, and the library's InputField is one line edited by byte, so the field is the app's own. Its state and editing are the core's (ImsdMessages:Edit, tested without a window): a plain struct, insertion at the cursor, Backspace and Delete by code point, Home and End within the line, a newline. Ui:Compose turns the keys into those edits and draws the field one to five lines tall — as many as half the area under the header and the banner holds, and one at the least — with the canvas's word wrapper (a longer text shows the lines that end at the caret's, or the first ones while the caret is among them), a placeholder when empty, the caret at the cursor, and a tap placing the cursor at the nearest byte by the widths the glyphs are drawn at, in the text as it is when the tap lands (an edit since the last frame only asked for one; a field no frame has laid out yet takes a tap as one at its text's end; a tap at or past the last line's end asks for the text's end, where a space the wrapper hung off the line may be). The bar under a conversation holds the field and Send, enabled only with text, a sendable status and an address to send to; Send hands the text to Sync with that address and clears the field (a store that refuses the text keeps the draft) (Model's SendAddress: as a link gave it, else the latest message's — the network's form of a received text, the dialled form of ours — never the key, whose completed country code is a guess that groups; a conversation with neither has Send off, and so has one whose address is not international — a national number, a short code; typed, linked or the message's — and was typed or written under another SIM's plan than the one known now, which the plan each row and the view carry tells (the view's is that of the SIM the address was typed under, which Number's AfterStatus keeps; Number's AnotherPlan, its second caller)); Sync's StateChanged moves the bubble's caption. Keys reach the field while a conversation is open (Escape goes back, Ctrl+Enter sends), a held key repeats through a timer since frames are on demand, and the caret blinks on one. A text typed and not sent is its conversation's, not the view's: leaving the conversation (Back, another one opened by a notification or a link) keeps it by the conversation's key for the run, and opening the conversation again takes it up (Edit's Drafts: an empty field keeps nothing and drops nothing; the draft of a typed or linked address follows imsd's status as the open conversation's key does — Number's AfterStatus over the address and the plan kept with it — so one left before the status brought the country code is found under the key the address makes afterwards; and a second text kept under one key — two keys that became one — goes after the first on a line of its own). Tested: tests/Model, the address a text goes to (the typed or linked one, the latest message's, none for an emptied conversation, none under another SIM's plan than it was typed or written under — a national number with or without a trunk prefix under another country's SIM, a short code under another operator's too, though dialled under the same operator, the own number read when it was typed or not; a national number typed before the own number was read, none under another operator — an international one under any — and a typed address judged by its own plan, whatever the latest row's); tests/Edit (code points of one to four bytes, the moves within a line, the edits that change nothing, the first line shown as the caret moves down a long text; the drafts: kept and taken up by key with the cursor, taken once, an empty field keeping and dropping nothing, one per conversation, a second text under one key on a line of its own; a typed address's following the status — moved when the code comes, not while texts are stored under its key, not under another SIM's status, a list conversation's left alone and the store not asked, the learned plan kept, two keys that became one keeping both texts).
2026-10-18 00:35:39 +02:00
if (field.value.empty()) return;
field.focused = ComposeState{}.focused;
const auto kept = byKey.find(key);
if (kept == byKey.end()) {
byKey.emplace(std::string(key), Kept{ std::move(field), std::string(dialled), std::move(plan) });
return;
}
kept->second.field.value += '\n';
kept->second.field.value += field.value;
kept->second.field.cursor = kept->second.field.value.size();
}
// A conversation is opened: its draft, which the field holds from
// here on; an empty field when it has none.
ComposeState Take(std::string_view key) {
const auto kept = byKey.find(key);
if (kept == byKey.end()) return {};
ComposeState field = std::move(kept->second.field);
byKey.erase(kept);
return field;
}
Ui, main: the new-conversation screen and the long-press sheets The + opens a screen with a number field (its placeholder "Number", a parameter of the compose field now) and Start; the number becomes a conversation key through Number's ConversationKey, as an sms: link's does (E.164 through the country code, a short code as digits), anything else is refused in place. A long press on a conversation row offers to delete the conversation, on a message to copy its text to the clipboard or delete it; only those two have one: App tells the recogniser before each press whether what it lands on has a long press (GestureDetector's longPress), and without one a press held as long — on a button, a field, a sheet's row — stays a tap at its release, so a slow finger presses the button all the same. A sheet draws on the overlay layer over a scrim and pushes its regions last, so they win the hit test, and the wheel scrolls nothing under it; Escape, the back arrow and a tap outside dismiss it. Deleting a conversation also closes its notification and drops its draft; the + keeps the draft of the conversation it leaves, as Back does, and so does a view that closes because its last message was deleted. The deletes go through Sync (Erase, EraseConversation: the commit before, which keeps a deleted text deleted). The number field's box is drawn by its screen, as the send bar's is by the bar: the shared field drawing paints no background of its own. Opening a conversation, from a notification or a link, leaves the new-conversation screen and any sheet, and the + leaves any sheet. A key whose press changed the screen acts once: held, its repeats are not the new screen's — Enter, which started the conversation, would type line breaks into its field, and Escape would go on back, from a sheet through the conversation and its draft. A sheet that asks to delete a conversation goes when a text arrives for it: a yes would delete that text unread. A press on the conversation's row opens no such sheet either while the row it aimed at had not shown the text — the regions are a frame's: the press that is down when the text arrives, and one that comes down before the next frame is drawn, have no long press; a release before the long-press time is still the row's tap, while the row stays under the finger. --new and --bench-sheet put either on screen for the bench (--bench-sheet conversation or message, each on the screen a long press opens it over: another value is refused, and one that finds nothing to press says so in the log), and are window flags as --screenshot is. Tested: the screens and the sheets by the bench (--new, --bench-sheet) and the phone step's screenshots; the deletes' logic with the commit before, in tests/Store and tests/Sync; the press without a long press in tests/Gesture (the timer gives no long press and a move within the slop nothing; the release is the tap, however late; a slide off the control is a drag); a deleted conversation's draft dropped, in tests/Edit. The press on a row a text arrived for has no bench: none holds a finger on a row.
2026-11-01 18:11:40 +01:00
// The conversation was deleted: its draft goes with it.
void Drop(std::string_view key) {
if (const auto kept = byKey.find(key); kept != byKey.end()) byKey.erase(kept);
}
Ui: the compose field and the send bar A text message needs several lines and UTF-8, and the library's InputField is one line edited by byte, so the field is the app's own. Its state and editing are the core's (ImsdMessages:Edit, tested without a window): a plain struct, insertion at the cursor, Backspace and Delete by code point, Home and End within the line, a newline. Ui:Compose turns the keys into those edits and draws the field one to five lines tall — as many as half the area under the header and the banner holds, and one at the least — with the canvas's word wrapper (a longer text shows the lines that end at the caret's, or the first ones while the caret is among them), a placeholder when empty, the caret at the cursor, and a tap placing the cursor at the nearest byte by the widths the glyphs are drawn at, in the text as it is when the tap lands (an edit since the last frame only asked for one; a field no frame has laid out yet takes a tap as one at its text's end; a tap at or past the last line's end asks for the text's end, where a space the wrapper hung off the line may be). The bar under a conversation holds the field and Send, enabled only with text, a sendable status and an address to send to; Send hands the text to Sync with that address and clears the field (a store that refuses the text keeps the draft) (Model's SendAddress: as a link gave it, else the latest message's — the network's form of a received text, the dialled form of ours — never the key, whose completed country code is a guess that groups; a conversation with neither has Send off, and so has one whose address is not international — a national number, a short code; typed, linked or the message's — and was typed or written under another SIM's plan than the one known now, which the plan each row and the view carry tells (the view's is that of the SIM the address was typed under, which Number's AfterStatus keeps; Number's AnotherPlan, its second caller)); Sync's StateChanged moves the bubble's caption. Keys reach the field while a conversation is open (Escape goes back, Ctrl+Enter sends), a held key repeats through a timer since frames are on demand, and the caret blinks on one. A text typed and not sent is its conversation's, not the view's: leaving the conversation (Back, another one opened by a notification or a link) keeps it by the conversation's key for the run, and opening the conversation again takes it up (Edit's Drafts: an empty field keeps nothing and drops nothing; the draft of a typed or linked address follows imsd's status as the open conversation's key does — Number's AfterStatus over the address and the plan kept with it — so one left before the status brought the country code is found under the key the address makes afterwards; and a second text kept under one key — two keys that became one — goes after the first on a line of its own). Tested: tests/Model, the address a text goes to (the typed or linked one, the latest message's, none for an emptied conversation, none under another SIM's plan than it was typed or written under — a national number with or without a trunk prefix under another country's SIM, a short code under another operator's too, though dialled under the same operator, the own number read when it was typed or not; a national number typed before the own number was read, none under another operator — an international one under any — and a typed address judged by its own plan, whatever the latest row's); tests/Edit (code points of one to four bytes, the moves within a line, the edits that change nothing, the first line shown as the caret moves down a long text; the drafts: kept and taken up by key with the cursor, taken once, an empty field keeping and dropping nothing, one per conversation, a second text under one key on a line of its own; a typed address's following the status — moved when the code comes, not while texts are stored under its key, not under another SIM's status, a list conversation's left alone and the store not asked, the learned plan kept, two keys that became one keeping both texts).
2026-10-18 00:35:39 +02:00
// imsd's status: the key of a kept typed address follows it as an
// open conversation's does (Number's AfterStatus, with the same
// arguments; `nothingStored` says whether a key has no texts) — a
// draft kept before the status brought the country code is found
// under the key the same address makes afterwards.
void Status(const SimPlan& now, std::string_view code, const std::function<bool(std::string_view)>& nothingStored) {
std::vector<std::pair<std::string, std::string>> moves;
for (auto& [key, kept] : byKey) {
if (kept.dialled.empty()) continue;
TypedKey typed = AfterStatus(kept.dialled, { key, kept.plan }, now, code, nothingStored(key));
kept.plan = std::move(typed.plan);
if (typed.key != key) moves.emplace_back(key, std::move(typed.key));
}
for (const auto& [from, to] : moves) {
auto node = byKey.extract(from);
Keep(to, std::move(node.mapped().field), node.mapped().dialled, std::move(node.mapped().plan));
}
}
std::size_t Size() const noexcept { return byKey.size(); }
private:
struct Kept {
ComposeState field;
std::string dialled;
SimPlan plan;
};
std::map<std::string, Kept, std::less<>> byKey;
};
}