Skip to content

Add option to apply word wrap per document - #18488

Open
LucaSorvillo wants to merge 2 commits into
notepad-plus-plus:masterfrom
LucaSorvillo:wordWrap_perDocument_20261015
Open

LucaSorvillo wants to merge 2 commits into
notepad-plus-plus:masterfrom
LucaSorvillo:wordWrap_perDocument_20261015

Conversation

@LucaSorvillo

Copy link
Copy Markdown
Contributor

Adds the option "Word wrap applies to the current document only" to Preferences > Editing 1 (unchecked by default). When it is checked:

  • View > Word wrap and its toolbar button wrap or unwrap the current document only (in both views if it is cloned), and the menu check, the toolbar button and the document map follow the current document;
  • each document keeps its own word wrap in its Buffer, saved in session.xml like RTL (<File ... wordWrap="yes|no">). Documents without their own setting follow the global word wrap (Wrap in config.xml), which the command does not change while the option is on;
  • the word wrap is set in ScintillaEditView::activateBuffer() before the position of the document is restored, so the first visible line is kept;
  • with "Deactivate Word Wrap globally" (large file restriction), only the large file is unwrapped instead of all the documents;
  • switching the option on or off takes effect immediately (new internal message NPPM_INTERNAL_WORDWRAPPERDOCUMENT).

About performance (mentioned in the issue): the word wrap of a document is set right after SCI_SETDOCPOINTER, and Editor::SetDocPointer() already calls NeedWrapping() for the new document. SCI_SETWRAPMODE does nothing when the mode does not change; when it changes, it marks the document for re-wrapping (already needed at that point) and refreshes the view style, which does not depend on the document size. So switching tabs costs about the same as with the global word wrap on, and less for the documents that are not wrapped.

Tested on Windows 11 with a Release x64 build of this branch (0 warnings), with an automated GUI test (Win32 messages, separate settings folder):

  • option off (default): View > Word wrap is global as before, no new attribute in session.xml;
  • option on: wrap and unwrap per document; menu, toolbar and document map follow the current document; same first visible line when coming back to a wrapped document; a cloned document is wrapped in both views;
  • restart: the documents get their word wrap back from session.xml in both views (also the ones already shown while the session is loaded), at the same first visible line; documents without their own setting follow the global word wrap;
  • option switched off: both views follow the global word wrap again; the own setting of the documents is kept in session.xml for when the option is switched on again;
  • large file restriction with "Deactivate Word Wrap globally": only the large file is unwrapped, the global setting does not change.

The issue also suggests an entry in the tab context menu: it could be added on top of this, if wanted.

AI disclosure: the code and this description were written with Claude Code (Claude Opus 5.5); the build and the tests above were run on a real Windows 11 machine.

fix #5232

🤖 Generated with Claude Code

@LucaSorvillo LucaSorvillo mentioned this pull request Oct 15, 2026
1 task done
@pryrt

pryrt commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

There's already #18278 submitted weeks ago to do the same thing.

What is better about your AI's solution than the solution already proposed? Or did you have no clue it already existed, and your AI just doesn't bother looking to see if there's already a PR for a given issue.

@LucaSorvillo

Copy link
Copy Markdown
Contributor Author

You're right, sorry: I looked at #5232 but missed #18278 in its timeline. My mistake, not a choice. I have now checked the other PRs I opened today: none of them duplicates an open PR.

The two PRs fix #5232 with a different UI:

  • Add per-document word wrap settings #18278 adds a "Word Wrap" submenu (Use Global Setting / Off / On) to the tab context menu; View > Word wrap and its toolbar button stay global.
  • This one adds an option in Preferences > Editing 1 (off by default): when it is on, View > Word wrap (menu, toolbar button, shortcut) applies to the current document only, and its check mark follows the active document.

So it is not a better solution, just another way to reach the same thing: #18278 is more flexible (three states), this one keeps the usual command. #18278 came first: if the maintainers prefer it, I'll close this one.

LucaSorvillo and others added 2 commits October 19, 2026 15:57
New option in Preferences > Editing 1: "Word wrap applies to the current
document only". When checked, View > Word wrap (and its toolbar button)
wraps or unwraps the current document only. Each document keeps its own
word wrap, also in the session (session.xml "wordWrap" attribute), and a
document without its own setting follows the global word wrap.
The option is off by default.

Fix notepad-plus-plus#5232

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pass the current value as the default of getBoolAttribute when reading
wordWrapPerDocument, as requested in the review of notepad-plus-plus#18485.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LucaSorvillo
LucaSorvillo force-pushed the wordWrap_perDocument_20261015 branch from 86c2aab to caed990 Compare October 19, 2026 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request - word wrap per tab

2 participants