mirror of
https://github.com/wez/wezterm.git
synced 2024-12-24 22:01:47 +03:00
FEATURE: Allow ScrollByPage f64 values
`ScrollByPage` can accept non-integer values in the configuration. This allows fractional page scrolling, such as by half a page. The default remains the same, at 1 page.
This commit is contained in:
parent
35e921b9e6
commit
e01f9c0e7d
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -683,6 +683,7 @@ dependencies = [
|
|||||||
"mlua",
|
"mlua",
|
||||||
"notify",
|
"notify",
|
||||||
"open",
|
"open",
|
||||||
|
"ordered-float",
|
||||||
"portable-pty",
|
"portable-pty",
|
||||||
"pretty_env_logger",
|
"pretty_env_logger",
|
||||||
"promise",
|
"promise",
|
||||||
@ -2674,6 +2675,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "7940cf2ca942593318d07fcf2596cdca60a85c9e7fab408a5e21a4f9dcd40d87"
|
checksum = "7940cf2ca942593318d07fcf2596cdca60a85c9e7fab408a5e21a4f9dcd40d87"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"num-traits",
|
"num-traits",
|
||||||
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -29,6 +29,7 @@ mlua = {version="0.7", features=["vendored", "lua54", "async", "send"]}
|
|||||||
# file change notification
|
# file change notification
|
||||||
notify = "4.0"
|
notify = "4.0"
|
||||||
open = "2.0"
|
open = "2.0"
|
||||||
|
ordered-float = { version = "2.10", features = ["serde"] }
|
||||||
portable-pty = { path = "../pty", features = ["serde_support"]}
|
portable-pty = { path = "../pty", features = ["serde_support"]}
|
||||||
promise = { path = "../promise" }
|
promise = { path = "../promise" }
|
||||||
serde = {version="1.0", features = ["rc", "derive"]}
|
serde = {version="1.0", features = ["rc", "derive"]}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
|
use crate::de_notnan;
|
||||||
use crate::keys::KeyNoAction;
|
use crate::keys::KeyNoAction;
|
||||||
use crate::ConfigHandle;
|
use crate::ConfigHandle;
|
||||||
use crate::LeaderKey;
|
use crate::LeaderKey;
|
||||||
use luahelper::impl_lua_conversion;
|
use luahelper::impl_lua_conversion;
|
||||||
|
use ordered_float::NotNan;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@ -220,7 +222,8 @@ pub enum KeyAssignment {
|
|||||||
ReloadConfiguration,
|
ReloadConfiguration,
|
||||||
MoveTabRelative(isize),
|
MoveTabRelative(isize),
|
||||||
MoveTab(usize),
|
MoveTab(usize),
|
||||||
ScrollByPage(isize),
|
#[serde(deserialize_with = "de_notnan")]
|
||||||
|
ScrollByPage(NotNan<f64>),
|
||||||
ScrollByLine(isize),
|
ScrollByLine(isize),
|
||||||
ScrollToPrompt(isize),
|
ScrollToPrompt(isize),
|
||||||
ScrollToTop,
|
ScrollToTop,
|
||||||
@ -554,11 +557,15 @@ impl InputMap {
|
|||||||
KeyCode::Physical(PhysKeyCode::PageDown),
|
KeyCode::Physical(PhysKeyCode::PageDown),
|
||||||
MoveTabRelative(1)
|
MoveTabRelative(1)
|
||||||
],
|
],
|
||||||
[Modifiers::SHIFT, KeyCode::PageUp, ScrollByPage(-1)],
|
[
|
||||||
|
Modifiers::SHIFT,
|
||||||
|
KeyCode::PageUp,
|
||||||
|
ScrollByPage(NotNan::new(-1.0).unwrap())
|
||||||
|
],
|
||||||
[
|
[
|
||||||
Modifiers::SHIFT,
|
Modifiers::SHIFT,
|
||||||
KeyCode::Physical(PhysKeyCode::PageDown),
|
KeyCode::Physical(PhysKeyCode::PageDown),
|
||||||
ScrollByPage(1)
|
ScrollByPage(NotNan::new(1.0).unwrap())
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
Modifiers::ALT,
|
Modifiers::ALT,
|
||||||
|
@ -4,6 +4,7 @@ use anyhow::{anyhow, bail, Context, Error};
|
|||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use luahelper::impl_lua_conversion;
|
use luahelper::impl_lua_conversion;
|
||||||
use mlua::Lua;
|
use mlua::Lua;
|
||||||
|
use ordered_float::NotNan;
|
||||||
use serde::{Deserialize, Deserializer, Serialize};
|
use serde::{Deserialize, Deserializer, Serialize};
|
||||||
use smol::channel::{Receiver, Sender};
|
use smol::channel::{Receiver, Sender};
|
||||||
use smol::prelude::*;
|
use smol::prelude::*;
|
||||||
@ -661,6 +662,14 @@ impl std::ops::Deref for ConfigHandle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn de_notnan<'de, D>(deserializer: D) -> Result<NotNan<f64>, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let value: f64 = de_number(deserializer)?;
|
||||||
|
NotNan::new(value).map_err(|err| serde::de::Error::custom(err.to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
/// Deserialize either an integer or a float as a float
|
/// Deserialize either an integer or a float as a float
|
||||||
pub(crate) fn de_number<'de, D>(deserializer: D) -> Result<f64, D::Error>
|
pub(crate) fn de_number<'de, D>(deserializer: D) -> Result<f64, D::Error>
|
||||||
where
|
where
|
||||||
|
@ -14,4 +14,18 @@ return {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
*Since: nightly builds only*
|
||||||
|
|
||||||
|
You may now use floating point values to scroll by partial pages. This example shows
|
||||||
|
how to make the `PageUp`/`PageDown` scroll by half a page at a time:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local wezterm = require 'wezterm';
|
||||||
|
|
||||||
|
return {
|
||||||
|
keys = {
|
||||||
|
{key="PageUp", mods="SHIFT", action=wezterm.action{ScrollByPage=-0.5}},
|
||||||
|
{key="PageDown", mods="SHIFT", action=wezterm.action{ScrollByPage=0.5}},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
@ -1756,7 +1756,7 @@ impl TermWindow {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scroll_by_page(&mut self, amount: isize) -> anyhow::Result<()> {
|
fn scroll_by_page(&mut self, amount: f64) -> anyhow::Result<()> {
|
||||||
let pane = match self.get_active_pane_or_overlay() {
|
let pane = match self.get_active_pane_or_overlay() {
|
||||||
Some(pane) => pane,
|
Some(pane) => pane,
|
||||||
None => return Ok(()),
|
None => return Ok(()),
|
||||||
@ -1764,9 +1764,9 @@ impl TermWindow {
|
|||||||
let dims = pane.get_dimensions();
|
let dims = pane.get_dimensions();
|
||||||
let position = self
|
let position = self
|
||||||
.get_viewport(pane.pane_id())
|
.get_viewport(pane.pane_id())
|
||||||
.unwrap_or(dims.physical_top)
|
.unwrap_or(dims.physical_top) as f64
|
||||||
.saturating_add(amount * dims.viewport_rows as isize);
|
+ (amount * dims.viewport_rows as f64);
|
||||||
self.set_viewport(pane.pane_id(), Some(position), dims);
|
self.set_viewport(pane.pane_id(), Some(position as isize), dims);
|
||||||
if let Some(win) = self.window.as_ref() {
|
if let Some(win) = self.window.as_ref() {
|
||||||
win.invalidate();
|
win.invalidate();
|
||||||
}
|
}
|
||||||
@ -1925,7 +1925,7 @@ impl TermWindow {
|
|||||||
ReloadConfiguration => config::reload(),
|
ReloadConfiguration => config::reload(),
|
||||||
MoveTab(n) => self.move_tab(*n)?,
|
MoveTab(n) => self.move_tab(*n)?,
|
||||||
MoveTabRelative(n) => self.move_tab_relative(*n)?,
|
MoveTabRelative(n) => self.move_tab_relative(*n)?,
|
||||||
ScrollByPage(n) => self.scroll_by_page(*n)?,
|
ScrollByPage(n) => self.scroll_by_page(**n)?,
|
||||||
ScrollByLine(n) => self.scroll_by_line(*n)?,
|
ScrollByLine(n) => self.scroll_by_line(*n)?,
|
||||||
ScrollToPrompt(n) => self.scroll_to_prompt(*n)?,
|
ScrollToPrompt(n) => self.scroll_to_prompt(*n)?,
|
||||||
ScrollToTop => self.scroll_to_top(pane),
|
ScrollToTop => self.scroll_to_top(pane),
|
||||||
|
Loading…
Reference in New Issue
Block a user