Commit a9c1e69a89
Unregistered key
Layout: unified · split
src/message/mod.rs +25 −11
| @@ -70,6 +70,8 @@ mod printer; | |||
| 70 | 70 | ||
| 71 | pub use self::compose::text_to_message; | 71 | pub use self::compose::text_to_message; |
| 72 | 72 | ||
| 73 | type ProtocolPreview<'a> = (&'a dyn Protocol, u16, u16); | ||
| 74 | |||
| 73 | pub type MessageKey = (MessageTimeStamp, OwnedEventId); | 75 | pub type MessageKey = (MessageTimeStamp, OwnedEventId); |
| 74 | 76 | ||
| 75 | #[derive(Default)] | 77 | #[derive(Default)] |
| @@ -715,11 +717,12 @@ impl<'a> MessageFormatter<'a> { | |||
| 715 | style: Style, | 717 | style: Style, |
| 716 | text: &mut Text<'a>, | 718 | text: &mut Text<'a>, |
| 717 | info: &'a RoomInfo, | 719 | info: &'a RoomInfo, |
| 718 | ) { | 720 | settings: &'a ApplicationSettings, |
| 721 | ) -> Option<ProtocolPreview<'a>> { | ||
| 719 | let width = self.width(); | 722 | let width = self.width(); |
| 720 | let w = width.saturating_sub(2); | 723 | let w = width.saturating_sub(2); |
| 721 | let shortcodes = self.settings.tunables.message_shortcode_display; | 724 | let shortcodes = self.settings.tunables.message_shortcode_display; |
| 722 | let (mut replied, _) = msg.show_msg(w, style, true, shortcodes); | 725 | let (mut replied, proto) = msg.show_msg(w, style, true, shortcodes); |
| 723 | let mut sender = msg.sender_span(info, self.settings); | 726 | let mut sender = msg.sender_span(info, self.settings); |
| 724 | let sender_width = UnicodeWidthStr::width(sender.content.as_ref()); | 727 | let sender_width = UnicodeWidthStr::width(sender.content.as_ref()); |
| 725 | let trailing = w.saturating_sub(sender_width + 1); | 728 | let trailing = w.saturating_sub(sender_width + 1); |
| @@ -738,12 +741,22 @@ impl<'a> MessageFormatter<'a> { | |||
| 738 | text, | 741 | text, |
| 739 | ); | 742 | ); |
| 740 | 743 | ||
| 744 | // Determine the image offset of the reply header, taking into account the formatting | ||
| 745 | let proto = proto.map(|p| { | ||
| 746 | let y_off = text.lines.len() as u16; | ||
| 747 | // Adjust x_off by 2 to account for the vertical line and indent | ||
| 748 | let x_off = self.cols.user_gutter_width(settings) + 2; | ||
| 749 | (p, x_off, y_off) | ||
| 750 | }); | ||
| 751 | |||
| 741 | for line in replied.lines.iter_mut() { | 752 | for line in replied.lines.iter_mut() { |
| 742 | line.spans.insert(0, Span::styled(THICK_VERTICAL, style)); | 753 | line.spans.insert(0, Span::styled(THICK_VERTICAL, style)); |
| 743 | line.spans.insert(0, Span::styled(" ", style)); | 754 | line.spans.insert(0, Span::styled(" ", style)); |
| 744 | } | 755 | } |
| 745 | 756 | ||
| 746 | self.push_text(replied, style, text); | 757 | self.push_text(replied, style, text); |
| 758 | |||
| 759 | proto | ||
| 747 | } | 760 | } |
| 748 | 761 | ||
| 749 | fn push_reactions(&mut self, counts: Vec<(&'a str, usize)>, style: Style, text: &mut Text<'a>) { | 762 | fn push_reactions(&mut self, counts: Vec<(&'a str, usize)>, style: Style, text: &mut Text<'a>) { |
| @@ -961,7 +974,7 @@ impl Message { | |||
| 961 | vwctx: &ViewportContext<MessageCursor>, | 974 | vwctx: &ViewportContext<MessageCursor>, |
| 962 | info: &'a RoomInfo, | 975 | info: &'a RoomInfo, |
| 963 | settings: &'a ApplicationSettings, | 976 | settings: &'a ApplicationSettings, |
| 964 | ) -> (Text<'a>, Option<(&'a dyn Protocol, u16, u16)>) { | 977 | ) -> (Text<'a>, [Option<ProtocolPreview<'a>>; 2]) { |
| 965 | let width = vwctx.get_width(); | 978 | let width = vwctx.get_width(); |
| 966 | 979 | ||
| 967 | let style = self.get_render_style(selected, settings); | 980 | let style = self.get_render_style(selected, settings); |
| @@ -974,10 +987,10 @@ impl Message { | |||
| 974 | .reply_to() | 987 | .reply_to() |
| 975 | .or_else(|| self.thread_root()) | 988 | .or_else(|| self.thread_root()) |
| 976 | .and_then(|e| info.get_event(&e)); | 989 | .and_then(|e| info.get_event(&e)); |
| 977 | 990 | let proto_reply = reply.as_ref().and_then(|r| { | |
| 978 | if let Some(r) = &reply { | 991 | // Format the reply header, push it into the `Text` buffer, and get any image. |
| 979 | fmt.push_in_reply(r, style, &mut text, info); | 992 | fmt.push_in_reply(r, style, &mut text, info, settings) |
| 980 | } | 993 | }); |
| 981 | 994 | ||
| 982 | // Now show the message contents, and the inlined reply if we couldn't find it above. | 995 | // Now show the message contents, and the inlined reply if we couldn't find it above. |
| 983 | let (msg, proto) = self.show_msg( | 996 | let (msg, proto) = self.show_msg( |
| @@ -988,10 +1001,11 @@ impl Message { | |||
| 988 | ); | 1001 | ); |
| 989 | 1002 | ||
| 990 | // Given our text so far, determine the image offset. | 1003 | // Given our text so far, determine the image offset. |
| 991 | let proto = proto.map(|p| { | 1004 | let proto_main = proto.map(|p| { |
| 992 | let y_off = text.lines.len() as u16; | 1005 | let y_off = text.lines.len() as u16; |
| 993 | let x_off = fmt.cols.user_gutter_width(settings); | 1006 | let x_off = fmt.cols.user_gutter_width(settings); |
| 994 | // Adjust y_off by 1 if a date was printed before the message to account for the extra line. | 1007 | // Adjust y_off by 1 if a date was printed before the message to account for |
| 1008 | // the extra line we're going to print. | ||
| 995 | let y_off = if fmt.date.is_some() { y_off + 1 } else { y_off }; | 1009 | let y_off = if fmt.date.is_some() { y_off + 1 } else { y_off }; |
| 996 | (p, x_off, y_off) | 1010 | (p, x_off, y_off) |
| 997 | }); | 1011 | }); |
| @@ -1012,7 +1026,7 @@ impl Message { | |||
| 1012 | fmt.push_thread_reply_count(thread.len(), &mut text); | 1026 | fmt.push_thread_reply_count(thread.len(), &mut text); |
| 1013 | } | 1027 | } |
| 1014 | 1028 | ||
| 1015 | (text, proto) | 1029 | (text, [proto_main, proto_reply]) |
| 1016 | } | 1030 | } |
| 1017 | 1031 | ||
| 1018 | pub fn show<'a>( | 1032 | pub fn show<'a>( |
| @@ -1053,7 +1067,7 @@ impl Message { | |||
| 1053 | }, | 1067 | }, |
| 1054 | ImageStatus::Loaded(backend) => { | 1068 | ImageStatus::Loaded(backend) => { |
| 1055 | proto = Some(backend.as_ref()); | 1069 | proto = Some(backend.as_ref()); |
| 1056 | placeholder_frame(None, width, &backend.rect().into()) | 1070 | placeholder_frame(Some("Loading..."), width, &backend.rect().into()) |
| 1057 | }, | 1071 | }, |
| 1058 | ImageStatus::Error(err) => Some(format!("[Image error: {err}]\n")), | 1072 | ImageStatus::Error(err) => Some(format!("[Image error: {err}]\n")), |
| 1059 | }; | 1073 | }; |
src/windows/room/scrollback.rs +9 −3
| @@ -1340,7 +1340,7 @@ impl<'a> StatefulWidget for Scrollback<'a> { | |||
| 1340 | 1340 | ||
| 1341 | for (key, item) in thread.range(&corner_key..) { | 1341 | for (key, item) in thread.range(&corner_key..) { |
| 1342 | let sel = key == cursor_key; | 1342 | let sel = key == cursor_key; |
| 1343 | let (txt, mut msg_preview) = | 1343 | let (txt, [mut msg_preview, mut reply_preview]) = |
| 1344 | item.show_with_preview(prev, foc && sel, &state.viewctx, info, settings); | 1344 | item.show_with_preview(prev, foc && sel, &state.viewctx, info, settings); |
| 1345 | 1345 | ||
| 1346 | let incomplete_ok = !full || !sel; | 1346 | let incomplete_ok = !full || !sel; |
| @@ -1357,11 +1357,17 @@ impl<'a> StatefulWidget for Scrollback<'a> { | |||
| 1357 | continue; | 1357 | continue; |
| 1358 | } | 1358 | } |
| 1359 | 1359 | ||
| 1360 | // Only take the preview into the matching row number. | ||
| 1361 | // `reply` and `msg` previews are on rows, | ||
| 1362 | // so an `or` works to pick the one that matches (if any) | ||
| 1360 | let line_preview = match msg_preview { | 1363 | let line_preview = match msg_preview { |
| 1361 | // Only take the preview into the matching row number. | ||
| 1362 | Some((_, _, y)) if y as usize == row => msg_preview.take(), | 1364 | Some((_, _, y)) if y as usize == row => msg_preview.take(), |
| 1363 | _ => None, | 1365 | _ => None, |
| 1364 | }; | 1366 | } |
| 1367 | .or(match reply_preview { | ||
| 1368 | Some((_, _, y)) if y as usize == row => reply_preview.take(), | ||
| 1369 | _ => None, | ||
| 1370 | }); | ||
| 1365 | 1371 | ||
| 1366 | lines.push((key, row, line, line_preview)); | 1372 | lines.push((key, row, line, line_preview)); |
| 1367 | sawit |= sel; | 1373 | sawit |= sel; |