Add quick scrolling

Not ideal, but better than nothing.

Closes: https://github.com/sayanarijit/xplr/issues/509
pull/511/head
Arijit Basu 2 years ago committed by Arijit Basu
parent 81e83365f2
commit 93bd53bbcb

@ -208,8 +208,6 @@ Example:
#### FocusByFileName
**YAML:** `FocusByFileName: string`
Focus on the file by name from the present working directory.
Type: { FocusByFileName = "string" }
@ -219,6 +217,42 @@ Example:
- Lua: `{ FocusByFileName = "filename.ext" }`
- YAML: `FocusByFileName: filename.ext`
#### ScrollUp
Scroll up by terminal height.
Example:
- Lua: `"ScrollUp"`
- YAML: `ScrollUp`
#### ScrollDown
Scroll down by terminal height.
Example:
- Lua: `"ScrollDown"`
- YAML: `ScrollDown`
#### ScrollUpHalf
Scroll up by half of terminal height.
Example:
- Lua: `"ScrollUpHalf"`
- YAML: `ScrollUpHalf`
#### ScrollDownHalf
Scroll down by half of terminal height.
Example:
- Lua: `"ScrollDownHalf"`
- YAML: `ScrollDownHalf`
#### ChangeDirectory
Change the present working directory ($PWD)

@ -406,6 +406,10 @@ impl App {
FocusByIndex(i) => self.focus_by_index(i),
FocusByIndexFromInput => self.focus_by_index_from_input(),
FocusByFileName(n) => self.focus_by_file_name(&n, true),
ScrollUp => self.scroll_up(),
ScrollDown => self.scroll_down(),
ScrollUpHalf => self.scroll_up_half(),
ScrollDownHalf => self.scroll_down_half(),
ChangeDirectory(dir) => self.change_directory(&dir, true),
Enter => self.enter(),
Back => self.back(),
@ -635,7 +639,7 @@ impl App {
Ok(self)
}
fn focus_previous_by_relative_index(mut self, index: usize) -> Result<Self> {
pub fn focus_previous_by_relative_index(mut self, index: usize) -> Result<Self> {
let mut history = self.history.clone();
if let Some(dir) = self.directory_buffer_mut() {
if let Some(n) = dir.focused_node() {
@ -680,7 +684,7 @@ impl App {
Ok(self)
}
fn focus_next_by_relative_index(mut self, index: usize) -> Result<Self> {
pub fn focus_next_by_relative_index(mut self, index: usize) -> Result<Self> {
let mut history = self.history.clone();
if let Some(dir) = self.directory_buffer_mut() {
if let Some(n) = dir.focused_node() {
@ -927,6 +931,26 @@ impl App {
}
}
pub fn scroll_up(mut self) -> Result<Self> {
self.msg_out.push_back(MsgOut::ScrollUp);
Ok(self)
}
pub fn scroll_down(mut self) -> Result<Self> {
self.msg_out.push_back(MsgOut::ScrollDown);
Ok(self)
}
pub fn scroll_up_half(mut self) -> Result<Self> {
self.msg_out.push_back(MsgOut::ScrollUp);
Ok(self)
}
pub fn scroll_down_half(mut self) -> Result<Self> {
self.msg_out.push_back(MsgOut::ScrollDownHalf);
Ok(self)
}
pub fn focus_path(self, path: &str, save_history: bool) -> Result<Self> {
let mut pathbuf = PathBuf::from(path);
if pathbuf.is_relative() {

@ -1206,6 +1206,30 @@ xplr.config.modes.builtin.default = {
},
},
},
["page-up"] = {
help = "scroll up",
messages = {
"ScrollUp",
},
},
["page-down"] = {
help = "scroll down",
messages = {
"ScrollDown",
},
},
["{"] = {
help = "scroll up half",
messages = {
"ScrollUpHalf",
},
},
["}"] = {
help = "scroll down half",
messages = {
"ScrollDownHalf",
},
},
},
on_number = {
help = "input",

@ -174,9 +174,6 @@ pub enum ExternalMsg {
/// - YAML: `FocusByIndexFromInput`
FocusByIndexFromInput,
///
/// **YAML:** `FocusByFileName: string`
///
/// Focus on the file by name from the present working directory.
///
/// Type: { FocusByFileName = "string" }
@ -187,6 +184,38 @@ pub enum ExternalMsg {
/// - YAML: `FocusByFileName: filename.ext`
FocusByFileName(String),
/// Scroll up by terminal height.
///
/// Example:
///
/// - Lua: `"ScrollUp"`
/// - YAML: `ScrollUp`
ScrollUp,
/// Scroll down by terminal height.
///
/// Example:
///
/// - Lua: `"ScrollDown"`
/// - YAML: `ScrollDown`
ScrollDown,
/// Scroll up by half of terminal height.
///
/// Example:
///
/// - Lua: `"ScrollUpHalf"`
/// - YAML: `ScrollUpHalf`
ScrollUpHalf,
/// Scroll down by half of terminal height.
///
/// Example:
///
/// - Lua: `"ScrollDownHalf"`
/// - YAML: `ScrollDownHalf`
ScrollDownHalf,
/// Change the present working directory ($PWD)
///
/// Type: { ChangeDirectory = "string" }

@ -8,7 +8,6 @@ pub enum MsgOut {
ExploreParentsAsync,
Refresh,
ClearScreen,
Quit,
Debug(String),
Call(Command),
CallSilently(Command),
@ -23,6 +22,11 @@ pub enum MsgOut {
StartFifo(String),
StopFifo,
ToggleFifo(String),
ScrollUp,
ScrollDown,
ScrollUpHalf,
ScrollDownHalf,
Quit,
PrintPwdAndQuit,
PrintFocusPathAndQuit,
PrintSelectionAndQuit,

@ -316,6 +316,30 @@ impl Runner {
terminal.clear()?;
}
ScrollUp => {
app = app.focus_previous_by_relative_index(
terminal.size()?.height as usize,
)?;
}
ScrollDown => {
app = app.focus_next_by_relative_index(
terminal.size()?.height as usize,
)?;
}
ScrollUpHalf => {
app = app.focus_next_by_relative_index(
terminal.size()?.height as usize / 2,
)?;
}
ScrollDownHalf => {
app = app.focus_next_by_relative_index(
terminal.size()?.height as usize / 2,
)?;
}
ExplorePwdAsync => {
explorer::explore_async(
app.explorer_config.clone(),

Loading…
Cancel
Save