@ -19,7 +19,6 @@
* along with meli . If not , see < http ://www.gnu.org/licenses/>.
* /
use super ::EntryStrings ;
use super ::* ;
use crate ::components ::PageMovement ;
use crate ::jobs ::JoinHandle ;
@ -153,7 +152,7 @@ pub struct CompactListing {
movement : Option < PageMovement > ,
modifier_active : bool ,
modifier_command : Option < cha r> ,
modifier_command : Option < Modifie r> ,
id : ComponentId ,
}
@ -595,7 +594,9 @@ impl ListingTrait for CompactListing {
self . highlight_line ( grid , new_area , * idx , context ) ;
context . dirty_areas . push_back ( new_area ) ;
}
return ;
if ! self . force_draw {
return ;
}
} else if self . cursor_pos ! = self . new_cursor_pos {
self . cursor_pos = self . new_cursor_pos ;
}
@ -852,8 +853,20 @@ impl ListingTrait for CompactListing {
}
}
fn set_command_modifier ( & mut self , is_active : bool ) {
self . modifier_active = is_active ;
fn unfocused ( & self ) -> bool {
self . unfocused
}
fn set_modifier_active ( & mut self , new_val : bool ) {
self . modifier_active = new_val ;
}
fn set_modifier_command ( & mut self , new_val : Option < Modifier > ) {
self . modifier_command = new_val ;
}
fn modifier_command ( & self ) -> Option < Modifier > {
self . modifier_command
}
fn set_movement ( & mut self , mvm : PageMovement ) {
@ -1406,8 +1419,7 @@ impl Component for CompactListing {
let ( upper_left , bottom_right ) = area ;
let rows = get_y ( bottom_right ) - get_y ( upper_left ) + 1 ;
if let Some ( 's' ) = self . modifier_command . take ( ) {
self . set_command_modifier ( false ) ;
if let Some ( modifier ) = self . modifier_command . take ( ) {
if let Some ( mvm ) = self . movement . as_ref ( ) {
match mvm {
PageMovement ::Up ( amount ) = > {
@ -1415,16 +1427,47 @@ impl Component for CompactListing {
..= self . new_cursor_pos . 2
{
let thread = self . get_thread_under_cursor ( c ) ;
self . selection . entry ( thread ) . and_modify ( | e | * e = ! * e ) ;
match modifier {
Modifier ::SymmetricDifference = > {
self . selection . entry ( thread ) . and_modify ( | e | * e = ! * e ) ;
}
Modifier ::Union = > {
self . selection . entry ( thread ) . and_modify ( | e | * e = true ) ;
}
Modifier ::Difference = > {
self . selection . entry ( thread ) . and_modify ( | e | * e = false ) ;
}
Modifier ::Intersection = > { }
}
self . row_updates . push ( thread ) ;
}
if modifier = = Modifier ::Intersection {
for c in ( 0 .. self . new_cursor_pos . 2. saturating_sub ( * amount ) )
. chain ( ( self . new_cursor_pos . 2 + 2 ) .. self . length )
{
let thread = self . get_thread_under_cursor ( c ) ;
self . selection . entry ( thread ) . and_modify ( | e | * e = false ) ;
self . row_updates . push ( thread ) ;
}
}
}
PageMovement ::PageUp ( multiplier ) = > {
for c in self . new_cursor_pos . 2. saturating_sub ( rows * multiplier )
..= self . new_cursor_pos . 2
{
let thread = self . get_thread_under_cursor ( c ) ;
self . selection . entry ( thread ) . and_modify ( | e | * e = ! * e ) ;
match modifier {
Modifier ::SymmetricDifference = > {
self . selection . entry ( thread ) . and_modify ( | e | * e = ! * e ) ;
}
Modifier ::Union = > {
self . selection . entry ( thread ) . and_modify ( | e | * e = true ) ;
}
Modifier ::Difference = > {
self . selection . entry ( thread ) . and_modify ( | e | * e = false ) ;
}
Modifier ::Intersection = > { }
}
self . row_updates . push ( thread ) ;
}
}
@ -1433,9 +1476,30 @@ impl Component for CompactListing {
.. std ::cmp ::min ( self . length , self . new_cursor_pos . 2 + amount + 1 )
{
let thread = self . get_thread_under_cursor ( c ) ;
self . selection . entry ( thread ) . and_modify ( | e | * e = ! * e ) ;
match modifier {
Modifier ::SymmetricDifference = > {
self . selection . entry ( thread ) . and_modify ( | e | * e = ! * e ) ;
}
Modifier ::Union = > {
self . selection . entry ( thread ) . and_modify ( | e | * e = true ) ;
}
Modifier ::Difference = > {
self . selection . entry ( thread ) . and_modify ( | e | * e = false ) ;
}
Modifier ::Intersection = > { }
}
self . row_updates . push ( thread ) ;
}
if modifier = = Modifier ::Intersection {
for c in ( 0 .. self . new_cursor_pos . 2 ) . chain (
( std ::cmp ::min ( self . length , self . new_cursor_pos . 2 + amount + 1 )
+ 1 ) .. self . length ,
) {
let thread = self . get_thread_under_cursor ( c ) ;
self . selection . entry ( thread ) . and_modify ( | e | * e = false ) ;
self . row_updates . push ( thread ) ;
}
}
}
PageMovement ::PageDown ( multiplier ) = > {
for c in self . new_cursor_pos . 2
@ -1445,27 +1509,87 @@ impl Component for CompactListing {
)
{
let thread = self . get_thread_under_cursor ( c ) ;
self . selection . entry ( thread ) . and_modify ( | e | * e = ! * e ) ;
match modifier {
Modifier ::SymmetricDifference = > {
self . selection . entry ( thread ) . and_modify ( | e | * e = ! * e ) ;
}
Modifier ::Union = > {
self . selection . entry ( thread ) . and_modify ( | e | * e = true ) ;
}
Modifier ::Difference = > {
self . selection . entry ( thread ) . and_modify ( | e | * e = false ) ;
}
Modifier ::Intersection = > { }
}
self . row_updates . push ( thread ) ;
}
if modifier = = Modifier ::Intersection {
for c in ( 0 .. self . new_cursor_pos . 2 ) . chain (
( std ::cmp ::min (
self . new_cursor_pos . 2 + rows * multiplier + 1 ,
self . length ,
) + 1 ) .. self . length ,
) {
let thread = self . get_thread_under_cursor ( c ) ;
self . selection . entry ( thread ) . and_modify ( | e | * e = false ) ;
self . row_updates . push ( thread ) ;
}
}
}
PageMovement ::Right ( _ ) | PageMovement ::Left ( _ ) = > { }
PageMovement ::Home = > {
for c in 0 ..= self . new_cursor_pos . 2 {
let thread = self . get_thread_under_cursor ( c ) ;
self . selection . entry ( thread ) . and_modify ( | e | * e = ! * e ) ;
match modifier {
Modifier ::SymmetricDifference = > {
self . selection . entry ( thread ) . and_modify ( | e | * e = ! * e ) ;
}
Modifier ::Union = > {
self . selection . entry ( thread ) . and_modify ( | e | * e = true ) ;
}
Modifier ::Difference = > {
self . selection . entry ( thread ) . and_modify ( | e | * e = false ) ;
}
Modifier ::Intersection = > { }
}
self . row_updates . push ( thread ) ;
}
if modifier = = Modifier ::Intersection {
for c in ( self . new_cursor_pos . 2 + 1 ) .. self . length {
let thread = self . get_thread_under_cursor ( c ) ;
self . selection . entry ( thread ) . and_modify ( | e | * e = false ) ;
self . row_updates . push ( thread ) ;
}
}
}
PageMovement ::End = > {
for c in self . new_cursor_pos . 2 .. self . length {
let thread = self . get_thread_under_cursor ( c ) ;
self . selection . entry ( thread ) . and_modify ( | e | * e = ! * e ) ;
match modifier {
Modifier ::SymmetricDifference = > {
self . selection . entry ( thread ) . and_modify ( | e | * e = ! * e ) ;
}
Modifier ::Union = > {
self . selection . entry ( thread ) . and_modify ( | e | * e = true ) ;
}
Modifier ::Difference = > {
self . selection . entry ( thread ) . and_modify ( | e | * e = false ) ;
}
Modifier ::Intersection = > { }
}
self . row_updates . push ( thread ) ;
}
if modifier = = Modifier ::Intersection {
for c in 0 .. self . new_cursor_pos . 2 {
let thread = self . get_thread_under_cursor ( c ) ;
self . selection . entry ( thread ) . and_modify ( | e | * e = false ) ;
self . row_updates . push ( thread ) ;
}
}
}
}
}
self . force_draw = true ;
}
if ! self . row_updates . is_empty ( ) {
@ -1540,12 +1664,10 @@ impl Component for CompactListing {
}
UIEvent ::Input ( ref key )
if ! self . unfocused
& & shortcut ! (
key = = shortcuts [ CompactListing ::DESCRIPTION ] [ "select_entry" ]
) = >
& & shortcut ! ( key = = shortcuts [ Listing ::DESCRIPTION ] [ "select_entry" ] ) = >
{
if self . modifier_active {
self . modifier_command = Some ( 's' ) ;
if self . modifier_active & & self . modifier_command . is_none ( ) {
self . modifier_command = Some ( Modifier ::default ( ) ) ;
} else {
let thread_hash = self . get_thread_under_cursor ( self . cursor_pos . 2 ) ;
self . selection . entry ( thread_hash ) . and_modify ( | e | * e = ! * e ) ;
@ -1783,6 +1905,8 @@ impl Component for CompactListing {
let config_map = context . settings . shortcuts . compact_listing . key_values ( ) ;
map . insert ( CompactListing ::DESCRIPTION , config_map ) ;
let config_map = context . settings . shortcuts . listing . key_values ( ) ;
map . insert ( Listing ::DESCRIPTION , config_map ) ;
map
}