Function broot::command::move_sel

source ·
pub fn move_sel(selection: usize, len: usize, d: i32, cycle: bool) -> usize
Expand description

compute a new selection index for the given list len, taking into account whether we should cycle or not

Examples found in repository?
src/syntactic/syntactic_view.rs (line 267)
265
266
267
268
269
270
271
272
    pub fn move_selection(&mut self, dy: i32, cycle: bool) {
        if let Some(idx) = self.selection_idx {
            self.selection_idx = Some(move_sel(idx, self.lines.len(), dy, cycle));
        } else if !self.lines.is_empty() {
            self.selection_idx = Some(0)
        }
        self.ensure_selection_is_visible();
    }
More examples
Hide additional examples
src/filesystems/filesystems_state.rs (line 130)
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
    fn move_line(
        &mut self,
        internal_exec: &InternalExecution,
        input_invocation: Option<&VerbInvocation>,
        dir: i32, // -1 for up, 1 for down
        cycle: bool,
    ) -> CmdResult {
        let count = get_arg(input_invocation, internal_exec, 1);
        let dir = dir * count as i32;
        if let Some(f) = self.filtered.as_mut() {
            f.selection_idx = move_sel(f.selection_idx, f.mounts.len(), dir, cycle);
        } else {
            self.selection_idx = move_sel(self.selection_idx, self.mounts.len().get(), dir, cycle);
        }
        if self.selection_idx < self.scroll {
            self.scroll = self.selection_idx;
        } else if self.selection_idx >= self.scroll + self.page_height {
            self.scroll = self.selection_idx + 1 - self.page_height;
        }
        CmdResult::Keep
    }