Browse Source

ui: add multiplier shortcuts to cursor movements

Prepend a cursor movement (Up/Down/PageUp/PageDown) with a multiplier
(e.g 23+Down, that is '2' then '3' then 'Down') to increase the
movement's length.
tags/pre-alpha-0.4.0
Manos Pitsidianakis 3 months ago
parent
commit
94152f7336
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS. GPG Key ID: 73627C2F690DF710
9 changed files with 345 additions and 153 deletions
  1. +101
    -12
      ui/src/components/contacts/contact_list.rs
  2. +126
    -10
      ui/src/components/mail/listing.rs
  3. +19
    -25
      ui/src/components/mail/listing/compact.rs
  4. +18
    -25
      ui/src/components/mail/listing/conversations.rs
  5. +18
    -20
      ui/src/components/mail/listing/plain.rs
  6. +18
    -41
      ui/src/components/mail/listing/thread.rs
  7. +20
    -7
      ui/src/components/mail/view/thread.rs
  8. +22
    -9
      ui/src/components/utilities.rs
  9. +3
    -4
      ui/src/conf/accounts.rs

+ 101
- 12
ui/src/components/contacts/contact_list.rs View File

@@ -35,6 +35,7 @@ pub struct ContactList {
show_divider: bool,
menu_visibility: bool,
movement: Option<PageMovement>,
cmd_buf: String,
view: Option<ContactManager>,
ratio: usize, // right/(container width) * 100
id: ComponentId,
@@ -70,6 +71,7 @@ impl ContactList {
initialized: false,
dirty: true,
movement: None,
cmd_buf: String::with_capacity(8),
view: None,
ratio: 90,
show_divider: false,
@@ -343,18 +345,29 @@ impl ContactList {

if let Some(mvm) = self.movement.take() {
match mvm {
PageMovement::PageUp => {
self.new_cursor_pos = self.new_cursor_pos.saturating_sub(rows);
PageMovement::Up(amount) => {
self.new_cursor_pos = self.new_cursor_pos.saturating_sub(amount);
}
PageMovement::PageDown => {
if self.new_cursor_pos + rows + 1 < self.length {
self.new_cursor_pos += rows;
} else if self.new_cursor_pos + rows > self.length {
PageMovement::PageUp(multiplier) => {
self.new_cursor_pos = self.new_cursor_pos.saturating_sub(rows * multiplier);
}
PageMovement::Down(amount) => {
if self.new_cursor_pos + amount + 1 < self.length {
self.new_cursor_pos += amount;
} else {
self.new_cursor_pos = self.length - 1;
}
}
PageMovement::PageDown(multiplier) => {
if self.new_cursor_pos + rows * multiplier + 1 < self.length {
self.new_cursor_pos += rows * multiplier;
} else if self.new_cursor_pos + rows * multiplier > self.length {
self.new_cursor_pos = self.length - 1;
} else {
self.new_cursor_pos = (self.length / rows) * rows;
}
}
PageMovement::Right(_) | PageMovement::Left(_) => {}
PageMovement::Home => {
self.new_cursor_pos = 0;
}
@@ -568,11 +581,26 @@ impl Component for ContactList {
return true;
}
UIEvent::Input(ref key) if *key == shortcuts["next_account"] && self.view.is_none() => {
let amount = if self.cmd_buf.is_empty() {
1
} else if let Ok(amount) = self.cmd_buf.parse::<usize>() {
self.cmd_buf.clear();
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
amount
} else {
self.cmd_buf.clear();
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
return true;
};
if self.accounts.is_empty() {
return true;
}
if self.account_pos < self.accounts.len() - 1 {
self.account_pos += 1;
if self.account_pos + amount < self.accounts.len() {
self.account_pos += amount;
self.set_dirty();
self.initialized = false;
context
@@ -585,11 +613,26 @@ impl Component for ContactList {
return true;
}
UIEvent::Input(ref key) if *key == shortcuts["prev_account"] && self.view.is_none() => {
let amount = if self.cmd_buf.is_empty() {
1
} else if let Ok(amount) = self.cmd_buf.parse::<usize>() {
self.cmd_buf.clear();
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
amount
} else {
self.cmd_buf.clear();
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
return true;
};
if self.accounts.is_empty() {
return true;
}
if self.account_pos > 0 {
self.account_pos -= 1;
if self.account_pos >= amount {
self.account_pos -= amount;
self.set_dirty();
self.initialized = false;
context
@@ -606,16 +649,62 @@ impl Component for ContactList {
self.menu_visibility = !self.menu_visibility;
self.set_dirty();
}
UIEvent::Input(Key::Esc) | UIEvent::Input(Key::Alt('')) => {
self.cmd_buf.clear();
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
return true;
}
UIEvent::Input(Key::Char(c)) if c >= '0' && c <= '9' => {
self.cmd_buf.push(c);
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufSet(
self.cmd_buf.clone(),
)));
return true;
}
UIEvent::Input(Key::Up) if self.view.is_none() => {
let amount = if self.cmd_buf.is_empty() {
1
} else if let Ok(amount) = self.cmd_buf.parse::<usize>() {
self.cmd_buf.clear();
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
amount
} else {
self.cmd_buf.clear();
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
return true;
};
self.movement = Some(PageMovement::Up(amount));
self.set_dirty();
self.new_cursor_pos = self.cursor_pos.saturating_sub(1);
return true;
}
UIEvent::Input(Key::Down)
if self.cursor_pos < self.length.saturating_sub(1) && self.view.is_none() =>
{
let amount = if self.cmd_buf.is_empty() {
1
} else if let Ok(amount) = self.cmd_buf.parse::<usize>() {
self.cmd_buf.clear();
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
amount
} else {
self.cmd_buf.clear();
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
return true;
};
self.set_dirty();
self.new_cursor_pos += 1;
self.movement = Some(PageMovement::Down(amount));
return true;
}
UIEvent::ComponentKill(ref kill_id) if self.mode == ViewMode::View(*kill_id) => {


+ 126
- 10
ui/src/components/mail/listing.rs View File

@@ -167,6 +167,7 @@ pub struct Listing {

show_divider: bool,
menu_visibility: bool,
cmd_buf: String,
/// This is the width of the right container to the entire width.
ratio: usize, // right/(container width) * 100
}
@@ -293,11 +294,26 @@ impl Component for Listing {
UIEvent::Input(ref k)
if k == shortcuts["next_folder"] || k == shortcuts["prev_folder"] =>
{
let amount = if self.cmd_buf.is_empty() {
1
} else if let Ok(amount) = self.cmd_buf.parse::<usize>() {
self.cmd_buf.clear();
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
amount
} else {
self.cmd_buf.clear();
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
return true;
};
let folder_length = context.accounts[self.cursor_pos.0].len();
match k {
k if k == shortcuts["next_folder"] && folder_length > 0 => {
if self.cursor_pos.1 < folder_length - 1 {
self.cursor_pos.1 += 1;
if self.cursor_pos.1 + amount < folder_length {
self.cursor_pos.1 += amount;
self.component.set_coordinates((
self.cursor_pos.0,
self.cursor_pos.1,
@@ -309,8 +325,8 @@ impl Component for Listing {
}
}
k if k == shortcuts["prev_folder"] => {
if self.cursor_pos.1 > 0 {
self.cursor_pos.1 -= 1;
if self.cursor_pos.1 >= amount {
self.cursor_pos.1 -= amount;
self.component.set_coordinates((
self.cursor_pos.0,
self.cursor_pos.1,
@@ -349,10 +365,25 @@ impl Component for Listing {
UIEvent::Input(ref k)
if k == shortcuts["next_account"] || k == shortcuts["prev_account"] =>
{
let amount = if self.cmd_buf.is_empty() {
1
} else if let Ok(amount) = self.cmd_buf.parse::<usize>() {
self.cmd_buf.clear();
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
amount
} else {
self.cmd_buf.clear();
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
return true;
};
match k {
k if k == shortcuts["next_account"] => {
if self.cursor_pos.0 < self.accounts.len() - 1 {
self.cursor_pos = (self.cursor_pos.0 + 1, 0);
if self.cursor_pos.0 + amount < self.accounts.len() {
self.cursor_pos = (self.cursor_pos.0 + amount, 0);
self.component.set_coordinates((self.cursor_pos.0, 0, None));
self.set_dirty();
} else {
@@ -360,8 +391,8 @@ impl Component for Listing {
}
}
k if k == shortcuts["prev_account"] => {
if self.cursor_pos.0 > 0 {
self.cursor_pos = (self.cursor_pos.0 - 1, 0);
if self.cursor_pos.0 >= amount {
self.cursor_pos = (self.cursor_pos.0 - amount, 0);
self.component.set_coordinates((self.cursor_pos.0, 0, None));
self.set_dirty();
} else {
@@ -439,12 +470,80 @@ impl Component for Listing {
UIEvent::Resize => {
self.dirty = true;
}
UIEvent::Input(Key::Up) => {
let amount = if self.cmd_buf.is_empty() {
1
} else if let Ok(amount) = self.cmd_buf.parse::<usize>() {
self.cmd_buf.clear();
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
amount
} else {
self.cmd_buf.clear();
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
return true;
};
self.component.set_movement(PageMovement::Up(amount));
return true;
}
UIEvent::Input(Key::Down) => {
let amount = if self.cmd_buf.is_empty() {
1
} else if let Ok(amount) = self.cmd_buf.parse::<usize>() {
self.cmd_buf.clear();
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
amount
} else {
self.cmd_buf.clear();
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
return true;
};
self.component.set_movement(PageMovement::Down(amount));
return true;
}
UIEvent::Input(ref key) if *key == shortcuts["prev_page"] => {
self.component.set_movement(PageMovement::PageUp);
let mult = if self.cmd_buf.is_empty() {
1
} else if let Ok(mult) = self.cmd_buf.parse::<usize>() {
self.cmd_buf.clear();
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
mult
} else {
self.cmd_buf.clear();
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
return true;
};
self.component.set_movement(PageMovement::PageUp(mult));
return true;
}
UIEvent::Input(ref key) if *key == shortcuts["next_page"] => {
self.component.set_movement(PageMovement::PageDown);
let mult = if self.cmd_buf.is_empty() {
1
} else if let Ok(mult) = self.cmd_buf.parse::<usize>() {
self.cmd_buf.clear();
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
mult
} else {
self.cmd_buf.clear();
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
return true;
};
self.component.set_movement(PageMovement::PageDown(mult));
return true;
}
UIEvent::Input(ref key) if *key == Key::Home => {
@@ -501,6 +600,22 @@ impl Component for Listing {
self.get_status(context).unwrap(),
)));
}
UIEvent::Input(Key::Esc) | UIEvent::Input(Key::Alt('')) => {
self.cmd_buf.clear();
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
return true;
}
UIEvent::Input(Key::Char(c)) if c >= '0' && c <= '9' => {
self.cmd_buf.push(c);
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufSet(
self.cmd_buf.clone(),
)));
return true;
}
_ => {}
}
false
@@ -642,6 +757,7 @@ impl Listing {
show_divider: false,
menu_visibility: true,
ratio: 90,
cmd_buf: String::with_capacity(4),
}
}



+ 19
- 25
ui/src/components/mail/listing/compact.rs View File

@@ -168,27 +168,34 @@ impl ListingTrait for CompactListing {

if let Some(mvm) = self.movement.take() {
match mvm {
PageMovement::PageUp => {
self.new_cursor_pos.2 = self.new_cursor_pos.2.saturating_sub(rows);
PageMovement::Up(amount) => {
self.new_cursor_pos.2 = self.new_cursor_pos.2.saturating_sub(amount);
}
PageMovement::PageDown => {
if self.new_cursor_pos.2 + rows + 1 < self.length {
self.new_cursor_pos.2 += rows;
} else if self.new_cursor_pos.2 + rows > self.length {
PageMovement::PageUp(multiplier) => {
self.new_cursor_pos.2 = self.new_cursor_pos.2.saturating_sub(rows * multiplier);
}
PageMovement::Down(amount) => {
if self.new_cursor_pos.2 + amount + 1 < self.length {
self.new_cursor_pos.2 += amount;
} else {
self.new_cursor_pos.2 = self.length - 1;
}
}
PageMovement::PageDown(multiplier) => {
if self.new_cursor_pos.2 + rows * multiplier + 1 < self.length {
self.new_cursor_pos.2 += rows * multiplier;
} else if self.new_cursor_pos.2 + rows * multiplier > self.length {
self.new_cursor_pos.2 = self.length - 1;
} else {
self.new_cursor_pos.2 = (self.length / rows) * rows;
}
}
PageMovement::Right(_) | PageMovement::Left(_) => {}
PageMovement::Home => {
self.new_cursor_pos.2 = 0;
}
PageMovement::End => {
if self.new_cursor_pos.2 + rows > self.length {
self.new_cursor_pos.2 = self.length - 1;
} else {
self.new_cursor_pos.2 = (self.length / rows) * rows;
}
self.new_cursor_pos.2 = self.length - 1;
}
}
}
@@ -942,20 +949,6 @@ impl Component for CompactListing {
let shortcuts = &self.get_shortcuts(context)[CompactListing::DESCRIPTION];
if self.length > 0 {
match *event {
UIEvent::Input(Key::Up) => {
if self.cursor_pos.2 > 0 {
self.new_cursor_pos.2 = self.new_cursor_pos.2.saturating_sub(1);
self.dirty = true;
}
return true;
}
UIEvent::Input(Key::Down) => {
if self.new_cursor_pos.2 < self.length - 1 {
self.new_cursor_pos.2 += 1;
self.dirty = true;
}
return true;
}
UIEvent::Input(ref k) if !self.unfocused && *k == shortcuts["open_thread"] => {
if self.filtered_selection.is_empty() {
self.view = ThreadView::new(self.cursor_pos, None, context);
@@ -1146,6 +1139,7 @@ impl Component for CompactListing {
UIEvent::Input(Key::Esc) if !self.unfocused && !self.filter_term.is_empty() => {
self.set_coordinates((self.new_cursor_pos.0, self.new_cursor_pos.1, None));
self.refresh_mailbox(context);
self.set_dirty();
return true;
}
UIEvent::Action(ref action) => match action {


+ 18
- 25
ui/src/components/mail/listing/conversations.rs View File

@@ -209,27 +209,34 @@ impl ListingTrait for ConversationsListing {

if let Some(mvm) = self.movement.take() {
match mvm {
PageMovement::PageUp => {
self.new_cursor_pos.2 = self.new_cursor_pos.2.saturating_sub(rows);
PageMovement::Up(amount) => {
self.new_cursor_pos.2 = self.new_cursor_pos.2.saturating_sub(amount);
}
PageMovement::PageDown => {
if self.new_cursor_pos.2 + rows + 1 < self.length {
self.new_cursor_pos.2 += rows;
} else if self.new_cursor_pos.2 + rows > self.length {
PageMovement::PageUp(multiplier) => {
self.new_cursor_pos.2 = self.new_cursor_pos.2.saturating_sub(rows * multiplier);
}
PageMovement::Down(amount) => {
if self.new_cursor_pos.2 + amount + 1 < self.length {
self.new_cursor_pos.2 += amount;
} else {
self.new_cursor_pos.2 = self.length - 1;
}
}
PageMovement::PageDown(multiplier) => {
if self.new_cursor_pos.2 + rows * multiplier + 1 < self.length {
self.new_cursor_pos.2 += rows * multiplier;
} else if self.new_cursor_pos.2 + rows * multiplier > self.length {
self.new_cursor_pos.2 = self.length - 1;
} else {
self.new_cursor_pos.2 = (self.length / rows) * rows;
}
}
PageMovement::Right(_) | PageMovement::Left(_) => {}
PageMovement::Home => {
self.new_cursor_pos.2 = 0;
}
PageMovement::End => {
if self.new_cursor_pos.2 + rows > self.length {
self.new_cursor_pos.2 = self.length - 1;
} else {
self.new_cursor_pos.2 = (self.length / rows) * rows;
}
self.new_cursor_pos.2 = self.length - 1;
}
}
}
@@ -1008,20 +1015,6 @@ impl Component for ConversationsListing {
let shortcuts = &self.get_shortcuts(context)[ConversationsListing::DESCRIPTION];
if self.length > 0 {
match *event {
UIEvent::Input(Key::Up) => {
if self.cursor_pos.2 > 0 {
self.new_cursor_pos.2 = self.new_cursor_pos.2.saturating_sub(1);
self.dirty = true;
}
return true;
}
UIEvent::Input(Key::Down) => {
if self.length > 0 && self.new_cursor_pos.2 < self.length - 1 {
self.new_cursor_pos.2 += 1;
self.dirty = true;
}
return true;
}
UIEvent::Input(ref k) if !self.unfocused && *k == shortcuts["open_thread"] => {
if self.length == 0 {
return true;


+ 18
- 20
ui/src/components/mail/listing/plain.rs View File

@@ -167,18 +167,29 @@ impl ListingTrait for PlainListing {

if let Some(mvm) = self.movement.take() {
match mvm {
PageMovement::PageUp => {
self.new_cursor_pos.2 = self.new_cursor_pos.2.saturating_sub(rows);
PageMovement::Up(amount) => {
self.new_cursor_pos.2 = self.new_cursor_pos.2.saturating_sub(amount);
}
PageMovement::PageDown => {
if self.new_cursor_pos.2 + rows + 1 < self.length {
self.new_cursor_pos.2 += rows;
} else if self.new_cursor_pos.2 + rows > self.length {
PageMovement::PageUp(multiplier) => {
self.new_cursor_pos.2 = self.new_cursor_pos.2.saturating_sub(rows * multiplier);
}
PageMovement::Down(amount) => {
if self.new_cursor_pos.2 + amount + 1 < self.length {
self.new_cursor_pos.2 += amount;
} else {
self.new_cursor_pos.2 = self.length - 1;
}
}
PageMovement::PageDown(multiplier) => {
if self.new_cursor_pos.2 + rows * multiplier + 1 < self.length {
self.new_cursor_pos.2 += rows * multiplier;
} else if self.new_cursor_pos.2 + rows * multiplier > self.length {
self.new_cursor_pos.2 = self.length - 1;
} else {
self.new_cursor_pos.2 = (self.length / rows) * rows;
}
}
PageMovement::Right(_) | PageMovement::Left(_) => {}
PageMovement::Home => {
self.new_cursor_pos.2 = 0;
}
@@ -885,20 +896,6 @@ impl Component for PlainListing {
let shortcuts = &self.get_shortcuts(context)[PlainListing::DESCRIPTION];
if self.length > 0 {
match *event {
UIEvent::Input(Key::Up) => {
if self.cursor_pos.2 > 0 {
self.new_cursor_pos.2 = self.new_cursor_pos.2.saturating_sub(1);
self.dirty = true;
}
return true;
}
UIEvent::Input(Key::Down) => {
if self.new_cursor_pos.2 < self.length - 1 {
self.new_cursor_pos.2 += 1;
self.dirty = true;
}
return true;
}
UIEvent::Input(ref k) if !self.unfocused && *k == shortcuts["open_thread"] => {
let env_hash = self.get_env_under_cursor(self.cursor_pos.2, context);
let temp = (self.cursor_pos.0, self.cursor_pos.1, env_hash);
@@ -1026,6 +1023,7 @@ impl Component for PlainListing {
}
UIEvent::Input(Key::Esc) if !self.unfocused && !self.filter_term.is_empty() => {
self.set_coordinates((self.new_cursor_pos.0, self.new_cursor_pos.1, None));
self.set_dirty();
self.refresh_mailbox(context);
return true;
}


+ 18
- 41
ui/src/components/mail/listing/thread.rs View File

@@ -78,27 +78,34 @@ impl ListingTrait for ThreadListing {
let rows = get_y(bottom_right) - get_y(upper_left) + 1;
if let Some(mvm) = self.movement.take() {
match mvm {
PageMovement::PageUp => {
self.new_cursor_pos.2 = self.new_cursor_pos.2.saturating_sub(rows);
PageMovement::Up(amount) => {
self.new_cursor_pos.2 = self.new_cursor_pos.2.saturating_sub(amount);
}
PageMovement::PageDown => {
if self.new_cursor_pos.2 + rows + 1 < self.length {
self.new_cursor_pos.2 += rows;
} else if self.new_cursor_pos.2 + rows > self.length {
PageMovement::PageUp(multiplier) => {
self.new_cursor_pos.2 = self.new_cursor_pos.2.saturating_sub(rows * multiplier);
}
PageMovement::Down(amount) => {
if self.new_cursor_pos.2 + amount + 1 < self.length {
self.new_cursor_pos.2 += amount;
} else {
self.new_cursor_pos.2 = self.length - 1;
}
}
PageMovement::PageDown(multiplier) => {
if self.new_cursor_pos.2 + rows * multiplier + 1 < self.length {
self.new_cursor_pos.2 += rows * multiplier;
} else if self.new_cursor_pos.2 + rows * multiplier > self.length {
self.new_cursor_pos.2 = self.length - 1;
} else {
self.new_cursor_pos.2 = (self.length / rows) * rows;
}
}
PageMovement::Right(_) | PageMovement::Left(_) => {}
PageMovement::Home => {
self.new_cursor_pos.2 = 0;
}
PageMovement::End => {
if self.new_cursor_pos.2 + rows > self.length {
self.new_cursor_pos.2 = self.length - 1;
} else {
self.new_cursor_pos.2 = (self.length / rows) * rows;
}
self.new_cursor_pos.2 = self.length - 1;
}
}
}
@@ -588,36 +595,6 @@ impl Component for ThreadListing {
}
}
match *event {
UIEvent::Input(Key::Up) => {
if self.cursor_pos.2 > 0 {
self.new_cursor_pos.2 -= 1;
self.dirty = true;
}
return true;
}
UIEvent::Input(Key::Down) => {
if self.length > 0 && self.new_cursor_pos.2 < self.length - 1 {
self.new_cursor_pos.2 += 1;
self.dirty = true;
}
return true;
}
UIEvent::Input(ref key) if *key == Key::PageUp => {
self.movement = Some(PageMovement::PageUp);
self.set_dirty();
}
UIEvent::Input(ref key) if *key == Key::PageDown => {
self.movement = Some(PageMovement::PageDown);
self.set_dirty();
}
UIEvent::Input(ref key) if *key == Key::Home => {
self.movement = Some(PageMovement::Home);
self.set_dirty();
}
UIEvent::Input(ref key) if *key == Key::End => {
self.movement = Some(PageMovement::End);
self.set_dirty();
}
UIEvent::Input(Key::Char('\n')) if !self.unfocused => {
self.unfocused = true;
self.dirty = true;


+ 20
- 7
ui/src/components/mail/view/thread.rs View File

@@ -428,16 +428,29 @@ impl ThreadView {
}
if let Some(mvm) = self.movement.take() {
match mvm {
PageMovement::PageUp => {
self.new_cursor_pos = self.new_cursor_pos.saturating_sub(rows);
PageMovement::Up(amount) => {
self.new_cursor_pos = self.new_cursor_pos.saturating_sub(amount);
}
PageMovement::PageDown => {
if self.new_cursor_pos + rows + 1 < height {
self.new_cursor_pos += rows;
PageMovement::PageUp(multiplier) => {
self.new_cursor_pos = self.new_cursor_pos.saturating_sub(rows * multiplier);
}
PageMovement::Down(amount) => {
if self.new_cursor_pos + amount + 1 < height {
self.new_cursor_pos += amount;
} else if self.new_cursor_pos + amount > height {
self.new_cursor_pos = height - 1;
} else {
self.new_cursor_pos = (height / rows) * rows;
}
}
PageMovement::PageDown(multiplier) => {
if self.new_cursor_pos + rows * multiplier + 1 < height {
self.new_cursor_pos += rows * multiplier;
} else {
self.new_cursor_pos = (height / rows) * rows;
}
}
PageMovement::Right(_) | PageMovement::Left(_) => {}
PageMovement::Home => {
self.new_cursor_pos = 0;
}
@@ -988,11 +1001,11 @@ impl Component for ThreadView {
return true;
}
UIEvent::Input(ref key) if *key == shortcuts["prev_page"] => {
self.movement = Some(PageMovement::PageUp);
self.movement = Some(PageMovement::PageUp(1));
self.dirty = true;
}
UIEvent::Input(ref key) if *key == shortcuts["next_page"] => {
self.movement = Some(PageMovement::PageDown);
self.movement = Some(PageMovement::PageDown(1));
self.dirty = true;
}
UIEvent::Input(ref key) if *key == Key::Home => {


+ 22
- 9
ui/src/components/utilities.rs View File

@@ -265,9 +265,13 @@ impl Component for VSplit {

#[derive(Debug, Clone, Copy)]
pub enum PageMovement {
Up(usize),
Right(usize),
Left(usize),
Down(usize),
PageUp(usize),
PageDown(usize),
Home,
PageUp,
PageDown,
End,
}

@@ -448,14 +452,23 @@ impl Component for Pager {
let height = height!(area);
if let Some(mvm) = self.movement.take() {
match mvm {
PageMovement::PageUp => {
self.cursor.1 = self.cursor.1.saturating_sub(height);
PageMovement::Up(amount) => {
self.cursor.1 = self.cursor.1.saturating_sub(amount);
}
PageMovement::PageDown => {
if self.cursor.1 + height < self.height {
self.cursor.1 += height;
PageMovement::PageUp(multiplier) => {
self.cursor.1 = self.cursor.1.saturating_sub(height * multiplier);
}
PageMovement::Down(amount) => {
if self.cursor.1 + amount < self.height {
self.cursor.1 += amount;
}
}
PageMovement::PageDown(multiplier) => {
if self.cursor.1 + height * multiplier < self.height {
self.cursor.1 += height * multiplier;
}
}
PageMovement::Right(_) | PageMovement::Left(_) => {}
PageMovement::Home => {
self.cursor.1 = 0;
}
@@ -517,12 +530,12 @@ impl Component for Pager {
return true;
}
UIEvent::Input(ref key) if *key == shortcuts["page_up"] => {
self.movement = Some(PageMovement::PageUp);
self.movement = Some(PageMovement::PageUp(1));
self.dirty = true;
return true;
}
UIEvent::Input(ref key) if *key == shortcuts["page_down"] => {
self.movement = Some(PageMovement::PageDown);
self.movement = Some(PageMovement::PageDown(1));
self.dirty = true;
return true;
}


+ 3
- 4
ui/src/conf/accounts.rs View File

@@ -257,7 +257,7 @@ impl Account {
settings.conf.cache_type = crate::conf::CacheType::None;
}

let mut ret = Account {
Account {
index,
name,
is_online: false,
@@ -277,10 +277,9 @@ impl Account {
notify_fn,

event_queue: VecDeque::with_capacity(8),
};

ret
}
}

fn init(&mut self) {
let mut ref_folders: FnvHashMap<FolderHash, Folder> =
self.backend.read().unwrap().folders();


Loading…
Cancel
Save