Skip to content

Commit a48d923

Browse files
committed
Fix wonky scrolling
Update RegExPlus dependency due to bug in Java 9 and above (new version fixes this)
1 parent 6ff6c97 commit a48d923

File tree

5 files changed

+40
-30
lines changed

5 files changed

+40
-30
lines changed

BEXCodeCompare/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<dependency>
2323
<groupId>info.codesaway</groupId>
2424
<artifactId>regexplus</artifactId>
25-
<version>1.2.0</version>
25+
<version>2.0.0</version>
2626
</dependency>
2727
<dependency>
2828
<groupId>com.github.spotbugs</groupId>

BEXCodeCompare/src/main/java/info/codesaway/bex/matching/BEXMatchingLanguage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public enum BEXMatchingLanguage implements MatchingLanguage {
2929
* SQL Matching language
3030
* @since 0.11
3131
*/
32-
SQL(BEXMatchingUtilities::parseSQLTextStates, "@", true, bexPair("BEGIN", "END")),
32+
SQL(BEXMatchingUtilities::parseSQLTextStates, "@#$", true, bexPair("BEGIN", "END")),
3333

3434
// End of enum
3535
;
@@ -92,11 +92,11 @@ public MatchingDelimiterState findEndDelimiter(final BEXPair<String> lastDelimit
9292

9393
BiPredicate<String, String> equals = this.hasCaseInsensitiveDelimiters
9494
? String::equalsIgnoreCase
95-
: String::equals;
95+
: String::equals;
9696

9797
MatchingDelimiterResult result = lastDelimiter != null && equals.test(s, lastDelimiter.getRight())
9898
? MatchingDelimiterResult.FOUND
99-
: MatchingDelimiterResult.MISMATCHED;
99+
: MatchingDelimiterResult.MISMATCHED;
100100

101101
return new MatchingDelimiterState(result, s);
102102
}

BEXCodeCompare/src/test/java/info/codesaway/bex/matching/BEXParseSQLTest.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ void testNestedBlockComments() {
4545
BEXString bexString = new BEXString(text, BEXMatchingLanguage.SQL);
4646

4747
assertThat(bexString.getTextStateMap().asMapOfRanges())
48-
.containsExactly(
49-
entry(closedOpen(2, 11), IN_MULTILINE_COMMENT),
50-
entry(closed(11, 21), IN_MULTILINE_COMMENT),
51-
entry(closed(22, 51), IN_MULTILINE_COMMENT));
48+
.containsExactly(
49+
entry(closedOpen(2, 11), IN_MULTILINE_COMMENT),
50+
entry(closed(11, 21), IN_MULTILINE_COMMENT),
51+
entry(closed(22, 51), IN_MULTILINE_COMMENT));
5252

5353
assertThat(bexString.substring(closed(11, 21))).asString()
54-
.isEqualTo("/*\r\n" +
55-
"def\r\n" +
56-
"*/");
54+
.isEqualTo("/*\r\n" +
55+
"def\r\n" +
56+
"*/");
5757
}
5858

5959
@Test
@@ -62,7 +62,7 @@ void testLineComment() {
6262
BEXString bexString = new BEXString(text, BEXMatchingLanguage.SQL);
6363

6464
assertThat(bexString.getTextStateMap().asMapOfRanges())
65-
.containsExactly(entry(closedOpen(2, text.length()), IN_LINE_COMMENT));
65+
.containsExactly(entry(closedOpen(2, text.length()), IN_LINE_COMMENT));
6666
}
6767

6868
@Test
@@ -71,7 +71,7 @@ void testSingleQuoteEscape() {
7171
BEXString bexString = new BEXString(text, BEXMatchingLanguage.SQL);
7272

7373
assertThat(bexString.getTextStateMap().asMapOfRanges())
74-
.containsExactly(entry(closed(0, text.length() - 1), IN_STRING_LITERAL));
74+
.containsExactly(entry(closed(0, text.length() - 1), IN_STRING_LITERAL));
7575
}
7676

7777
@Test
@@ -80,7 +80,7 @@ void testBackslashDoesNotEscapeSingleQuote() {
8080
BEXString bexString = new BEXString(text, BEXMatchingLanguage.SQL);
8181

8282
assertThat(bexString.getTextStateMap().asMapOfRanges())
83-
.containsExactly(entry(closed(7, 13), IN_STRING_LITERAL));
83+
.containsExactly(entry(closed(7, 13), IN_STRING_LITERAL));
8484
}
8585

8686
@Test
@@ -133,7 +133,7 @@ void testTrailingBeginDoesNotMatch() {
133133
}
134134

135135
@Test
136-
void testVariableNamedBeginMatches() {
136+
void testVariableNameBeginMatches() {
137137
String pattern = ":[value]";
138138
String text = "@BEGIN";
139139

@@ -142,7 +142,7 @@ void testVariableNamedBeginMatches() {
142142
}
143143

144144
@Test
145-
void testVariableNamedContainingBeginMatches() {
145+
void testVariableNameContainingBeginMatches() {
146146
String pattern = ":[value]";
147147
String text = "@lets_begin";
148148

@@ -159,7 +159,7 @@ void testTrailingEndDoesNotMatch() {
159159
}
160160

161161
@Test
162-
void testVariableNamedEndMatches() {
162+
void testVariableNameEndMatches() {
163163
String pattern = ":[value]";
164164
String text = "@end";
165165

@@ -168,11 +168,21 @@ void testVariableNamedEndMatches() {
168168
}
169169

170170
@Test
171-
void testVariableNamedContainingEndMatches() {
171+
void testVariableNameContainingEndMatches() {
172172
String pattern = ":[value]";
173173
String text = "@the_end";
174174

175175
BEXMatcher bexMatcher = testJustBEXMatch(pattern, text, BEXMatchingLanguage.SQL);
176176
assertThat(bexMatcher.group("value")).isEqualTo("@the_end");
177177
}
178+
179+
// Issue #89
180+
@Test
181+
void testTableNameContainingEndMatches() {
182+
String pattern = ":[value]";
183+
String text = "#end";
184+
185+
BEXMatcher bexMatcher = testJustBEXMatch(pattern, text, BEXMatchingLanguage.SQL);
186+
assertThat(bexMatcher.group("value")).isEqualTo("#end");
187+
}
178188
}

BEXCodeComparePlugin/src/info/codesaway/bex/views/BEXView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ private void setChanges(final List<DiffChange<BEXChangeInfo>> changes) {
354354
List<TreeParent> expandedElements = new ArrayList<>();
355355

356356
boolean shouldShowBothSidesOfSubstitution = Activator.shouldShowBothSidesOfSubstitution();
357-
System.out.println("In BEXView.setChanges");
357+
// System.out.println("In BEXView.setChanges");
358358

359359
for (DiffChange<BEXChangeInfo> change : changes) {
360360
TreeParent changeParent = new TreeParent(change.toString());

BEXCodeComparePlugin/src/info/codesaway/eclipse/compare/contentmergeviewer/TextMergeViewer.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
import org.eclipse.jface.text.IRewriteTarget;
124124
import org.eclipse.jface.text.ITextPresentationListener;
125125
import org.eclipse.jface.text.ITextViewer;
126+
import org.eclipse.jface.text.JFaceTextUtil;
126127
import org.eclipse.jface.text.Position;
127128
import org.eclipse.jface.text.Region;
128129
import org.eclipse.jface.text.TextPresentation;
@@ -6152,7 +6153,6 @@ private void updateStructure(final char leg) {
61526153

61536154
public void scroll(final int leftLineNumber, final int rightLineNumber) {
61546155
char contributor;
6155-
// boolean isLeft;
61566156
int line;
61576157
MergeSourceViewer mergeSourceViewer;
61586158

@@ -6177,12 +6177,17 @@ public void scroll(final int leftLineNumber, final int rightLineNumber) {
61776177
Position position = new Position(offset);
61786178

61796179
// Issue #18
6180-
// TODO: when does this, still shows green background (should it?)
6181-
// (when I perform an actual mouse click, it doesn't show the background)
6182-
Diff diff = this.findDiff(contributor, offset);
6180+
// First, check if the specified line is already visible
6181+
// (based on logic in TextViewer.internalRevealRange)
6182+
StyledText text = mergeSourceViewer.getSourceViewer().getTextWidget();
6183+
int top = text.getTopIndex();
6184+
int bottom = JFaceTextUtil.getBottomIndex(text);
6185+
boolean isVisible = line >= top && line <= bottom;
61836186

6184-
// System.out.println("Scroll to " + offset + "\t" + diff);
6185-
this.setCurrentDiff(diff, true);
6187+
if (!isVisible) {
6188+
Diff diff = this.fMerger.findDiff(contributor, position);
6189+
this.setCurrentDiff(diff, true);
6190+
}
61866191

61876192
if (leftLineNumber != -1 && rightLineNumber != -1) {
61886193
// Subtract 1 to make 0-based line
@@ -6201,10 +6206,5 @@ public void scroll(final int leftLineNumber, final int rightLineNumber) {
62016206
}
62026207

62036208
mergeSourceViewer.setSelection(position);
6204-
6205-
// TODO: does this help Issue #18 at all?
6206-
this.updatePresentation();
6207-
6208-
// this.revealDiff(diff, true);
62096209
}
62106210
}

0 commit comments

Comments
 (0)