summaryrefslogtreecommitdiffstats
path: root/src/command
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2021-02-14 18:27:26 +0100
committerCanop <cano.petrole@gmail.com>2021-02-14 18:27:26 +0100
commit0016efad0cfecc0386fa8e01403d89af3766912b (patch)
treed8fc63016c6da7dd5fec74bc7a7c1c6e8628eb69 /src/command
parente9cb412e05511d662a856f724451791bc92cc065 (diff)
:line_up_no_cycle and :line_down_no_cyle
May be mapped instead of :line_up and :line_down when you don't want to cycle (ie arrive on top when you go down past the end of the tree/list): { key: ctrl-u internal: line_up_no_cycle } { key: ctrl-j internal: line_down_no_cycle }
Diffstat (limited to 'src/command')
-rw-r--r--src/command/mod.rs2
-rw-r--r--src/command/panel_input.rs4
-rw-r--r--src/command/sel.rs30
3 files changed, 34 insertions, 2 deletions
diff --git a/src/command/mod.rs b/src/command/mod.rs
index 70e89f5..c42a3cb 100644
--- a/src/command/mod.rs
+++ b/src/command/mod.rs
@@ -3,6 +3,7 @@ mod completion;
mod panel_input;
mod parts;
mod sequence;
+mod sel;
mod scroll;
mod trigger_type;
@@ -12,6 +13,7 @@ pub use {
panel_input::PanelInput,
parts::CommandParts,
sequence::Sequence,
+ sel::move_sel,
scroll::ScrollCommand,
trigger_type::TriggerType,
};
diff --git a/src/command/panel_input.rs b/src/command/panel_input.rs
index b065730..903bd59 100644
--- a/src/command/panel_input.rs
+++ b/src/command/panel_input.rs
@@ -309,9 +309,9 @@ impl PanelInput {
}
Event::Wheel(lines_count) => {
let internal = if lines_count > 0 {
- Internal::line_down
+ Internal::line_down_no_cycle
} else {
- Internal::line_up
+ Internal::line_up_no_cycle
};
return Command::Internal {
internal,
diff --git a/src/command/sel.rs b/src/command/sel.rs
new file mode 100644
index 0000000..e345bb3
--- /dev/null
+++ b/src/command/sel.rs
@@ -0,0 +1,30 @@
+
+
+/// compute a new selection index for the given list len,
+/// taking into account whether we should cycle or not
+pub fn move_sel(
+ selection: usize,
+ len: usize,
+ d: i32, // displacement
+ cycle: bool,
+) -> usize {
+ if len == 0 {
+ return 0;
+ }
+ let ns = (selection as i32) + d;
+ if ns < 0 {
+ if cycle {
+ len - 1
+ } else {
+ 0
+ }
+ } else if ns >= len as i32 {
+ if cycle {
+ 0
+ } else {
+ len - 1
+ }
+ } else {
+ ns as usize
+ }
+}