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

Commit b79fe49

Browse files
committed
Fix bobbylight#191: Folds are not expanded when clicking on a marker in the ErrorStrip
1 parent c5aacf3 commit b79fe49

File tree

5 files changed

+146
-12
lines changed

5 files changed

+146
-12
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,13 +867,14 @@ protected void mouseClicked(MouseEvent e) {
867867
int offs = pn.getOffset();
868868
int len = pn.getLength();
869869
if (offs>-1 && len>-1) { // These values are optional
870-
textArea.setSelectionStart(offs);
871-
textArea.setSelectionEnd(offs+len);
870+
DocumentRange range = new DocumentRange(offs, offs + len);
871+
RSyntaxUtilities.selectAndPossiblyCenter(textArea, range, true);
872872
}
873873
else {
874874
int line = pn.getLine();
875875
try {
876876
offs = textArea.getLineStartOffset(line);
877+
textArea.getFoldManager().ensureOffsetNotInClosedFold(offs);
877878
textArea.setCaretPosition(offs);
878879
} catch (BadLocationException ble) { // Never happens
879880
UIManager.getLookAndFeel().provideErrorFeedback(textArea);

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

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ public class RTextArea extends RTextAreaBase implements Printable {
9797
*/
9898
public static final String MARK_ALL_COLOR_PROPERTY = "RTA.markAllColor";
9999

100+
/**
101+
* The property fired when the "mark all on occurrence" property changes.
102+
*/
103+
public static final String MARK_ALL_ON_OCCURRENCE_SEARCHES_PROPERTY =
104+
"RTA.markAllOnOccurrenceSearches";
105+
100106
/**
101107
* The property fired when what ranges are labeled "mark all" changes.
102108
*/
@@ -172,6 +178,8 @@ public class RTextArea extends RTextAreaBase implements Printable {
172178

173179
private SmartHighlightPainter markAllHighlightPainter;
174180

181+
private boolean markAllOnOccurrenceSearches;
182+
175183
private CaretStyle[] carets; // Index 0=>insert caret, 1=>overwrite.
176184

177185
private static final String MSG = "org.fife.ui.rtextarea.RTextArea";
@@ -723,6 +731,19 @@ public static IconGroup getIconGroup() {
723731
}
724732

725733

734+
/**
735+
* Returns whether "mark all" should be enabled when a user does a "find
736+
* next/find previous" action via Ctrl+K or Ctrl+Shift+K (the default
737+
* shortcut keys for this action). The default value is {@code true}.
738+
*
739+
* @return Whether "mark all" should be enabled.
740+
* @see #setMarkAllOnOccurrenceSearches(boolean)
741+
*/
742+
public boolean getMarkAllOnOccurrenceSearches() {
743+
return markAllOnOccurrenceSearches;
744+
}
745+
746+
726747
/**
727748
* Returns the line highlight manager.
728749
*
@@ -850,9 +871,6 @@ protected void handleReplaceSelection(String content) {
850871
}
851872

852873

853-
/**
854-
* {@inheritDoc}
855-
*/
856874
@Override
857875
protected void init() {
858876

@@ -883,6 +901,7 @@ protected void init() {
883901
setDragEnabled(true); // Enable drag-and-drop.
884902

885903
setTextMode(INSERT_MODE); // Carets array must be created first!
904+
setMarkAllOnOccurrenceSearches(true);
886905

887906
// Fix the odd "Ctrl+H <=> Backspace" Java behavior.
888907
fixCtrlH();
@@ -956,9 +975,6 @@ void markAll(List<DocumentRange> ranges) {
956975
}
957976

958977

959-
/**
960-
* {@inheritDoc}
961-
*/
962978
@Override
963979
public void paste() {
964980
// Treat paste operations as atomic, otherwise the removal and
@@ -1492,6 +1508,25 @@ public void setMarkAllHighlightColor(Color color) {
14921508
}
14931509

14941510

1511+
/**
1512+
* Sets whether "mark all" should be enabled when a user does a "find
1513+
* next/find previous" action via Ctrl+K or Ctrl+Shift+K (the default
1514+
* shortcut keys for this action). The default value is {@code true}.<p>
1515+
* This method fires a property change event of type
1516+
* {@link #MARK_ALL_ON_OCCURRENCE_SEARCHES_PROPERTY}.
1517+
*
1518+
* @param markAll Whether "mark all" should be enabled.
1519+
* @see #getMarkAllOnOccurrenceSearches()
1520+
*/
1521+
public void setMarkAllOnOccurrenceSearches(boolean markAll) {
1522+
if (markAll != markAllOnOccurrenceSearches) {
1523+
markAllOnOccurrenceSearches = markAll;
1524+
firePropertyChange(MARK_ALL_ON_OCCURRENCE_SEARCHES_PROPERTY,
1525+
!markAll, markAll);
1526+
}
1527+
}
1528+
1529+
14951530
/**
14961531
* Sets the popup menu used by this text area.<p>
14971532
*
@@ -1510,9 +1545,6 @@ public void setPopupMenu(JPopupMenu popupMenu) {
15101545
}
15111546

15121547

1513-
/**
1514-
* {@inheritDoc}
1515-
*/
15161548
@Override
15171549
public void setRoundedSelectionEdges(boolean rounded) {
15181550
if (getRoundedSelectionEdges()!=rounded) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,9 @@ public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
18741874
}
18751875
}
18761876
SearchContext context = new SearchContext(selectedText);
1877+
if (!textArea.getMarkAllOnOccurrenceSearches()) {
1878+
context.setMarkAll(false);
1879+
}
18771880
if (!SearchEngine.find(textArea, context).wasFound()) {
18781881
UIManager.getLookAndFeel().provideErrorFeedback(textArea);
18791882
}
@@ -2190,6 +2193,9 @@ public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
21902193
}
21912194
}
21922195
SearchContext context = new SearchContext(selectedText);
2196+
if (!textArea.getMarkAllOnOccurrenceSearches()) {
2197+
context.setMarkAll(false);
2198+
}
21932199
context.setSearchForward(false);
21942200
if (!SearchEngine.find(textArea, context).wasFound()) {
21952201
UIManager.getLookAndFeel().provideErrorFeedback(textArea);

src/main/resources/org/fife/ui/rsyntaxtextarea/RSyntaxTextArea_fr.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ Action.CollapseAllFolds.Desc=Comprime tous les plis.
99
Action.CollapseCommentFolds.Name=Comprimer tous les commentaires
1010
Action.CollapseCommentFolds.Mnemonic=C
1111
Action.CollapseCommentFolds.Desc=Comprime tous les plis commentaires.
12-
Action.ExpandAllFolds.Name=D\u00e9comrpimer tous les plis
12+
Action.ExpandAllFolds.Name=D\u00e9comprimer tous les plis
1313
Action.ExpandAllFolds.Mnemonic=E
1414
Action.ExpandAllFolds.Desc=D\u00e9comrpime tous les plis.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package org.fife.ui.rtextarea;
2+
3+
import org.fife.ui.SwingRunner;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
8+
9+
/**
10+
* Unit tests for the {@link RTextArea} class.
11+
*
12+
* @author Robert Futrell
13+
* @version 1.0
14+
*/
15+
@RunWith(SwingRunner.class)
16+
public class RTextAreaTest {
17+
18+
19+
@Test
20+
public void testCanRedo() {
21+
RTextArea textArea = new RTextArea();
22+
Assert.assertFalse(textArea.canRedo());
23+
textArea.replaceSelection("Hi");
24+
Assert.assertFalse(textArea.canRedo());
25+
textArea.undoLastAction();
26+
Assert.assertTrue(textArea.canRedo());
27+
textArea.redoLastAction();
28+
Assert.assertFalse(textArea.canRedo());
29+
}
30+
31+
32+
@Test
33+
public void testCanUndo() {
34+
RTextArea textArea = new RTextArea();
35+
Assert.assertFalse(textArea.canUndo());
36+
textArea.replaceSelection("Hi");
37+
Assert.assertTrue(textArea.canUndo());
38+
textArea.undoLastAction();
39+
Assert.assertFalse(textArea.canUndo());
40+
}
41+
42+
43+
@Test
44+
public void testCreateDefaultModel() {
45+
RTextArea textArea = new RTextArea();
46+
Assert.assertTrue(textArea.createDefaultModel() instanceof RDocument);
47+
}
48+
49+
50+
@Test
51+
public void testDiscardAllEdits() {
52+
RTextArea textArea = new RTextArea();
53+
textArea.replaceSelection("Hi");
54+
Assert.assertTrue(textArea.canUndo());
55+
textArea.discardAllEdits();
56+
Assert.assertFalse(textArea.canUndo());
57+
}
58+
59+
60+
@Test
61+
public void testGetPopupMenu() {
62+
RTextArea textArea = new RTextArea();
63+
Assert.assertNotNull(textArea.getPopupMenu());
64+
}
65+
66+
67+
@Test
68+
public void testRecordingMacro_happyPath() {
69+
Assert.assertFalse(RTextArea.isRecordingMacro());
70+
RTextArea.beginRecordingMacro();
71+
Assert.assertTrue(RTextArea.isRecordingMacro());
72+
RTextArea.endRecordingMacro();
73+
Assert.assertFalse(RTextArea.isRecordingMacro());
74+
}
75+
76+
77+
@Test
78+
public void testRecordingMacro_endWhileNotRecording() {
79+
Assert.assertFalse(RTextArea.isRecordingMacro());
80+
Assert.assertFalse(RTextArea.isRecordingMacro());
81+
RTextArea.endRecordingMacro();
82+
Assert.assertFalse(RTextArea.isRecordingMacro());
83+
}
84+
85+
86+
@Test
87+
public void testMarkAllOnOccurrenceSearches() {
88+
RTextArea textArea = new RTextArea();
89+
Assert.assertTrue(textArea.getMarkAllOnOccurrenceSearches());
90+
textArea.setMarkAllOnOccurrenceSearches(false);
91+
Assert.assertFalse(textArea.getMarkAllOnOccurrenceSearches());
92+
}
93+
94+
95+
}

0 commit comments

Comments
 (0)