refactor: simplify the code

This commit is contained in:
sxyazi
2025-02-21 18:47:47 +08:00
parent 781a798464
commit 5186af7984
2 changed files with 33 additions and 14 deletions

View File

@@ -23,6 +23,7 @@ ya pack -a yazi-rs/plugins:toggle-pane
Hide/Show preview: Hide/Show preview:
```toml ```toml
# keymap.toml
[[manager.prepend_keymap]] [[manager.prepend_keymap]]
on = "T" on = "T"
run = "plugin toggle-pane min-preview" run = "plugin toggle-pane min-preview"
@@ -32,6 +33,7 @@ desc = "Show or hide the preview pane"
Maximize/Restore preview: Maximize/Restore preview:
```toml ```toml
# keymap.toml
[[manager.prepend_keymap]] [[manager.prepend_keymap]]
on = "T" on = "T"
run = "plugin toggle-pane max-preview" run = "plugin toggle-pane max-preview"
@@ -52,6 +54,25 @@ end
In the example above, when it detects that you're [using Yazi in nvim](https://yazi-rs.github.io/docs/resources#vim), the preview is hidden by default — you can always press `T` (or any key you've bound) to show it again. In the example above, when it detects that you're [using Yazi in nvim](https://yazi-rs.github.io/docs/resources#vim), the preview is hidden by default — you can always press `T` (or any key you've bound) to show it again.
## Tips
This plugin only maximizes the "available preview area", without actually changing the content size.
This means that the appearance of your preview largely depends on the previewer you are using.
However, most previewers tend to make the most of the available space, so this usually isn't an issue.
For image previews, you may want to tune up the [`max_width`][max-width] and [`max_height`][max-height] options in your `yazi.toml`:
```toml
[preview]
# Change them to your desired values
max_width = 1000
max_height = 1000
```
[max-width]: https://yazi-rs.github.io/docs/configuration/yazi/#preview.max_width
[max-height]: https://yazi-rs.github.io/docs/configuration/yazi/#preview.max_height
## License ## License
This plugin is MIT-licensed. For more information, check the [LICENSE](LICENSE) file. This plugin is MIT-licensed. For more information, check the [LICENSE](LICENSE) file.

View File

@@ -3,23 +3,21 @@
local function entry(st, job) local function entry(st, job)
local R = MANAGER.ratio local R = MANAGER.ratio
job = type(job) == "string" and { args = { job } } or job
st.parent = st.parent and st.parent or R.parent st.parent = st.parent and st.parent or R.parent
st.current = st.current and st.current or R.current st.current = st.current and st.current or R.current
st.preview = st.preview and st.preview or R.preview st.preview = st.preview and st.preview or R.preview
local act = type(job) == "string" and job or job.args[1] local act, to = string.match(job.args[1] or "", "(.-)-(.+)")
if act == "min-parent" then if act == "min" then
st.parent = st.parent == R.parent and 0 or R.parent st[to] = st[to] == R[to] and 0 or R[to]
elseif act == "min-current" then elseif act == "max" then
st.current = st.current == R.current and 0 or R.current local max = st[to] == 65535 and R[to] or 65535
elseif act == "min-preview" then st.parent = st.parent == 65535 and R.parent or st.parent
st.preview = st.preview == R.preview and 0 or R.preview st.current = st.current == 65535 and R.current or st.current
elseif act == "max-parent" then st.preview = st.preview == 65535 and R.preview or st.preview
st.parent = st.parent == 65535 and R.parent or 65535 st[to] = max
elseif act == "max-current" then
st.current = st.current == 65535 and R.current or 65535
elseif act == "max-preview" then
st.preview = st.preview == 65535 and R.preview or 65535
end end
if not st.old then if not st.old then
@@ -37,7 +35,7 @@ local function entry(st, job)
end end
end end
if act == "reset" then if not act then
Tab.layout, st.old = st.old, nil Tab.layout, st.old = st.old, nil
st.parent, st.current, st.preview = nil, nil, nil st.parent, st.current, st.preview = nil, nil, nil
end end