Skip to content

Commit 82be3af

Browse files
committed
Fix programmatic text insertion font size
`StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE)` gets the style that is default for all documents where it is not set. What we rather need is the default style for the current document, which is always set (somewhere). This fixes comment/uncomment and template insertion always happening with the font size that the document was opened with.
1 parent 4807255 commit 82be3af

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/main/java/edu/umich/soar/visualsoar/ruleeditor/SoarDocument.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public SoarDocument() {
5151
colorTable = Prefs.getSyntaxColors().clone();
5252

5353
//set font size and style
54-
Style defaultStyle = this.getStyle("default");
54+
Style defaultStyle = this.getStyle(StyleContext.DEFAULT_STYLE);
5555
MutableAttributeSet attributeSet = new SimpleAttributeSet();
5656
StyleConstants.setFontSize(attributeSet, Prefs.editorFontSize.getInt());
5757
defaultStyle.addAttributes(attributeSet);
@@ -63,13 +63,12 @@ public void setFontSize(int size) {
6363
SoarDocument.fontSize = size;
6464

6565
// Create or update a style for the font size
66-
StyleContext context = StyleContext.getDefaultStyleContext();
67-
Style fontStyle = context.getStyle(StyleContext.DEFAULT_STYLE);
66+
Style defaultStyle = getStyle(StyleContext.DEFAULT_STYLE);
6867

69-
// Update the font size in the style
68+
// Update the font size in the default style
7069
MutableAttributeSet attributeSet = new SimpleAttributeSet();
7170
StyleConstants.setFontSize(attributeSet, size);
72-
fontStyle.addAttributes(attributeSet);
71+
defaultStyle.addAttributes(attributeSet);
7372

7473
// Apply the updated style to the entire document
7574
SwingUtilities.invokeLater(() -> {

0 commit comments

Comments
 (0)