on master help sign in
Move navigation methods from Picker to FilePicker
commit8516f43837005474439b7e3c8184ecc9f3df0efc authorGokul Soumya <gokulps15@gmail.com> dateSun 18 Jun 2023, 12:05 (3 years ago) parent7a058c7
1 file changed+56−23
helix-term/src/ui/picker.rs+56−23
helix-term/src/ui/picker.rs+56−23
@@ -312,6 +312,55 @@ impl<T: Item + 'static> FilePicker<T> {
312312 self.matches.sort_unstable();
313313 }
314314
315+ /// Move the cursor by a number of lines, either down (`Forward`) or up (`Backward`)
316+ pub fn move_by(&mut self, amount: usize, direction: Direction) {
317+ let len = self.matches.len();
318+
319+ if len == 0 {
320+ // No results, can't move.
321+ return;
322+ }
323+
324+ match direction {
325+ Direction::Forward => {
326+ self.cursor = self.cursor.saturating_add(amount) % len;
327+ }
328+ Direction::Backward => {
329+ self.cursor = self.cursor.saturating_add(len).saturating_sub(amount) % len;
330+ }
331+ }
332+ }
333+
334+ /// Move the cursor down by exactly one page. After the last page comes the first page.
335+ pub fn page_up(&mut self) {
336+ self.move_by(self.completion_height as usize, Direction::Backward);
337+ }
338+
339+ /// Move the cursor up by exactly one page. After the first page comes the last page.
340+ pub fn page_down(&mut self) {
341+ self.move_by(self.completion_height as usize, Direction::Forward);
342+ }
343+
344+ /// Move the cursor to the first entry
345+ pub fn to_start(&mut self) {
346+ self.cursor = 0;
347+ }
348+
349+ /// Move the cursor to the last entry
350+ pub fn to_end(&mut self) {
351+ self.cursor = self.matches.len().saturating_sub(1);
352+ }
353+
354+ pub fn selection(&self) -> Option<&T> {
355+ self.matches
356+ .get(self.cursor)
357+ .map(|pmatch| &self.options[pmatch.index])
358+ }
359+
360+ pub fn toggle_preview(&mut self) {
361+ self.show_preview = !self.show_preview;
362+ }
363+
315364 fn current_file(&self, editor: &Editor) -> Option<FileLocation> {
316365 self.picker
317366 .selection()
@@ -656,51 +705,35 @@ impl<T: Item> Picker<T> {
656705
657706 /// Move the cursor by a number of lines, either down (`Forward`) or up (`Backward`)
658707 pub fn move_by(&mut self, amount: usize, direction: Direction) {
659− let len = self.matches.len();
660−
661− if len == 0 {
662− // No results, can't move.
663− return;
664− }
665−
666− match direction {
667− Direction::Forward => {
668− self.cursor = self.cursor.saturating_add(amount) % len;
669− }
670− Direction::Backward => {
671− self.cursor = self.cursor.saturating_add(len).saturating_sub(amount) % len;
672− }
673− }
708+ unimplemented!()
674709 }
675710
676711 /// Move the cursor down by exactly one page. After the last page comes the first page.
677712 pub fn page_up(&mut self) {
678− self.move_by(self.completion_height as usize, Direction::Backward);
713+ unimplemented!()
679714 }
680715
681716 /// Move the cursor up by exactly one page. After the first page comes the last page.
682717 pub fn page_down(&mut self) {
683− self.move_by(self.completion_height as usize, Direction::Forward);
718+ unimplemented!()
684719 }
685720
686721 /// Move the cursor to the first entry
687722 pub fn to_start(&mut self) {
688− self.cursor = 0;
723+ unimplemented!()
689724 }
690725
691726 /// Move the cursor to the last entry
692727 pub fn to_end(&mut self) {
693− self.cursor = self.matches.len().saturating_sub(1);
728+ unimplemented!()
694729 }
695730
696731 pub fn selection(&self) -> Option<&T> {
697− self.matches
698− .get(self.cursor)
699− .map(|pmatch| &self.options[pmatch.index])
732+ unimplemented!()
700733 }
701734
702735 pub fn toggle_preview(&mut self) {
703− self.show_preview = !self.show_preview;
736+ unimplemented!()
704737 }
705738
706739 fn prompt_handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult {