Compare commits

..

1 Commits

Author SHA1 Message Date
13fa1bf108 fix(ui): reserve pad height per message to prevent multi-line clip and scroll desync
All checks were successful
CI Code / Check spelling (pull_request) Successful in 15s
CI Code / Check coding style (pull_request) Successful in 29s
CI Code / Code Coverage (pull_request) Successful in 3m39s
CI Code / Linux (debian) (pull_request) Successful in 4m39s
CI Code / Linux (ubuntu) (pull_request) Successful in 4m48s
CI Code / Linux (arch) (pull_request) Successful in 6m58s
A tall multi-line message printed near the bottom of the ncurses pad was clipped because _win_print_internal grew the pad from the current cursor only (_win_ensure_pad_capacity(getcury)), not the height of the message about to be printed. The clipped message's captured height (e.g. 1 row for a 49-row message) was wrong while win_redraw later rendered it in full; the resulting buffer->lines / y_start_pos mismatch desynced the page-up scroll anchor, producing a ~one-page jump when scrolling past such messages from history.

Estimate the rendered height (hard newlines + soft-wrap over the usable width) and reserve that many rows before printing, so the message is never clipped and its captured height matches the redraw. All print paths go through _win_print_internal, so incoming/outgoing/history are covered.

Regression from the upstream sync (72f4f186d), which replaced the fixed-size pad with the dynamic _win_ensure_pad_capacity model.
2026-06-20 12:24:55 +03:00
4 changed files with 30 additions and 50 deletions

View File

@@ -67,6 +67,20 @@ _win_ensure_pad_capacity(ProfWin* window, WINDOW* win, int lines_needed)
}
}
}
// upper-bound estimate of rows a message body occupies (hard newlines + soft-wrap), to reserve pad space before printing so a tall message isn't clipped (a clipped height desyncs the scroll offset)
static int
_win_estimated_lines(WINDOW* win, const char* const message, int indent, int pad_indent)
{
int usable = MAX(1, getmaxx(win) - (indent + pad_indent));
int newlines = 0;
for (const char* p = message; *p; p++) {
if (*p == '\n') {
newlines++;
}
}
return newlines + utf8_display_len(message) / usable + 2;
}
static const char* LOADING_MESSAGE = "Loading older messages…";
static const char* CONS_WIN_TITLE = "CProof. Type /help for help information.";
static const char* XML_WIN_TITLE = "XML Console";
@@ -2001,7 +2015,7 @@ _win_print_internal(ProfWin* window, const char* show_char, int pad_indent, GDat
}
}
_win_ensure_pad_capacity(window, window->layout->win, getcury(window->layout->win));
_win_ensure_pad_capacity(window, window->layout->win, getcury(window->layout->win) + _win_estimated_lines(window->layout->win, message + offset, indent, pad_indent));
if (prefs_get_boolean(PREF_WRAP)) {
_win_print_wrapped(window->layout->win, message + offset, indent, pad_indent);

View File

@@ -1132,17 +1132,12 @@ _handle_groupchat(xmpp_stanza_t* const stanza)
message->timestamp = NULL;
}
// XEP-0203 §4: trust <delay> only from the room or our server, not a client-forged stamp
message->timestamp = stanza_get_oldest_delay_from(stanza, from_jid->barejid);
if (!message->timestamp && from_jid->domainpart) {
message->timestamp = stanza_get_oldest_delay_from(stanza, from_jid->domainpart);
}
if (!message->timestamp) {
const char* my_domain = connection_get_domain();
if (my_domain) {
message->timestamp = stanza_get_oldest_delay_from(stanza, my_domain);
}
}
// we want to display the oldest delay
message->timestamp = stanza_get_oldest_delay(stanza);
// now this has nothing to do with MUC history
// it's just setting the time to the received time so upon displaying we can use this time
// for example in win_println_incoming_muc_msg()
if (!message->timestamp) {
message->timestamp = g_date_time_new_now_local();
}
@@ -1273,15 +1268,7 @@ _handle_muc_private_message(xmpp_stanza_t* const stanza)
_receive_omemo(stanza, message);
#endif
// XEP-0203 §4: trust <delay> only from a server domain, not a client-forged stamp
const char* my_domain = connection_get_domain();
message->timestamp = stanza_get_delay_from(stanza, my_domain);
if (!message->timestamp && message->from_jid->domainpart) {
message->timestamp = stanza_get_delay_from(stanza, message->from_jid->domainpart);
}
if (!message->timestamp) {
message->timestamp = g_date_time_new_now_local();
}
message->timestamp = stanza_get_delay(stanza);
message->body = xmpp_message_get_body(stanza);
if (!message->plain && !message->body) {
@@ -1432,12 +1419,8 @@ _handle_chat(xmpp_stanza_t* const stanza, gboolean is_mam, gboolean is_carbon, c
// timestamp provided outside like in a <forwarded> by MAM
message->timestamp = timestamp;
} else {
// XEP-0203 §4: trust <delay> only from a server domain, not a client-forged stamp
const char* my_domain = connection_get_domain();
message->timestamp = stanza_get_delay_from(stanza, my_domain);
if (!message->timestamp && jid->domainpart) {
message->timestamp = stanza_get_delay_from(stanza, jid->domainpart);
}
// timestamp in the message stanza or use time of receival (now)
message->timestamp = stanza_get_delay(stanza);
if (!message->timestamp) {
message->timestamp = g_date_time_new_now_local();
}

View File

@@ -1163,7 +1163,7 @@ _stanza_get_delay_timestamp_xep0091(xmpp_stanza_t* const x_stanza)
}
GDateTime*
stanza_get_delay_from(xmpp_stanza_t* const stanza, const char* const from)
stanza_get_delay_from(xmpp_stanza_t* const stanza, gchar* from)
{
xmpp_stanza_t* delay = NULL;
@@ -1195,12 +1195,6 @@ stanza_get_delay_from(xmpp_stanza_t* const stanza, const char* const from)
GDateTime*
stanza_get_oldest_delay(xmpp_stanza_t* const stanza)
{
return stanza_get_oldest_delay_from(stanza, NULL);
}
GDateTime*
stanza_get_oldest_delay_from(xmpp_stanza_t* const stanza, const char* const from)
{
xmpp_stanza_t* child;
const char* child_name;
@@ -1211,37 +1205,27 @@ stanza_get_oldest_delay_from(xmpp_stanza_t* const stanza, const char* const from
child_name = xmpp_stanza_get_name(child);
if (child_name && g_strcmp0(child_name, STANZA_NAME_DELAY) == 0) {
if (from) {
const char* child_from = xmpp_stanza_get_attribute(child, STANZA_ATTR_FROM);
if (!child_from || g_strcmp0(child_from, from) != 0)
continue;
}
GDateTime* tmp = _stanza_get_delay_timestamp_xep0203(child);
if (oldest == NULL) {
oldest = tmp;
} else if (tmp && g_date_time_compare(oldest, tmp) == 1) {
} else if (g_date_time_compare(oldest, tmp) == 1) {
g_date_time_unref(oldest);
oldest = tmp;
} else if (tmp) {
} else {
g_date_time_unref(tmp);
}
}
if (child_name && g_strcmp0(child_name, STANZA_NAME_X) == 0) {
if (from) {
const char* child_from = xmpp_stanza_get_attribute(child, STANZA_ATTR_FROM);
if (!child_from || g_strcmp0(child_from, from) != 0)
continue;
}
GDateTime* tmp = _stanza_get_delay_timestamp_xep0091(child);
if (oldest == NULL) {
oldest = tmp;
} else if (tmp && g_date_time_compare(oldest, tmp) == 1) {
} else if (g_date_time_compare(oldest, tmp) == 1) {
g_date_time_unref(oldest);
oldest = tmp;
} else if (tmp) {
} else {
g_date_time_unref(tmp);
}
}

View File

@@ -305,9 +305,8 @@ xmpp_stanza_t* stanza_create_mediated_invite(xmpp_ctx_t* ctx, const char* const
gboolean stanza_contains_chat_state(xmpp_stanza_t* stanza);
GDateTime* stanza_get_delay(xmpp_stanza_t* const stanza);
GDateTime* stanza_get_delay_from(xmpp_stanza_t* const stanza, const char* const from);
GDateTime* stanza_get_delay_from(xmpp_stanza_t* const stanza, gchar* from);
GDateTime* stanza_get_oldest_delay(xmpp_stanza_t* const stanza);
GDateTime* stanza_get_oldest_delay_from(xmpp_stanza_t* const stanza, const char* const from);
gboolean stanza_is_muc_presence(xmpp_stanza_t* const stanza);
gboolean stanza_is_muc_self_presence(xmpp_stanza_t* const stanza,