Add an option to dynamic-break inside words
ClosedPublic

Authored by eudoxos on Feb 8 2020, 11:42 AM.

Details

Summary

Add option to break lines longer than view width (or static boundary, when dynamic-wrapping at static boundary) anywhere. It merely sets QTextOption::WrapAnywhere for the view, plus exposes that as checkbox in the config and key for saving the configuration.

QTextOption::WrapAtWordBoundaryOrAnywhere is unfortunately very dumb, splitting at space only; while this might be ok for natural languages, it is not suitable for code: e.g. if(eng->option.wrapMode()==QTextOption::WrapAtWordBoundaryOrAnywhere){ has no "word boundary" according the the algorithm. FYI QTtextLayout internally uses QTextEngine::itemize() [https://code.qt.io/cgit/qt/qtbase.git/tree/src/gui/text/qtextengine.cpp?h=dev#n2057](link).

This patch makes a difference also for long lines "without word boundary" which should break anywhere as fallback (as per Qt's docs); in this fallback case, though ktextedit inserts zero-length line at the beginning (this is likely an existing but in ktextedit).

Without breaking anywhere (old behavior, the default):

breaking anywhere:

(My first contribution here.)

Diff Detail

Repository
R39 KTextEditor
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
eudoxos created this revision.Feb 8 2020, 11:42 AM
Restricted Application added projects: Kate, Frameworks. · View Herald TranscriptFeb 8 2020, 11:42 AM
Restricted Application added subscribers: kde-frameworks-devel, kwrite-devel. · View Herald Transcript
eudoxos requested review of this revision.Feb 8 2020, 11:42 AM

A complementary (also related to dynamic wrapping) change is tracked under D27285.

cullmann requested changes to this revision.Feb 11 2020, 9:46 AM

I am ok with this.
Thought I would like to have a more consistent name for the config key.
We have already "dynamic-word-wrap", I would like "dynamic-word-wrap-anywhere" better than the abbreviated "dyn-wrap-anywhere"

This revision now requires changes to proceed.Feb 11 2020, 9:46 AM
eudoxos added a comment.EditedFeb 11 2020, 10:08 PM

I am ok with this.
Thought I would like to have a more consistent name for the config key.
We have already "dynamic-word-wrap", I would like "dynamic-word-wrap-anywhere" better than the abbreviated "dyn-wrap-anywhere"

No problem. While I am at fixing that, would not "dynamic-wrap", "dynamic-wrap-anywhere", ... fit better? It is lines which are wrapped after all, not words. (The menu is also "View / Word Wrap"). There might be more options with this prefix later (working on that) and it will be harder to change.

Hmm, not sure.
Given we have everywhere at the moment the dynamic/static word wrap wording, I would rather stick with that.

for me the menu reads "View -> Word Wrap -> Dynamic Word Wrap", too.

eudoxos updated this revision to Diff 75509.EditedFeb 12 2020, 5:38 AM

Changed config key to dynamic-word-wrap-anywhere as suggested by @cullmann .

cullmann accepted this revision.Feb 12 2020, 8:03 AM

Ok, happy with that, thanks!

This revision is now accepted and ready to land.Feb 12 2020, 8:03 AM
This revision was automatically updated to reflect the committed changes.