Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2022-01-02 18:47:09 +0000
committerThomas Wolf2022-01-14 12:06:21 +0000
commit19d29ce7bcfd4793649398e414de200c4d607ef6 (patch)
tree943bc9e8c8c17d92622095360f92d6ef3d19212a
parent58fbfc9fd2266016e490fd06a2c975017966e2d7 (diff)
downloadeclipse.platform.text-19d29ce7bcfd4793649398e414de200c4d607ef6.tar.gz
eclipse.platform.text-19d29ce7bcfd4793649398e414de200c4d607ef6.tar.xz
eclipse.platform.text-19d29ce7bcfd4793649398e414de200c4d607ef6.zip
Bug 578018 - Regex content assist: fix backslash counting
In addBsProposal(), only omit the backslash if there is an odd number of backslashes before the insertion point. 'fIsEscape' already contains this information. Change-Id: I2dcb86cc52d89652e371446a1734b89801d2ecad Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch> Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.text/+/189224 Tested-by: Platform Bot <platform-bot@eclipse.org> Reviewed-by: Karsten Thoms <karsten.thoms@karakun.com>
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/FindReplaceDocumentAdapterContentProposalProviderTest.java60
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/JFaceTextTestSuite.java3
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/FindReplaceDocumentAdapterContentProposalProvider.java14
3 files changed, 65 insertions, 12 deletions
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/FindReplaceDocumentAdapterContentProposalProviderTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/FindReplaceDocumentAdapterContentProposalProviderTest.java
new file mode 100644
index 00000000000..3046512de64
--- /dev/null
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/FindReplaceDocumentAdapterContentProposalProviderTest.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2022 Thomas Wolf <thomas.wolf@paranor.ch> and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************/
+package org.eclipse.jface.text.tests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+import org.eclipse.jface.fieldassist.IContentProposal;
+
+import org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider;
+
+public class FindReplaceDocumentAdapterContentProposalProviderTest {
+
+ private FindReplaceDocumentAdapterContentProposalProvider provider= new FindReplaceDocumentAdapterContentProposalProvider(true);
+
+ private void assertProposal(IContentProposal[] proposals, String prefix, String replacement) {
+ IContentProposal match= null;
+ for (IContentProposal p : proposals) {
+ if (p.getLabel().startsWith(prefix)) {
+ match= p;
+ break;
+ }
+ }
+ assertNotNull("No proposal for " + prefix + " found", match);
+ assertEquals("Unexpected replacement", replacement, match.getContent());
+ }
+
+ @Test
+ public void testEmptyTextProposal() {
+ assertProposal(provider.getProposals("", 0), "\\r", "\\r");
+ }
+
+ @Test
+ public void testNonEmptyProposal() {
+ assertProposal(provider.getProposals("text", 3), "\\r", "\\r");
+ }
+
+ @Test
+ public void testBackslashOddProposal() {
+ assertProposal(provider.getProposals("te\\xt", 3), "\\r", "r");
+ assertProposal(provider.getProposals("te\\\\\\xt", 5), "\\r", "r");
+ }
+
+ @Test
+ public void testBackslashEvenProposal() {
+ assertProposal(provider.getProposals("te\\\\xt", 4), "\\r", "\\r");
+ assertProposal(provider.getProposals("te\\\\\\xt", 4), "\\r", "\\r");
+ assertProposal(provider.getProposals("te\\\\\\\\xt", 6), "\\r", "\\r");
+ }
+}
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/JFaceTextTestSuite.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/JFaceTextTestSuite.java
index 011bf026dd1..9668ad7342d 100644
--- a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/JFaceTextTestSuite.java
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/JFaceTextTestSuite.java
@@ -74,7 +74,8 @@ import org.eclipse.jface.text.tests.templates.persistence.TemplatePersistenceDat
TabsToSpacesConverterTest.class,
DefaultTextDoubleClickStrategyTest.class,
- MultiSelectionTest.class
+ MultiSelectionTest.class,
+ FindReplaceDocumentAdapterContentProposalProviderTest.class
})
public class JFaceTextTestSuite {
// see @SuiteClasses
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/FindReplaceDocumentAdapterContentProposalProvider.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/FindReplaceDocumentAdapterContentProposalProvider.java
index 94cc14067bd..de047a91b57 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/FindReplaceDocumentAdapterContentProposalProvider.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/FindReplaceDocumentAdapterContentProposalProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 IBM Corporation and others.
+ * Copyright (c) 2008, 2022 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -306,18 +306,10 @@ public class FindReplaceDocumentAdapterContentProposalProvider implements IConte
* @param additionalInfo the additional information
*/
private void addBsProposal(String proposal, String displayString, String additionalInfo) {
- String prolog= fExpression.substring(0, fDocumentOffset);
- int position= proposal.length();
- // If the string already contains the backslash, do not include in the proposal
- if (prolog.endsWith("\\")) { //$NON-NLS-1$
- position--;
- proposal= proposal.substring(1);
- }
-
if (fIsEscape) {
- fPriorityProposals.add(new ContentProposal(proposal, displayString, additionalInfo, position));
+ fPriorityProposals.add(new ContentProposal(proposal.substring(1), displayString, additionalInfo, proposal.length() - 1));
} else {
- addProposal(proposal, position, displayString, additionalInfo);
+ addProposal(proposal, proposal.length(), displayString, additionalInfo);
}
}
}

Back to the top