From 0a9c89b6b357fc3d002c3eb451fd67e7a49ce7f5 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sat, 2 Sep 2023 21:47:14 +0300 Subject: [PATCH] mail/view/thread: add toggle_layout shortcut Toggles between horizontal and vertical layout. Previously it was decided on the terminal width. Signed-off-by: Manos Pitsidianakis --- meli/docs/meli.conf.5 | 11 +++++++---- meli/src/conf/shortcuts.rs | 3 ++- meli/src/mail/view/thread.rs | 25 ++++++++++++++++++++----- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/meli/docs/meli.conf.5 b/meli/docs/meli.conf.5 index e00d5876..725aac25 100644 --- a/meli/docs/meli.conf.5 +++ b/meli/docs/meli.conf.5 @@ -967,7 +967,7 @@ Scroll up list. Scroll down list. .Pq Em j \" default value .It Ic collapse_subtree -collapse thread branches +collapse thread branches. .Pq Em h \" default value .It Ic next_page Go to next page. @@ -976,14 +976,17 @@ Go to next page. Go to previous page. .Pq Em PageUp \" default value .It Ic reverse_thread_order -reverse thread order +reverse thread order. .Pq Em C-r \" default value .It Ic toggle_mailview -toggle mail view visibility +toggle mail view visibility. .Pq Em p \" default value .It Ic toggle_threadview -toggle thread view visibility +toggle thread view visibility. .Pq Em t \" default value +.It Ic toggle_layout +Toggle between horizontal and vertical layout. +.Pq Em Space \" default value .El .sp .Sh NOTIFICATIONS diff --git a/meli/src/conf/shortcuts.rs b/meli/src/conf/shortcuts.rs index 94e966d7..5c2b95c9 100644 --- a/meli/src/conf/shortcuts.rs +++ b/meli/src/conf/shortcuts.rs @@ -264,6 +264,7 @@ shortcut_key_values! { "thread-view", prev_page |> "Go to previous page." |> Key::PageUp, reverse_thread_order |> "reverse thread order" |> Key::Ctrl('r'), toggle_mailview |> "toggle mail view visibility" |> Key::Char('p'), - toggle_threadview |> "toggle thread view visibility" |> Key::Char('t') + toggle_threadview |> "toggle thread view visibility" |> Key::Char('t'), + toggle_layout |> "Toggle between horizontal and vertical layout." |> Key::Char(' ') } } diff --git a/meli/src/mail/view/thread.rs b/meli/src/mail/view/thread.rs index 3227759b..48495ea4 100644 --- a/meli/src/mail/view/thread.rs +++ b/meli/src/mail/view/thread.rs @@ -62,7 +62,7 @@ pub struct ThreadView { visible_entries: Vec>, indentation_colors: [ThemeAttribute; 6], use_color: bool, - + horizontal: Option, movement: Option, dirty: bool, content: CellBuffer, @@ -104,6 +104,7 @@ impl ThreadView { crate::conf::value(context, "mail.view.thread.indentation.f"), ], use_color: context.settings.terminal.use_color(), + horizontal: None, ..Default::default() }; view.initiate(expanded_hash, go_to_first_unread, context); @@ -794,7 +795,7 @@ impl ThreadView { (set_y(upper_left, y), set_x(bottom_right, mid - 1)), context, ); - let upper_left = (mid + 1, get_y(upper_left) + y - 1); + let upper_left = (mid + 1, get_y(upper_left)); self.entries[self.new_expanded_pos].mailview.draw( grid, (upper_left, bottom_right), @@ -1058,10 +1059,13 @@ impl Component for ThreadView { self.entries[self.new_expanded_pos] .mailview .draw(grid, area, context); - } else if total_cols >= self.content.size().0 + 74 { - self.draw_vert(grid, area, context); - } else { + } else if self + .horizontal + .unwrap_or(total_cols >= self.content.size().0 + 74) + { self.draw_horz(grid, area, context); + } else { + self.draw_vert(grid, area, context); } self.dirty = false; } @@ -1096,6 +1100,17 @@ impl Component for ThreadView { let shortcuts = self.shortcuts(context); match *event { + UIEvent::Input(ref key) + if shortcut!(key == shortcuts[Shortcuts::THREAD_VIEW]["toggle_layout"]) => + { + if let Some(ref mut v) = self.horizontal { + *v = !*v; + } else { + self.horizontal = Some(false); + } + self.set_dirty(true); + true + } UIEvent::Input(ref key) if shortcut!(key == shortcuts[Shortcuts::THREAD_VIEW]["scroll_up"]) => {