diff --git a/zulipterminal/core.py b/zulipterminal/core.py index 3eb27a3416..8215f52041 100644 --- a/zulipterminal/core.py +++ b/zulipterminal/core.py @@ -490,9 +490,27 @@ def report_warning( """ self.view.set_footer_text(text, "task:warning", duration) - def show_spoiler(self, content: str) -> None: + def show_spoiler( + self, + content: str, + message: Message, + topic_links: Dict[str, Tuple[str, int, bool]], + message_links: Dict[str, Tuple[str, int, bool]], + time_mentions: List[Tuple[str, str]], + spoilers: List[Tuple[int, List[Any], List[Any]]], + ) -> None: self.show_pop_up( - SpoilerView(self, "Spoiler (up/down scrolls)", content), "area:msg" + SpoilerView( + self, + "Spoiler (up/down scrolls)", + content, + message, + topic_links, + message_links, + time_mentions, + spoilers, + ), + "area:msg", ) def show_media_confirmation_popup( diff --git a/zulipterminal/ui_tools/buttons.py b/zulipterminal/ui_tools/buttons.py index 749f01b8d7..4c7682db61 100644 --- a/zulipterminal/ui_tools/buttons.py +++ b/zulipterminal/ui_tools/buttons.py @@ -324,10 +324,20 @@ def __init__( header_len: int, header: List[Any], content: List[Any], + message: Message, + topic_links: Dict[str, Tuple[str, int, bool]], + message_links: Dict[str, Tuple[str, int, bool]], + time_mentions: List[Tuple[str, str]], + spoilers: List[Tuple[int, List[Any], List[Any]]], display_attr: Optional[str], ) -> None: self.controller = controller self.content = content + self.message = message + self.topic_links = topic_links + self.message_links = message_links + self.time_mentions = time_mentions + self.spoilers = spoilers super().__init__("") self.update_widget(header_len, header, display_attr) @@ -344,7 +354,14 @@ def update_widget( self._w = urwid.AttrMap(icon, display_attr, focus_map="selected") def show_spoiler(self, *_: Any) -> None: - self.controller.show_spoiler(self.content) + self.controller.show_spoiler( + self.content, + self.message, + self.topic_links, + self.message_links, + self.time_mentions, + self.spoilers, + ) class TopicButton(TopButton): diff --git a/zulipterminal/ui_tools/views.py b/zulipterminal/ui_tools/views.py index 69c2d05845..c5e6cf7c1f 100644 --- a/zulipterminal/ui_tools/views.py +++ b/zulipterminal/ui_tools/views.py @@ -1078,12 +1078,39 @@ def __init__( class SpoilerView(PopUpView): - def __init__(self, controller: Any, title: str, content: str) -> None: + def __init__( + self, + controller: Any, + title: str, + content: str, + message: Message, + topic_links: Dict[str, Tuple[str, int, bool]], + message_links: Dict[str, Tuple[str, int, bool]], + time_mentions: List[Tuple[str, str]], + spoilers: List[Tuple[int, List[Any], List[Any]]], + ) -> None: + self.message = message + self.topic_links = topic_links + self.message_links = message_links + self.time_mentions = time_mentions + self.spoilers = spoilers width, _ = controller.maximum_popup_dimensions() widget = [urwid.Text(content)] super().__init__(controller, widget, "ENTER", width, title) + def keypress(self, size: urwid_Size, key: str) -> str: + if is_command_key("GO_BACK", key): + self.controller.show_msg_info( + msg=self.message, + topic_links=self.topic_links, + message_links=self.message_links, + time_mentions=self.time_mentions, + spoilers=self.spoilers, + ) + return key + return super().keypress(size, key) + class AboutView(PopUpView): def __init__( @@ -1687,14 +1714,9 @@ def __init__( popup_width = max(popup_width, topic_link_width) if spoilers: - spoiler_buttons = [] - spoiler_width = 0 - for index, (header_len, header, content) in enumerate(spoilers): - spoiler_width = max(header_len, spoiler_width) - display_attr = None if index % 2 else "popup_contrast" - spoiler_buttons.append( - SpoilerButton(controller, header_len, header, content, display_attr) - ) + spoiler_buttons, spoiler_width = self.create_spoiler_buttons( + controller, spoilers + ) # slice_index = Number of labels before message links + 1 newline # + 1 'Spoilers' category label. @@ -1735,6 +1757,39 @@ def create_link_buttons( return link_widgets, link_width + def create_spoiler_buttons( + self, controller: Any, spoilers: List[Tuple[int, List[Any], List[Any]]] + ) -> Tuple[List[SpoilerButton], int]: + spoiler_buttons = [] + spoiler_width = 0 + + for index, (header_len, header, content) in enumerate(spoilers): + spoiler_width = max(header_len, spoiler_width) + + display_attr = None if index % 2 else "popup_contrast" + + processed_header = [f"{index+1}: "] + header + header_len = sum( + len(part[1]) if isinstance(part, tuple) else len(part) + for part in processed_header + ) + + spoiler_buttons.append( + SpoilerButton( + controller, + header_len, + processed_header, + header+["\n\n"]+content, + self.msg, + self.topic_links, + self.message_links, + self.time_mentions, + self.spoilers, + display_attr, + ) + ) + return spoiler_buttons, spoiler_width + def keypress(self, size: urwid_Size, key: str) -> str: if is_command_key("EDIT_HISTORY", key) and self.show_edit_history_label: self.controller.show_edit_history(