Skip to content
This repository was archived by the owner on Aug 10, 2022. It is now read-only.

Commit 91720e4

Browse files
committed
Fix bobbylight#195: Repaint gutter if necessary when ensuring an offset is not in a closed fold
1 parent b79fe49 commit 91720e4

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

src/main/java/org/fife/ui/rsyntaxtextarea/RSyntaxTextAreaEditorKit.java

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.fife.ui.rsyntaxtextarea.folding.FoldCollapser;
3232
import org.fife.ui.rsyntaxtextarea.folding.FoldManager;
3333
import org.fife.ui.rsyntaxtextarea.templates.CodeTemplate;
34-
import org.fife.ui.rtextarea.Gutter;
3534
import org.fife.ui.rtextarea.IconRowHeader;
3635
import org.fife.ui.rtextarea.RTextArea;
3736
import org.fife.ui.rtextarea.RTextAreaEditorKit;
@@ -286,7 +285,7 @@ public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
286285
if (fold!=null) {
287286
fold.setCollapsed(collapse);
288287
}
289-
possiblyRepaintGutter(textArea);
288+
RSyntaxUtilities.possiblyRepaintGutter(textArea);
290289
}
291290
else {
292291
UIManager.getLookAndFeel().provideErrorFeedback(rsta);
@@ -560,7 +559,7 @@ public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
560559
if (rsta.isCodeFoldingEnabled()) {
561560
FoldCollapser collapser = new FoldCollapser();
562561
collapser.collapseFolds(rsta.getFoldManager());
563-
possiblyRepaintGutter(textArea);
562+
RSyntaxUtilities.possiblyRepaintGutter(textArea);
564563
}
565564
else {
566565
UIManager.getLookAndFeel().provideErrorFeedback(rsta);
@@ -609,7 +608,7 @@ public boolean getShouldCollapse(Fold fold) {
609608
}
610609
};
611610
collapser.collapseFolds(rsta.getFoldManager());
612-
possiblyRepaintGutter(textArea);
611+
RSyntaxUtilities.possiblyRepaintGutter(textArea);
613612
}
614613
else {
615614
UIManager.getLookAndFeel().provideErrorFeedback(rsta);
@@ -1197,7 +1196,7 @@ public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
11971196
for (int i=0; i<fm.getFoldCount(); i++) {
11981197
expand(fm.getFold(i));
11991198
}
1200-
possiblyRepaintGutter(rsta);
1199+
RSyntaxUtilities.possiblyRepaintGutter(rsta);
12011200
}
12021201
else {
12031202
UIManager.getLookAndFeel().provideErrorFeedback(rsta);
@@ -1244,18 +1243,6 @@ protected Fold getClosestFold(RSyntaxTextArea textArea) {
12441243
return fold;
12451244
}
12461245

1247-
/**
1248-
* Repaints the gutter in a text area's scroll pane, if necessary.
1249-
*
1250-
* @param textArea The text area.
1251-
*/
1252-
protected void possiblyRepaintGutter(RTextArea textArea) {
1253-
Gutter gutter = RSyntaxUtilities.getGutter(textArea);
1254-
if (gutter!=null) {
1255-
gutter.repaint();
1256-
}
1257-
}
1258-
12591246
}
12601247

12611248

@@ -2104,7 +2091,7 @@ public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
21042091
if (fold!=null) {
21052092
fold.toggleCollapsedState();
21062093
}
2107-
possiblyRepaintGutter(textArea);
2094+
RSyntaxUtilities.possiblyRepaintGutter(textArea);
21082095
}
21092096
else {
21102097
UIManager.getLookAndFeel().provideErrorFeedback(rsta);

src/main/java/org/fife/ui/rsyntaxtextarea/RSyntaxUtilities.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,19 @@ public static boolean isWhitespace(char ch) {
13361336
}
13371337

13381338

1339+
/**
1340+
* Repaints the gutter in a text area's scroll pane, if necessary.
1341+
*
1342+
* @param textArea The text area.
1343+
*/
1344+
public static void possiblyRepaintGutter(RTextArea textArea) {
1345+
Gutter gutter = RSyntaxUtilities.getGutter(textArea);
1346+
if (gutter!=null) {
1347+
gutter.repaint();
1348+
}
1349+
}
1350+
1351+
13391352
/**
13401353
* Returns whether a regular expression token can follow the specified
13411354
* token in JavaScript.

src/main/java/org/fife/ui/rsyntaxtextarea/folding/DefaultFoldManager.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.ArrayList;
1313
import java.util.Collections;
1414
import java.util.List;
15+
1516
import javax.swing.event.DocumentEvent;
1617
import javax.swing.event.DocumentListener;
1718
import javax.swing.text.BadLocationException;
@@ -20,6 +21,7 @@
2021

2122
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument;
2223
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
24+
import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities;
2325
import org.fife.ui.rsyntaxtextarea.parser.AbstractParser;
2426
import org.fife.ui.rsyntaxtextarea.parser.DefaultParseResult;
2527
import org.fife.ui.rsyntaxtextarea.parser.ParseResult;
@@ -87,16 +89,24 @@ public void clear() {
8789

8890
@Override
8991
public boolean ensureOffsetNotInClosedFold(int offs) {
92+
9093
boolean foldsOpened = false;
9194
Fold fold = getDeepestFoldContaining(offs);
95+
9296
while (fold!=null) {
9397
if (fold.isCollapsed()) {
9498
fold.setCollapsed(false);
9599
foldsOpened = true;
96100
}
97101
fold = fold.getParent();
98102
}
103+
104+
if (foldsOpened) { // Folds changing state mean gutter is stale
105+
RSyntaxUtilities.possiblyRepaintGutter(textArea);
106+
}
107+
99108
return foldsOpened;
109+
100110
}
101111

102112

src/main/java/org/fife/ui/rtextarea/SearchEngine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static SearchResult find(JTextArea textArea, SearchContext context) {
7676
if (doMarkAll) {
7777
// Force "mark all" event to be broadcast so listeners know to
7878
// clear their mark-all markers. The RSTA already cleared its
79-
// highlights above, but cleraMarkAllHighlights() doesn't firs
79+
// highlights above, but cleraMarkAllHighlights() doesn't fire
8080
// an event itself for performance reasons.
8181
List<DocumentRange> emptyRangeList = Collections.emptyList();
8282
((RTextArea)textArea).markAll(emptyRangeList);

0 commit comments

Comments
 (0)