Pass scrolltop in custom Lua function

pull/708/head
Arijit Basu 2 months ago
parent 168f552a3a
commit f54e28903a
No known key found for this signature in database
GPG Key ID: 0F8EF5258DC38077

@ -42,9 +42,16 @@ Set it to `true` if you want to hide all remaps in the help menu.
Type: boolean Type: boolean
#### xplr.config.general.vimlike_scrolling #### xplr.config.general.paginated_scrolling
Set it to `true` if you want vim-like scrolling. Set it to `true` if you want paginated scrolling.
Type: boolean
#### xplr.config.general.scroll_padding
Set the padding value to the scroll area.
Only applicable when `xplr.config.general.paginated_scrolling = false`.
Type: boolean Type: boolean

@ -495,6 +495,7 @@ It contains the following information:
- [layout_size][37] - [layout_size][37]
- [screen_size][37] - [screen_size][37]
- [scrolltop][57]
- [app][38] - [app][38]
### Size ### Size
@ -508,6 +509,12 @@ It contains the following information:
Every field is of integer type. Every field is of integer type.
### scrolltop
Type: integer
The start index of the visible nodes in the table.
### app ### app
This is a lightweight version of the [Lua Context][39]. In this context, the This is a lightweight version of the [Lua Context][39]. In this context, the
@ -587,3 +594,4 @@ Hence, only the following fields are available.
[54]: borders.md#border-type [54]: borders.md#border-type
[55]: #customlayout [55]: #customlayout
[56]: sum-type.md [56]: sum-type.md
[57]: #scrolltop

@ -132,6 +132,8 @@ compatibility.
`xplr.config.general.paginated_scrolling = true` to revert back to the `xplr.config.general.paginated_scrolling = true` to revert back to the
paginated scrolling. paginated scrolling.
- Set `xplr.config.general.scroll_padding` to customize the scroll padding. - Set `xplr.config.general.scroll_padding` to customize the scroll padding.
- The calculated `scrolltop` value will be passed as part of the
`Content Rendeder Argument` in `Dynamic` layout renderer functions.
Thanks to @noahmayr for contributing to a major part of this release. Thanks to @noahmayr for contributing to a major part of this release.

@ -96,8 +96,8 @@ xplr.config.general.hide_remaps_in_help_menu = false
-- Type: boolean -- Type: boolean
xplr.config.general.paginated_scrolling = false xplr.config.general.paginated_scrolling = false
-- Set the padding value to the scroll area. Only applicable when -- Set the padding value to the scroll area.
-- `xplr.config.general.paginated_scrolling` is set to `false`. -- Only applicable when `xplr.config.general.paginated_scrolling = false`.
-- --
-- Type: boolean -- Type: boolean
xplr.config.general.scroll_padding = 5 xplr.config.general.scroll_padding = 5
@ -489,7 +489,7 @@ xplr.config.general.sort_and_filter_ui.search_identifiers = {
-- --
-- Type: nullable string -- Type: nullable string
xplr.config.general.sort_and_filter_ui.search_direction_identifiers.ordered.format = xplr.config.general.sort_and_filter_ui.search_direction_identifiers.ordered.format =
"" ""
-- The shape of unordered indicator for search ordering identifiers in Sort & filter panel. -- The shape of unordered indicator for search ordering identifiers in Sort & filter panel.
-- --
@ -687,7 +687,7 @@ xplr.config.general.panel_ui.sort_and_filter.border_style = {}
-- Type: nullable list of [Node Sorter](https://xplr.dev/en/sorting#node-sorter-applicable) -- Type: nullable list of [Node Sorter](https://xplr.dev/en/sorting#node-sorter-applicable)
xplr.config.general.initial_sorting = { xplr.config.general.initial_sorting = {
{ sorter = "ByCanonicalIsDir", reverse = true }, { sorter = "ByCanonicalIsDir", reverse = true },
{ sorter = "ByIRelativePath", reverse = false }, { sorter = "ByIRelativePath", reverse = false },
} }
-- The name of one of the modes to use when xplr loads. -- The name of one of the modes to use when xplr loads.
@ -1336,23 +1336,23 @@ xplr.config.modes.builtin.default = {
} }
xplr.config.modes.builtin.default.key_bindings.on_key["v"] = xplr.config.modes.builtin.default.key_bindings.on_key["v"] =
xplr.config.modes.builtin.default.key_bindings.on_key["space"] xplr.config.modes.builtin.default.key_bindings.on_key["space"]
xplr.config.modes.builtin.default.key_bindings.on_key["V"] = xplr.config.modes.builtin.default.key_bindings.on_key["V"] =
xplr.config.modes.builtin.default.key_bindings.on_key["ctrl-a"] xplr.config.modes.builtin.default.key_bindings.on_key["ctrl-a"]
xplr.config.modes.builtin.default.key_bindings.on_key["/"] = xplr.config.modes.builtin.default.key_bindings.on_key["/"] =
xplr.config.modes.builtin.default.key_bindings.on_key["ctrl-f"] xplr.config.modes.builtin.default.key_bindings.on_key["ctrl-f"]
xplr.config.modes.builtin.default.key_bindings.on_key["h"] = xplr.config.modes.builtin.default.key_bindings.on_key["h"] =
xplr.config.modes.builtin.default.key_bindings.on_key["left"] xplr.config.modes.builtin.default.key_bindings.on_key["left"]
xplr.config.modes.builtin.default.key_bindings.on_key["j"] = xplr.config.modes.builtin.default.key_bindings.on_key["j"] =
xplr.config.modes.builtin.default.key_bindings.on_key["down"] xplr.config.modes.builtin.default.key_bindings.on_key["down"]
xplr.config.modes.builtin.default.key_bindings.on_key["k"] = xplr.config.modes.builtin.default.key_bindings.on_key["k"] =
xplr.config.modes.builtin.default.key_bindings.on_key["up"] xplr.config.modes.builtin.default.key_bindings.on_key["up"]
xplr.config.modes.builtin.default.key_bindings.on_key["l"] = xplr.config.modes.builtin.default.key_bindings.on_key["l"] =
xplr.config.modes.builtin.default.key_bindings.on_key["right"] xplr.config.modes.builtin.default.key_bindings.on_key["right"]
xplr.config.modes.builtin.default.key_bindings.on_key["tab"] = xplr.config.modes.builtin.default.key_bindings.on_key["tab"] =
xplr.config.modes.builtin.default.key_bindings.on_key["ctrl-i"] -- compatibility workaround xplr.config.modes.builtin.default.key_bindings.on_key["ctrl-i"] -- compatibility workaround
xplr.config.modes.builtin.default.key_bindings.on_key["?"] = xplr.config.modes.builtin.default.key_bindings.on_key["?"] =
xplr.config.general.global_key_bindings.on_key["f1"] xplr.config.general.global_key_bindings.on_key["f1"]
-- The builtin debug error mode. -- The builtin debug error mode.
-- --
@ -2004,9 +2004,9 @@ xplr.config.modes.builtin.number = {
} }
xplr.config.modes.builtin.number.key_bindings.on_key["j"] = xplr.config.modes.builtin.number.key_bindings.on_key["j"] =
xplr.config.modes.builtin.number.key_bindings.on_key["down"] xplr.config.modes.builtin.number.key_bindings.on_key["down"]
xplr.config.modes.builtin.number.key_bindings.on_key["k"] = xplr.config.modes.builtin.number.key_bindings.on_key["k"] =
xplr.config.modes.builtin.number.key_bindings.on_key["up"] xplr.config.modes.builtin.number.key_bindings.on_key["up"]
-- The builtin go to mode. -- The builtin go to mode.
-- --
@ -2490,9 +2490,9 @@ xplr.config.modes.builtin.search = {
} }
xplr.config.modes.builtin.search.key_bindings.on_key["ctrl-n"] = xplr.config.modes.builtin.search.key_bindings.on_key["ctrl-n"] =
xplr.config.modes.builtin.search.key_bindings.on_key["down"] xplr.config.modes.builtin.search.key_bindings.on_key["down"]
xplr.config.modes.builtin.search.key_bindings.on_key["ctrl-p"] = xplr.config.modes.builtin.search.key_bindings.on_key["ctrl-p"] =
xplr.config.modes.builtin.search.key_bindings.on_key["up"] xplr.config.modes.builtin.search.key_bindings.on_key["up"]
-- The builtin filter mode. -- The builtin filter mode.
-- --
@ -3172,7 +3172,7 @@ xplr.fn.builtin.fmt_general_table_row_cols_1 = function(m)
r = r .. "×" r = r .. "×"
else else
local symlink_path = local symlink_path =
xplr.util.shorten(m.symlink.absolute_path, { base = m.parent }) xplr.util.shorten(m.symlink.absolute_path, { base = m.parent })
if m.symlink.is_dir then if m.symlink.is_dir then
symlink_path = symlink_path .. "/" symlink_path = symlink_path .. "/"
end end
@ -3194,14 +3194,14 @@ xplr.fn.builtin.fmt_general_table_row_cols_2 = function(m)
local T = xplr.util.paint("T", { fg = "Red" }) local T = xplr.util.paint("T", { fg = "Red" })
return xplr.util return xplr.util
.permissions_rwx(m.permissions) .permissions_rwx(m.permissions)
:gsub("r", r) :gsub("r", r)
:gsub("w", w) :gsub("w", w)
:gsub("x", x) :gsub("x", x)
:gsub("s", s) :gsub("s", s)
:gsub("S", S) :gsub("S", S)
:gsub("t", t) :gsub("t", t)
:gsub("T", T) :gsub("T", T)
end end
-- Renders the fourth column in the table -- Renders the fourth column in the table

@ -84,6 +84,7 @@ pub struct ContentRendererArg {
pub app: app::LuaContextLight, pub app: app::LuaContextLight,
pub screen_size: Rect, pub screen_size: Rect,
pub layout_size: Rect, pub layout_size: Rect,
pub scrolltop: u16,
} }
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)] #[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
@ -743,7 +744,7 @@ pub fn block<'a>(config: PanelUiConfig, default_title: String) -> Block<'a> {
pub struct UI<'lua> { pub struct UI<'lua> {
pub lua: &'lua Lua, pub lua: &'lua Lua,
pub screen_size: TuiRect, pub screen_size: TuiRect,
pub scrolltop: usize, pub scrolltop: u16,
} }
impl<'lua> UI<'lua> { impl<'lua> UI<'lua> {
@ -764,8 +765,7 @@ impl UI<'_> {
let config = panel_config.default.clone().extend(&panel_config.table); let config = panel_config.default.clone().extend(&panel_config.table);
let app_config = app.config.clone(); let app_config = app.config.clone();
let header_height = app_config.general.table.header.height.unwrap_or(1); let header_height = app_config.general.table.header.height.unwrap_or(1);
let height: usize = let height: usize = layout_size.height.saturating_sub(header_height + 2).into();
(layout_size.height.max(header_height + 2) - (header_height + 2)).into();
let row_style = app_config.general.table.row.style.clone(); let row_style = app_config.general.table.row.style.clone();
let rows = app let rows = app
@ -773,16 +773,17 @@ impl UI<'_> {
.as_ref() .as_ref()
.map(|dir| { .map(|dir| {
// Scroll // Scroll
let padding = app.config.general.scroll_padding;
if app.config.general.paginated_scrolling { if app.config.general.paginated_scrolling {
// Paginated scrolling // Paginated scrolling
self.scrolltop = height * (dir.focus / height.max(1)) self.scrolltop = height * (dir.focus / height.max(1))
} else { } else {
// vim-like-scrolling // Vim-like-scrolling
self.scrolltop = match dir.focus.cmp(&self.scrolltop) { self.scrolltop = match dir.focus.cmp(&self.scrolltop) {
Ordering::Greater => { Ordering::Greater => {
// Scrolling down // Scrolling down
if dir.focus >= self.scrolltop + height { if dir.focus >= self.scrolltop + height {
dir.focus - height + 1 dir.focus.saturating_sub(height + 1)
} else { } else {
self.scrolltop self.scrolltop
} }
@ -792,7 +793,6 @@ impl UI<'_> {
}; };
// Add padding if possible // Add padding if possible
let padding = app.config.general.scroll_padding;
if padding != 0 { if padding != 0 {
if dir.focus < self.scrolltop + padding { if dir.focus < self.scrolltop + padding {
self.scrolltop = dir.focus.saturating_sub(padding); self.scrolltop = dir.focus.saturating_sub(padding);
@ -1326,6 +1326,7 @@ impl UI<'_> {
app: app.to_lua_ctx_light(), app: app.to_lua_ctx_light(),
layout_size: layout_size.into(), layout_size: layout_size.into(),
screen_size: self.screen_size.into(), screen_size: self.screen_size.into(),
scrolltop: self.scrolltop,
}; };
let panel: CustomPanel = lua::serialize(self.lua, &ctx) let panel: CustomPanel = lua::serialize(self.lua, &ctx)

Loading…
Cancel
Save