bobbylight / RSyntaxTextArea

A syntax highlighting, code folding text editor for Java Swing applications.
BSD 3-Clause "New" or "Revised" License
1.12k stars 259 forks source link

Fix #541: Line numbers resize when getting a new document #580

Closed bobbylight closed 3 days ago

bobbylight commented 3 days ago

Gutter components should be notified when the Document is updated. Currently they're only notified when a DocumentEvent occurs, but when loading entirely new content via JTextComponent#read(), we create a new RDocument instance and swap it out with the old one for performance reasons.

This PR notifies all Gutter components when a new Document is set on the text area. Currently only LineNumberList does anything - it recalculates its preferred width.

Note: This isn't always reproducible, e.g. it isn't reproducible in RText. It is reproducible in the RSTA demo app if you add > 100 lines to one of the sample language source files, then flip back and forth between it. This triggers a TextEditorPane.load(), which ultimately delegates to JTextComponent.read().