on master help sign in
Move navigation methods from Picker to FilePicker
8516f43Gokul Soumya
helix-term/src/ui/picker.rs+56−23
@@ -312,6 +312,55 @@ impl<T: Item + 'static> FilePicker<T> {
312 self.matches.sort_unstable();
312 self.matches.sort_unstable();
313 }
313 }
314
314
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+
315 fn current_file(&self, editor: &Editor) -> Option<FileLocation> {
364 fn current_file(&self, editor: &Editor) -> Option<FileLocation> {
316 self.picker
365 self.picker
317 .selection()
366 .selection()
@@ -656,51 +705,35 @@ impl<T: Item> Picker<T> {
656
705
657 /// Move the cursor by a number of lines, either down (`Forward`) or up (`Backward`)
706 /// Move the cursor by a number of lines, either down (`Forward`) or up (`Backward`)
658 pub fn move_by(&mut self, amount: usize, direction: Direction) {
707 pub fn move_by(&mut self, amount: usize, direction: Direction) {
659− let len = self.matches.len();
708+ unimplemented!()
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− }
674 }
709 }
675
710
676 /// Move the cursor down by exactly one page. After the last page comes the first page.
711 /// Move the cursor down by exactly one page. After the last page comes the first page.
677 pub fn page_up(&mut self) {
712 pub fn page_up(&mut self) {
678− self.move_by(self.completion_height as usize, Direction::Backward);
713+ unimplemented!()
679 }
714 }
680
715
681 /// Move the cursor up by exactly one page. After the first page comes the last page.
716 /// Move the cursor up by exactly one page. After the first page comes the last page.
682 pub fn page_down(&mut self) {
717 pub fn page_down(&mut self) {
683− self.move_by(self.completion_height as usize, Direction::Forward);
718+ unimplemented!()
684 }
719 }
685
720
686 /// Move the cursor to the first entry
721 /// Move the cursor to the first entry
687 pub fn to_start(&mut self) {
722 pub fn to_start(&mut self) {
688− self.cursor = 0;
723+ unimplemented!()
689 }
724 }
690
725
691 /// Move the cursor to the last entry
726 /// Move the cursor to the last entry
692 pub fn to_end(&mut self) {
727 pub fn to_end(&mut self) {
693− self.cursor = self.matches.len().saturating_sub(1);
728+ unimplemented!()
694 }
729 }
695
730
696 pub fn selection(&self) -> Option<&T> {
731 pub fn selection(&self) -> Option<&T> {
697− self.matches
732+ unimplemented!()
698− .get(self.cursor)
699− .map(|pmatch| &self.options[pmatch.index])
700 }
733 }
701
734
702 pub fn toggle_preview(&mut self) {
735 pub fn toggle_preview(&mut self) {
703− self.show_preview = !self.show_preview;
736+ unimplemented!()
704 }
737 }
705
738
706 fn prompt_handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult {
739 fn prompt_handle_event(&mut self, event: &Event, cx: &mut Context) -> EventResult {