Commit bd0ed63038
Unsigned
Layout: unified · split
src/config/main.rs +13
| @@ -30,6 +30,8 @@ pub struct MainConfig { | |||
| 30 | pub syncing: SyncConfig, | 30 | pub syncing: SyncConfig, |
| 31 | #[serde(default)] | 31 | #[serde(default)] |
| 32 | pub limits: Limits, | 32 | pub limits: Limits, |
| 33 | #[serde(default = "textbar_scroll_behaviour_default")] | ||
| 34 | pub textbar_scroll_behaviour: TextbarScrollBehaviour, | ||
| 33 | #[serde(default = "image_index_default")] | 35 | #[serde(default = "image_index_default")] |
| 34 | // The image to download from the array of images provided by the invidious api | 36 | // The image to download from the array of images provided by the invidious api |
| 35 | // 0 is usually `maxres` and 3 (default) is good enough for normal uses without having huge files sizes | 37 | // 0 is usually `maxres` and 3 (default) is good enough for normal uses without having huge files sizes |
| @@ -65,6 +67,7 @@ impl Default for MainConfig { | |||
| 65 | image_index: image_index_default(), | 67 | image_index: image_index_default(), |
| 66 | refresh_after_modifying_search_filters: refresh_after_modifying_search_filters_default( | 68 | refresh_after_modifying_search_filters: refresh_after_modifying_search_filters_default( |
| 67 | ), | 69 | ), |
| 70 | textbar_scroll_behaviour: textbar_scroll_behaviour_default(), | ||
| 68 | limits: Limits::default(), | 71 | limits: Limits::default(), |
| 69 | syncing: sync_config_default(), | 72 | syncing: sync_config_default(), |
| 70 | provider: provider_default(), | 73 | provider: provider_default(), |
| @@ -300,3 +303,13 @@ const fn sync_videos_cooldown_secs_default() -> u64 { | |||
| 300 | const fn legacy_input_handling_default() -> bool { | 303 | const fn legacy_input_handling_default() -> bool { |
| 301 | false | 304 | false |
| 302 | } | 305 | } |
| 306 | |||
| 307 | #[derive(Serialize, Deserialize, Clone, Copy)] | ||
| 308 | pub enum TextbarScrollBehaviour { | ||
| 309 | Character, | ||
| 310 | Word, | ||
| 311 | History, | ||
| 312 | } | ||
| 313 | const fn textbar_scroll_behaviour_default() -> TextbarScrollBehaviour { | ||
| 314 | TextbarScrollBehaviour::History | ||
| 315 | } | ||
src/items/searchbar.rs +58 −3
| @@ -238,18 +238,73 @@ impl FrameworkItem for SearchBar { | |||
| 238 | 238 | ||
| 239 | fn message( | 239 | fn message( |
| 240 | &mut self, | 240 | &mut self, |
| 241 | _framework: &mut tui_additions::framework::FrameworkClean, | 241 | framework: &mut tui_additions::framework::FrameworkClean, |
| 242 | data: std::collections::HashMap<String, Box<dyn std::any::Any>>, | 242 | data: std::collections::HashMap<String, Box<dyn std::any::Any>>, |
| 243 | ) -> bool { | 243 | ) -> bool { |
| 244 | if !data.contains_key("type") { | 244 | if !data.contains_key("type") { |
| 245 | return false; | 245 | return false; |
| 246 | } | 246 | } |
| 247 | 247 | ||
| 248 | let scroll_behaviour = framework | ||
| 249 | .data | ||
| 250 | .global | ||
| 251 | .get::<MainConfig>() | ||
| 252 | .unwrap() | ||
| 253 | .textbar_scroll_behaviour; | ||
| 254 | |||
| 248 | data.get("type").is_some_and(|v| { | 255 | data.get("type").is_some_and(|v| { |
| 256 | // copied from key_event | ||
| 257 | // if modify this, also modify it there | ||
| 249 | v.downcast_ref::<String>() | 258 | v.downcast_ref::<String>() |
| 250 | .is_some_and(|v| match v.as_str() { | 259 | .is_some_and(|v| match v.as_str() { |
| 251 | "scrollup" => self.text_field.left().is_ok(), | 260 | "scrollup" => match scroll_behaviour { |
| 252 | "scrolldown" => self.text_field.right().is_ok(), | 261 | TextbarScrollBehaviour::Character => self.text_field.left().is_ok(), |
| 262 | TextbarScrollBehaviour::Word => { | ||
| 263 | previous_word(&mut self.text_field); | ||
| 264 | true | ||
| 265 | } | ||
| 266 | TextbarScrollBehaviour::History => { | ||
| 267 | let history = framework.data.global.get::<SearchHistory>().unwrap(); | ||
| 268 | if self.history_index != Some(0) && !history.0.is_empty() { | ||
| 269 | if self.history_index.is_none() { | ||
| 270 | self.custom_value_cache = self.text_field.content.clone(); | ||
| 271 | self.history_index = None | ||
| 272 | } | ||
| 273 | self.history_index = | ||
| 274 | Some(self.history_index.unwrap_or(history.0.len()) - 1); | ||
| 275 | self.text_field.content = | ||
| 276 | history.0[self.history_index.unwrap()].clone(); | ||
| 277 | let _ = self.text_field.last(); | ||
| 278 | true | ||
| 279 | } else { | ||
| 280 | false | ||
| 281 | } | ||
| 282 | } | ||
| 283 | }, | ||
| 284 | "scrolldown" => match scroll_behaviour { | ||
| 285 | TextbarScrollBehaviour::Character => self.text_field.right().is_ok(), | ||
| 286 | TextbarScrollBehaviour::Word => { | ||
| 287 | next_word(&mut self.text_field); | ||
| 288 | true | ||
| 289 | } | ||
| 290 | TextbarScrollBehaviour::History => { | ||
| 291 | let history = framework.data.global.get::<SearchHistory>().unwrap(); | ||
| 292 | if self.history_index.is_none() { | ||
| 293 | false | ||
| 294 | } else if self.history_index == Some(history.0.len() - 1) { | ||
| 295 | self.history_index = None; | ||
| 296 | self.text_field.content = self.custom_value_cache.clone(); | ||
| 297 | let _ = self.text_field.last(); | ||
| 298 | true | ||
| 299 | } else { | ||
| 300 | self.history_index = self.history_index.map(|n| n + 1); | ||
| 301 | self.text_field.content = | ||
| 302 | history.0[self.history_index.unwrap()].clone(); | ||
| 303 | let _ = self.text_field.last(); | ||
| 304 | true | ||
| 305 | } | ||
| 306 | } | ||
| 307 | }, | ||
| 253 | _ => false, | 308 | _ => false, |
| 254 | }) | 309 | }) |
| 255 | }) | 310 | }) |
src/run.rs +107 −2
| @@ -73,6 +73,12 @@ pub fn run( | |||
| 73 | .unwrap() | 73 | .unwrap() |
| 74 | .mouse_support => | 74 | .mouse_support => |
| 75 | { | 75 | { |
| 76 | let scroll_behaviour = framework | ||
| 77 | .data | ||
| 78 | .global | ||
| 79 | .get::<MainConfig>() | ||
| 80 | .unwrap() | ||
| 81 | .textbar_scroll_behaviour; | ||
| 76 | let command_capture = &mut framework | 82 | let command_capture = &mut framework |
| 77 | .data | 83 | .data |
| 78 | .global | 84 | .global |
| @@ -81,8 +87,55 @@ pub fn run( | |||
| 81 | .command_capture; | 87 | .command_capture; |
| 82 | 88 | ||
| 83 | match mouse.kind { | 89 | match mouse.kind { |
| 90 | // copied from messagebar.rs::key_event | ||
| 91 | // if modify this, also modify it there | ||
| 84 | MouseEventKind::ScrollUp if command_capture.is_some() => { | 92 | MouseEventKind::ScrollUp if command_capture.is_some() => { |
| 85 | updated = updated || command_capture.as_mut().unwrap().left().is_ok() | 93 | updated = updated |
| 94 | || match scroll_behaviour { | ||
| 95 | TextbarScrollBehaviour::Character => { | ||
| 96 | command_capture.as_mut().unwrap().left().is_ok() | ||
| 97 | } | ||
| 98 | TextbarScrollBehaviour::History => { | ||
| 99 | let status = framework.data.global.get::<Status>().unwrap(); | ||
| 100 | let history = | ||
| 101 | framework.data.global.get::<CommandHistory>().unwrap(); | ||
| 102 | if status.command_history_index != Some(0) | ||
| 103 | && !history.0.is_empty() | ||
| 104 | { | ||
| 105 | let new_index = | ||
| 106 | status.command_history_index.unwrap_or(history.0.len()) | ||
| 107 | - 1; | ||
| 108 | let new_content = history.0[new_index].clone(); | ||
| 109 | |||
| 110 | let status = | ||
| 111 | framework.data.global.get_mut::<Status>().unwrap(); | ||
| 112 | let text_field = status.command_capture.as_mut().unwrap(); | ||
| 113 | if status.command_history_index.is_none() { | ||
| 114 | status.command_editing_cache = | ||
| 115 | text_field.content.clone(); | ||
| 116 | } | ||
| 117 | text_field.content = new_content; | ||
| 118 | status.command_history_index = Some(new_index); | ||
| 119 | let _ = text_field.last(); | ||
| 120 | true | ||
| 121 | } else { | ||
| 122 | false | ||
| 123 | } | ||
| 124 | } | ||
| 125 | TextbarScrollBehaviour::Word => { | ||
| 126 | previous_word( | ||
| 127 | framework | ||
| 128 | .data | ||
| 129 | .global | ||
| 130 | .get_mut::<Status>() | ||
| 131 | .unwrap() | ||
| 132 | .command_capture | ||
| 133 | .as_mut() | ||
| 134 | .unwrap(), | ||
| 135 | ); | ||
| 136 | true | ||
| 137 | } | ||
| 138 | } | ||
| 86 | } | 139 | } |
| 87 | MouseEventKind::ScrollUp => { | 140 | MouseEventKind::ScrollUp => { |
| 88 | let data: Box<dyn Any> = Box::new("scrollup".to_string()); | 141 | let data: Box<dyn Any> = Box::new("scrollup".to_string()); |
| @@ -90,7 +143,59 @@ pub fn run( | |||
| 90 | || framework.message(HashMap::from([("type".to_string(), data)])) | 143 | || framework.message(HashMap::from([("type".to_string(), data)])) |
| 91 | } | 144 | } |
| 92 | MouseEventKind::ScrollDown if command_capture.is_some() => { | 145 | MouseEventKind::ScrollDown if command_capture.is_some() => { |
| 93 | updated = updated || command_capture.as_mut().unwrap().right().is_ok() | 146 | updated = updated |
| 147 | || match scroll_behaviour { | ||
| 148 | TextbarScrollBehaviour::Word => { | ||
| 149 | next_word( | ||
| 150 | framework | ||
| 151 | .data | ||
| 152 | .global | ||
| 153 | .get_mut::<Status>() | ||
| 154 | .unwrap() | ||
| 155 | .command_capture | ||
| 156 | .as_mut() | ||
| 157 | .unwrap(), | ||
| 158 | ); | ||
| 159 | true | ||
| 160 | } | ||
| 161 | TextbarScrollBehaviour::History => { | ||
| 162 | let status = framework.data.global.get::<Status>().unwrap(); | ||
| 163 | if status.command_history_index.is_none() { | ||
| 164 | false | ||
| 165 | } else { | ||
| 166 | let history = | ||
| 167 | framework.data.global.get::<CommandHistory>().unwrap(); | ||
| 168 | if status.command_history_index == Some(history.0.len() - 1) | ||
| 169 | { | ||
| 170 | let status = | ||
| 171 | framework.data.global.get_mut::<Status>().unwrap(); | ||
| 172 | let text_field = | ||
| 173 | status.command_capture.as_mut().unwrap(); | ||
| 174 | status.command_history_index = None; | ||
| 175 | text_field.content = | ||
| 176 | status.command_editing_cache.clone(); | ||
| 177 | } else { | ||
| 178 | let new_index = status | ||
| 179 | .command_history_index | ||
| 180 | .unwrap_or(history.0.len()) | ||
| 181 | + 1; | ||
| 182 | let new_content = history.0[new_index].clone(); | ||
| 183 | |||
| 184 | let status = | ||
| 185 | framework.data.global.get_mut::<Status>().unwrap(); | ||
| 186 | let text_field = | ||
| 187 | status.command_capture.as_mut().unwrap(); | ||
| 188 | text_field.content = new_content; | ||
| 189 | status.command_history_index = Some(new_index); | ||
| 190 | let _ = text_field.last(); | ||
| 191 | } | ||
| 192 | true | ||
| 193 | } | ||
| 194 | } | ||
| 195 | TextbarScrollBehaviour::Character => { | ||
| 196 | command_capture.as_mut().unwrap().right().is_ok() | ||
| 197 | } | ||
| 198 | } | ||
| 94 | } | 199 | } |
| 95 | MouseEventKind::ScrollDown => { | 200 | MouseEventKind::ScrollDown => { |
| 96 | let data: Box<dyn Any> = Box::new("scrolldown".to_string()); | 201 | let data: Box<dyn Any> = Box::new("scrolldown".to_string()); |