Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soft Line Wrapping #636

Merged
merged 16 commits into from
Mar 24, 2022
Merged

Conversation

adamharrison
Copy link
Member

@adamharrison adamharrison commented Oct 26, 2021

An ongoing PR where implementing soft line wrapping.

I've managed to implement it as a plugin; I think that's probably the best place to put it, as it's not really core to the editor; but it is a very common ask. (#326, #36, numerous times on discord, etc..)

The only changes I've made to the core (beyond the plugin), are making things a bit clearer in the DocView by renaming idx to line where appropriate, and ensuring that the various draw_line functions return the height of the line they're drawing (as with this plugin, a variable line height is possible). This will have to be paired with plugin changes, as several plugins override these functions, so this should be paired with a mod-version bump, and upgrading these plugins to support that kind of change if we want to merge this.

Currently the plugin is semi-functional, but is incredibly verbose and needlessly repetitive, and highly inefficient. I'll be refining it over the coming days to get it up to snuff; hopefully cutting down the size and complexity significantly and having it incrementally compute the linebreaks, rather than recomputing the entire document on every keystroke.

Example here:

example.mp4

:

@adamharrison adamharrison marked this pull request as draft October 26, 2021 19:42
@aqilc
Copy link
Contributor

aqilc commented Oct 26, 2021

Adam = god 🙏🏼

@adamharrison adamharrison marked this pull request as ready for review October 27, 2021 03:24
@adamharrison
Copy link
Member Author

OK; I think this is good to go, or at least, ready for testing by people that are interested.

I'm sure there are bugs. And it's still pretty beefy; I feel like I could still pare this down a lot. And I need to implement the "word" mode, but this should be 'good'.

@adamharrison
Copy link
Member Author

OK, I'm decently happy with this.

Obviously this is a bigger change than just the plugin (minor changes to the docview API); and it is being proposed as a core plguin, so I'll leave this up for discussion for a while.

@vincens2005
Copy link
Contributor

this is such a heavily requested feature I think it's worth it

@adamharrison
Copy link
Member Author

Should close #36 .

@adamharrison adamharrison mentioned this pull request Nov 23, 2021
@adamharrison
Copy link
Member Author

Should close #585 .

@adamharrison
Copy link
Member Author

OK; I think this is now ready for testing. It seems to reliably work at this point for me. The only thing a little broken is some of the plugins I'm using.

@adamharrison adamharrison changed the base branch from master to master-2.1 March 24, 2022 15:59
@adamharrison adamharrison merged commit a8b97df into lite-xl:master-2.1 Mar 24, 2022
adamharrison added a commit that referenced this pull request Apr 3, 2022
Added in soft line wrapping.
adamharrison added a commit to adamharrison/lite-xl that referenced this pull request Apr 22, 2022
Added in soft line wrapping.
@dajare
Copy link

dajare commented Sep 25, 2022

I have just "discovered" Lite XL, and am very impressed. Immediately I looked for "linewrap" :/

I have installed the latest "release" available (= 2.0.5 as I type), but it looks like this is going out in a 2.1 release. Can I try the linewrapping.lua plugin in my version? Or do I simply wait patiently for 2.1 to be released?

Thanks! This looks very promising!

@Guldoman
Copy link
Member

Sadly no, the linewrapping plugin needs the new API available in 2.1, so it won't work on 2.0.5.

@dajare
Copy link

dajare commented Sep 25, 2022

Sadly no, the linewrapping plugin needs the new API available in 2.1, so it won't work on 2.0.5.

Thanks for the reply. I'm looking forward to the 2.1 release with keen anticipation! 😉

@adamharrison
Copy link
Member Author

Sadly no, the linewrapping plugin needs the new API available in 2.1, so it won't work on 2.0.5.

Thanks for the reply. I'm looking forward to the 2.1 release with keen anticipation! 😉

You can download a preview release here for Linux and Windows: https://github.com/adamharrison/lite-xl-simplified/releases/tag/continuous if you want to try it out.

@humanplayer2
Copy link

humanplayer2 commented Sep 28, 2022

@adamharrison ,
This is marvelous, thank you!

I have two observations:

  • Line wrapping may occur mid-string, not at spaces. I think it would be nice if strong preference was given to wrapping at spaces.
  • The wrapping position is not updated when the window text is zoomed using Ctrl+mousewheel-scroll.

Edit: PS I'm on your Lite XL Simplified, downloaded yesterday.

@dajare
Copy link

dajare commented Sep 28, 2022

You can download a preview release here for Linux and Windows: https://github.com/adamharrison/lite-xl-simplified/releases/tag/continuous if you want to try it out.

Thanks - I did! And it's great to see this feature being implemented. My take tallies exactly with @humanplayer2 in the comment above this one. I generally use a "lite" editor for long-form writing (typically, but not always, markdown), so having "soft line-wrap" is almost essential for me.

This is very much a step in the right/write ;) direction, though. The speed of Lite-XL is really impressive!

@adamharrison
Copy link
Member Author

adamharrison commented Sep 28, 2022

@adamharrison ,
This is marvelous, thank you!

I have two observations:

Line wrapping may occur mid-string, not at spaces. I think it would be nice if strong preference was given to wrapping at spaces.

@humanplayer2 This is actually configurable, in you user plugin, you can set config.plugins.linewrapping.mode = "word", and that should wrap at a space boundary, if it can.

The wrapping position is not updated when the window text is zoomed using Ctrl+mousewheel-scroll.

Ah, good call. I'll open an issue.

Edit: PS I'm on your Lite XL Simplified, downloaded yesterday.

Awesome, glad to hear it.

Thanks - I did! And it's great to see this feature being implemented. My take tallies exactly with @humanplayer2 in the comment above this one. I generally use a "lite" editor for long-form writing (typically, but not always, markdown), so having "soft line-wrap" is almost essential for me.

@dajare Awesome; you may be interested as well in https://github.com/adamharrison/write-xl; it doesn't have any releases, but I can just add some CI to it; I also do some long-form creative writing in markdown, and I compiled it onto my tablet so I can take it with me in cafés and stuff. It's not perfect or anything, but I like it a lot more than google docs and whatnot for my purposes; might fit your needs as well.

@dajare
Copy link

dajare commented Sep 28, 2022

...you can set config.plugins.linewrapping.mode = "word", and that should wrap at a space boundary, if it can.

@adamharrison : Genius! This just gets better and better. :) Works a treat.

...you may be interested as well in...

Write-XL looks super, too! I don't have any Android use for it (I only have an old Nokia phone, no tablet). But I'll be firing up Lite-XL on Ubuntu regularly, I imagine. I also have Typora that I use for yet more serious "long-form" writing in Markdown (with footnotes, etc.), and it meets my needs pretty well.

@beastehg
Copy link

when i use it pres F10 i take this bug all the time
https://i.imgur.com/CKvu6uO.png

@Guldoman
Copy link
Member

Sadly line wrapping isn't compatible with every plugin yet, so try disabling some to find the culprit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants