Open mskvsk opened 1 month ago
Also, I have never written any Rust but can give it a shot if @sxyazi deems this feature good to have.
We can also downscale the scope of this feature to a single boolean (wordwrap = true/false) in the config if it seems an overkill.
All I need is my text files to word wrap as I use text preview on them daily.
Nice to have!
Would you like to raise a PR for it? Here is the method that handles code highlighting: https://github.com/sxyazi/yazi/blob/9df256f7f4abc312ae94b59c948502310ecb2c87/yazi-plugin/src/external/highlighter.rs#L59
Maybe we can change its function signature to:
pub async fn highlight(&self, skip: usize, area: Rect, wrap: bool) -> Result<Text<'static>, PeekError> {
And handle text wrapping when wrap = true
.
Sure, will do. I'm half-way through the solution already.
If anyone is interested in implementing it, https://github.com/sxyazi/yazi/pull/1142 would be a great starting point.
I might also add that I am ready to pay a small bounty of $50 in crypto (USDC/USDT) to anyone who solves this issue without using an external crate (I don't mind if you copypaste the solution from the crate I have used in my PR).
This feature is quite nice to have to me, as I use Yazi to browse a lot of personal content that is stored as separate text files which don't look good without wrapping.
Hello @mskvsk, I tried to solve this problem in #1159. Your previous commits helped me a bit, so thanks for that! You can try and build my solution, check it out on your use cases, maybe you will find some bugs. Feel free to comment and review my code!
I found an issue with files that are handled by plugins, like json
, toml
etc. They use preview_widgets
, not preview_code
function. But file.lua
plugin has word wrapping functionality in it, handled by Lua. Should Rust application handle the word wrapping or this is responsibility of plugins?
Thank you, I tried it out and have left some comments!
Thanks for the PR @ArtyomArtamonov! I'll review it ASAP
Please describe the problem you're trying to solve
Word wrapping in preview has been a pretty contentious issue in the discussions of at least two terminal file managers. Some people like to scroll it, some people prefer it to word wrap.
Personally, I would like some of my documents to word wrap, while the others and code to not to.
I suspect, many people have their own expectations around that which I will try to address in the solution.
Would you be willing to contribute this feature?
Describe the solution you'd like
An optional "wrap" field in the previewers array in yazi.toml
True for word wrapping, false for long lines. The default is false. Ignored if the active preview is not wrappable.
Example:
Additional context
No response