Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateusz Matela2019-07-06 10:42:30 +0000
committerMickael Istria2019-09-17 09:56:22 +0000
commit5f90916aa35368e9894d559308845c7f5c5d6a23 (patch)
treebb5b657380376356dd8e3509466421f9f4d7f585
parent812fe47c98daf733d10a208cfe4717109fdd59f7 (diff)
downloadeclipse.platform.text-5f90916aa35368e9894d559308845c7f5c5d6a23.tar.gz
eclipse.platform.text-5f90916aa35368e9894d559308845c7f5c5d6a23.tar.xz
eclipse.platform.text-5f90916aa35368e9894d559308845c7f5c5d6a23.zip
Bug 483846 - [typing] Spaces only mode: backspace key to remove manyI20190918-0300I20190917-1800
spaces Change-Id: I162b412281bc0028aba4e763a859410d86f34aa6 Signed-off-by: Mateusz Matela <mateusz.matela@gmail.com>
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/JFaceTextTestSuite.java6
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TabsToSpacesConverterTest.java201
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java2
-rw-r--r--org.eclipse.jface.text/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.jface.text/pom.xml4
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentCommand.java3
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/TabsToSpacesConverter.java52
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java3
-rw-r--r--org.eclipse.ui.editors/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.ui.editors/pom.xml4
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorDefaultsPreferencePage.java9
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.java3
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties3
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java10
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditorPreferenceConstants.java16
-rw-r--r--org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.ui.workbench.texteditor/pom.xml2
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java17
18 files changed, 317 insertions, 24 deletions
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 3a481804467..5790030af85 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -62,7 +62,9 @@ import org.eclipse.jface.text.tests.templates.persistence.TemplatePersistenceDat
LineContentBoundsDrawingTest.class,
AnnotationOnTabTest.class,
CodeMiningTest.class,
- CodeMiningProjectionViewerTest.class
+ CodeMiningProjectionViewerTest.class,
+
+ TabsToSpacesConverterTest.class,
})
public class JFaceTextTestSuite {
// see @SuiteClasses
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TabsToSpacesConverterTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TabsToSpacesConverterTest.java
new file mode 100644
index 00000000000..b2617626bff
--- /dev/null
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TabsToSpacesConverterTest.java
@@ -0,0 +1,201 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Mateusz Matela 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
+ *
+ * Contributors:
+ * Mateusz Matela - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jface.text.tests;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Shell;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DefaultLineTracker;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.TabsToSpacesConverter;
+import org.eclipse.jface.text.TextViewer;
+import org.eclipse.jface.text.source.projection.ProjectionAnnotation;
+import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
+import org.eclipse.jface.text.source.projection.ProjectionViewer;
+
+public class TabsToSpacesConverterTest {
+
+ private void doTest(String input, String output, int keyCode, int tabWidth) {
+ Shell shell= new Shell();
+ TextViewer textViewer= new TextViewer(shell, SWT.NONE);
+
+ TabsToSpacesConverter tabToSpacesConverter= new TabsToSpacesConverter();
+ tabToSpacesConverter.setLineTracker(new DefaultLineTracker());
+ tabToSpacesConverter.setNumberOfSpacesPerTab(tabWidth);
+ tabToSpacesConverter.setDeleteSpacesAsTab(true);
+ textViewer.setTabsToSpacesConverter(tabToSpacesConverter);
+
+ int selectionFrom= input.indexOf('|');
+ int selectionTo= input.indexOf('|', selectionFrom + 1) - 1;
+ Document document= new Document(input.replace("|", ""));
+ textViewer.setDocument(document);
+ textViewer.setSelectedRange(selectionFrom, selectionTo - selectionFrom);
+
+ TextViewerTest.postKeyEvent(textViewer.getTextWidget(), keyCode, SWT.NONE, SWT.KeyDown);
+
+ assertEquals(output, document.get());
+ }
+
+ @Test
+ public void testDelete1() {
+ doTest("|| ABC", " ABC", SWT.DEL, 4);
+ }
+
+ @Test
+ public void testDelete2() {
+ doTest(" || ABC", " ABC", SWT.DEL, 4);
+ }
+
+ @Test
+ public void testDelete3() {
+ doTest(" || ABC", " ABC", SWT.DEL, 4);
+ }
+
+ @Test
+ public void testDelete4() {
+ doTest(" || ABC", " ABC", SWT.DEL, 4);
+ }
+
+ @Test
+ public void testDeleteRange1() {
+ doTest(" | | ABC", " ABC", SWT.DEL, 4);
+ }
+
+ @Test
+ public void testDeleteRange2() {
+ doTest(" | | ABC", " ABC", SWT.DEL, 4);
+ }
+
+ @Test
+ public void testDeleteInside1() {
+ doTest(" ABCD|| EFG", " ABCDEFG", SWT.DEL, 4);
+ }
+
+ @Test
+ public void testDeleteInside2() {
+ doTest(" ABCD || EFG", " ABCD EFG", SWT.DEL, 4);
+ }
+
+ @Test
+ public void testDeleteInside3() {
+ doTest(" ABCD|| EFG", " ABCDEFG", SWT.DEL, 4);
+ }
+
+ @Test
+ public void testDeleteLargeWidth1() {
+ doTest(" || ABC", " ABC", SWT.DEL, 10);
+ }
+
+ @Test
+ public void testDeleteLargeWidth2() {
+ doTest(" || ABC", " ABC", SWT.DEL, 10);
+ }
+
+ @Test
+ public void testDeleteSmallWidth() {
+ doTest(" || ABC", " ABC", SWT.DEL, 2);
+ }
+
+ @Test
+ public void testBackspace1() {
+ doTest(" || ABC", " ABC", SWT.BS, 4);
+ }
+
+ @Test
+ public void testBackspace2() {
+ doTest(" ||ABC", " ABC", SWT.BS, 4);
+ }
+
+ @Test
+ public void testBackspace3() {
+ doTest(" || ABC", " ABC", SWT.BS, 4);
+ }
+
+ @Test
+ public void testBackspace4() {
+ doTest(" || ABC", " ABC", SWT.BS, 4);
+ }
+
+ @Test
+ public void testBackspaceRange1() {
+ doTest(" | | ABC", " ABC", SWT.BS, 4);
+ }
+
+ @Test
+ public void testBackspaceRange2() {
+ doTest(" | | ABC", " ABC", SWT.BS, 4);
+ }
+
+ @Test
+ public void testBackspaceInside1() {
+ doTest(" ABCD ||EFG", " ABCDEFG", SWT.BS, 4);
+ }
+
+ @Test
+ public void testBackspaceInside2() {
+ doTest(" ABCD ||EFG", " ABCD EFG", SWT.BS, 4);
+ }
+
+ @Test
+ public void testBackspaceInside3() {
+ doTest(" ABCDEF ||G", " ABCDEFG", SWT.BS, 4);
+ }
+
+ @Test
+ public void testBackspaceLargeWidth1() {
+ doTest(" || ABC", " ABC", SWT.BS, 10);
+ }
+
+ @Test
+ public void testBackspaceLargeWidth2() {
+ doTest(" || ABC", " ABC", SWT.BS, 10);
+ }
+
+ @Test
+ public void testBackspaceSmallWidth() {
+ doTest(" || ABC", " ABC", SWT.BS, 2);
+ }
+
+ @Test
+ public void testDeleteAfterCollapsedRegion() throws BadLocationException {
+ Shell shell= new Shell();
+ ProjectionViewer textViewer= new ProjectionViewer(shell, null, null, false, SWT.NONE);
+
+ TabsToSpacesConverter tabToSpacesConverter= new TabsToSpacesConverter();
+ tabToSpacesConverter.setLineTracker(new DefaultLineTracker());
+ tabToSpacesConverter.setNumberOfSpacesPerTab(4);
+ tabToSpacesConverter.setDeleteSpacesAsTab(true);
+ textViewer.setTabsToSpacesConverter(tabToSpacesConverter);
+
+ Document document= new Document(" COLLAPSED!!!\n REGION!!!\n VISIBLE\n REGION");
+ int caretPosition= document.get().indexOf("VISIBLE") - 4;
+ textViewer.setDocument(document, new ProjectionAnnotationModel());
+ textViewer.enableProjection();
+ textViewer.setSelectedRange(caretPosition, 0);
+
+ ProjectionAnnotation annotation= new ProjectionAnnotation(true);
+ textViewer.getProjectionAnnotationModel().addAnnotation(annotation, new Position(0, document.getLineOffset(2)));
+ textViewer.doOperation(ProjectionViewer.COLLAPSE_ALL);
+
+ TextViewerTest.postKeyEvent(textViewer.getTextWidget(), SWT.DEL, SWT.NONE, SWT.KeyDown);
+
+ assertEquals(" COLLAPSED!!!\n REGION!!!\nVISIBLE\n REGION", document.get());
+ }
+}
diff --git a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java
index a53a00dfc2e..2ee51f54302 100644
--- a/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java
@@ -292,7 +292,7 @@ public class TextViewerTest {
postKeyEvent(viewer.getTextWidget(), SWT.HOME, SWT.CTRL, SWT.KeyDown);
}
- private static void postKeyEvent(Control widget, int keyCode, int stateMask, int type) {
+ static void postKeyEvent(Control widget, int keyCode, int stateMask, int type) {
Display display= widget.getDisplay();
widget.setFocus();
DisplayHelper.driveEventQueue(display);
diff --git a/org.eclipse.jface.text/META-INF/MANIFEST.MF b/org.eclipse.jface.text/META-INF/MANIFEST.MF
index 38c33e54307..cad51887da2 100644
--- a/org.eclipse.jface.text/META-INF/MANIFEST.MF
+++ b/org.eclipse.jface.text/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jface.text
-Bundle-Version: 3.16.0.qualifier
+Bundle-Version: 3.16.100.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package:
diff --git a/org.eclipse.jface.text/pom.xml b/org.eclipse.jface.text/pom.xml
index 3c59bdaaac5..57899690073 100644
--- a/org.eclipse.jface.text/pom.xml
+++ b/org.eclipse.jface.text/pom.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2012, 2017 Eclipse Foundation and others.
+ Copyright (c) 2012, 2019 Eclipse Foundation and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Distribution License v1.0
which accompanies this distribution, and is available at
@@ -18,6 +18,6 @@
</parent>
<groupId>org.eclipse.jface</groupId>
<artifactId>org.eclipse.jface.text</artifactId>
- <version>3.16.0-SNAPSHOT</version>
+ <version>3.16.100-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentCommand.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentCommand.java
index cf6898d4d8a..cc6958e834a 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentCommand.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentCommand.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -251,6 +251,7 @@ public class DocumentCommand {
*/
public boolean shiftsCaret;
+ ITextSelection fSelection;
/**
* Creates a new document command.
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/TabsToSpacesConverter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/TabsToSpacesConverter.java
index 600e0556bd8..c342a3039ba 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/TabsToSpacesConverter.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/TabsToSpacesConverter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 IBM Corporation and others.
+ * Copyright (c) 2007, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,7 +13,6 @@
*******************************************************************************/
package org.eclipse.jface.text;
-
/**
* Auto edit strategy that converts tabs into spaces.
* <p>
@@ -26,6 +25,9 @@ package org.eclipse.jface.text;
public class TabsToSpacesConverter implements IAutoEditStrategy {
private int fTabRatio;
+
+ private boolean fDeleteSpacesAsTab;
+
private ILineTracker fLineTracker;
@@ -33,6 +35,14 @@ public class TabsToSpacesConverter implements IAutoEditStrategy {
fTabRatio= ratio;
}
+ /**
+ * @param enabled if true, spaces deletion will be modified to match tabs behavior
+ * @since 3.16
+ */
+ public void setDeleteSpacesAsTab(boolean enabled) {
+ fDeleteSpacesAsTab= enabled;
+ }
+
public void setLineTracker(ILineTracker lineTracker) {
fLineTracker= lineTracker;
}
@@ -55,8 +65,11 @@ public class TabsToSpacesConverter implements IAutoEditStrategy {
if (text == null)
return;
- int index= text.indexOf('\t');
- if (index > -1) {
+ if (text.isEmpty()) {
+
+ replaceDeleteSpaceByDeleteTab(document, command);
+
+ } else if (text.indexOf('\t') > -1) {
StringBuilder buffer= new StringBuilder();
@@ -93,7 +106,38 @@ public class TabsToSpacesConverter implements IAutoEditStrategy {
command.text= buffer.toString();
} catch (BadLocationException x) {
+ throw new IllegalArgumentException("should never happen", x); //$NON-NLS-1$
+ }
+ }
+ }
+
+ private void replaceDeleteSpaceByDeleteTab(IDocument document, DocumentCommand command) {
+ if (!fDeleteSpacesAsTab || fTabRatio == 0 || command.length != 1)
+ return;
+ ITextSelection selection= command.fSelection;
+ if (selection == null || selection.getLength() != 0)
+ return;
+ try {
+ if (document.getChar(command.offset) != ' ')
+ return;
+
+ IRegion line= document.getLineInformationOfOffset(command.offset);
+ int offsetInLine= command.offset - line.getOffset();
+ boolean isDeleteKey= selection.getOffset() == command.offset;
+ if (isDeleteKey) {
+ int spacesToRemove= fTabRatio - (offsetInLine % fTabRatio) - 1;
+ while (spacesToRemove-- > 0 && document.getChar(command.offset + command.length) == ' ') {
+ command.length++;
+ }
+ } else { //backspace
+ int spacesToRemove= offsetInLine % fTabRatio;
+ while (spacesToRemove-- > 0 && document.getChar(command.offset - 1) == ' ') {
+ command.offset--;
+ command.length++;
+ }
}
+ } catch (BadLocationException e) {
+ throw new IllegalArgumentException("should never happen", e); //$NON-NLS-1$
}
}
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java
index 9a274e3d94b..1a79229ea8c 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -3663,6 +3663,7 @@ public class TextViewer extends Viewer implements
IRegion modelRange= event2ModelRange(e);
fDocumentCommand.setEvent(e, modelRange);
+ fDocumentCommand.fSelection= (ITextSelection) getSelection();
customizeDocumentCommand(fDocumentCommand);
if (!fDocumentCommand.fillEvent(e, modelRange)) {
diff --git a/org.eclipse.ui.editors/META-INF/MANIFEST.MF b/org.eclipse.ui.editors/META-INF/MANIFEST.MF
index c3821be4c92..ff421860f5b 100644
--- a/org.eclipse.ui.editors/META-INF/MANIFEST.MF
+++ b/org.eclipse.ui.editors/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.ui.editors; singleton:=true
-Bundle-Version: 3.12.0.qualifier
+Bundle-Version: 3.13.0.qualifier
Bundle-Activator: org.eclipse.ui.internal.editors.text.EditorsPlugin
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
diff --git a/org.eclipse.ui.editors/pom.xml b/org.eclipse.ui.editors/pom.xml
index 0a9f23b138b..7bb1058f86f 100644
--- a/org.eclipse.ui.editors/pom.xml
+++ b/org.eclipse.ui.editors/pom.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2012, 2015 Eclipse Foundation and others.
+ Copyright (c) 2012, 2019 Eclipse Foundation and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Distribution License v1.0
which accompanies this distribution, and is available at
@@ -18,6 +18,6 @@
</parent>
<groupId>org.eclipse.ui</groupId>
<artifactId>org.eclipse.ui.editors</artifactId>
- <version>3.12.0-SNAPSHOT</version>
+ <version>3.13.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorDefaultsPreferencePage.java b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorDefaultsPreferencePage.java
index fc766ccd06d..47c22c621f8 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorDefaultsPreferencePage.java
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorDefaultsPreferencePage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -732,6 +732,7 @@ public class TextEditorDefaultsPreferencePage extends PreferencePage implements
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractTextEditor.PREFERENCE_WORD_WRAP_ENABLED));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS));
+ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_DELETE_SPACES_AS_TABS));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN));
@@ -854,8 +855,12 @@ public class TextEditorDefaultsPreferencePage extends PreferencePage implements
label= TextEditorMessages.TextEditorPreferencePage_convertTabsToSpaces;
Preference spacesForTabs= new Preference(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS, label, null);
- addCheckBox(appearanceComposite, spacesForTabs, new BooleanDomain(), 0);
+ final Button spacesForTabsButton= addCheckBox(appearanceComposite, spacesForTabs, new BooleanDomain(), 0);
+ label= TextEditorMessages.TextEditorDefaultsPreferencePage_deleteSpacesAsTabs;
+ Preference deleteSpacesAsTabs= new Preference(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_DELETE_SPACES_AS_TABS, label, null);
+ final Button deleteSpacesAsTabsButton= addCheckBox(appearanceComposite, deleteSpacesAsTabs, new BooleanDomain(), 0);
+ createDependency(spacesForTabsButton, spacesForTabs, new Control[] { deleteSpacesAsTabsButton });
label= TextEditorMessages.TextEditorPreferencePage_highlightCurrentLine;
Preference highlightCurrentLine= new Preference(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE, label, null);
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.java b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.java
index 12568d9e97c..93e6ea4c5d4 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.java
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -138,6 +138,7 @@ final class TextEditorMessages extends NLS {
public static String TextEditorDefaultsPreferencePage_carriageReturn;
public static String TextEditorDefaultsPreferencePage_transparencyLevel;
public static String TextEditorDefaultsPreferencePage_configureWhitespaceCharacterPainterProperties;
+ public static String TextEditorDefaultsPreferencePage_deleteSpacesAsTabs;
public static String TextEditorDefaultsPreferencePage_enclosed;
public static String TextEditorDefaultsPreferencePage_enrichHoverMode;
public static String TextEditorDefaultsPreferencePage_enrichHover_immediately;
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties
index a770961b5f6..a316d243636 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2000, 2018 IBM Corporation and others.
+# Copyright (c) 2000, 2019 IBM Corporation and others.
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
@@ -40,6 +40,7 @@ TextEditorPreferencePage_accessibility_useSaturatedColorsInOverviewRuler=U&se sa
TextEditorDefaultsPreferencePage_carriageReturn=Carriage Return ( \u00a4 )
TextEditorDefaultsPreferencePage_transparencyLevel=&Transparency level (0 is transparent and 255 is opaque):
TextEditorDefaultsPreferencePage_configureWhitespaceCharacterPainterProperties=Configure visibility of whitespace characters in different regions of a line of text:
+TextEditorDefaultsPreferencePage_deleteSpacesAsTabs=Remove &multiple spaces on backspace/delete
TextEditorDefaultsPreferencePage_enclosed=Enclosed
TextEditorDefaultsPreferencePage_enrichHoverMode=When mouse mo&ved into hover:
TextEditorDefaultsPreferencePage_enrichHover_afterDelay=Enrich after delay
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java b/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java
index 76e411f0c7a..7e884ee217c 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -854,7 +854,8 @@ public abstract class AbstractDecoratedTextEditor extends StatusTextEditor {
return;
}
- if (AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS.equals(property)) {
+ if (AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS.equals(property)
+ || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_DELETE_SPACES_AS_TABS.equals(property)) {
if (isTabsToSpacesConversionEnabled())
installTabsToSpacesConverter();
else
@@ -2232,4 +2233,9 @@ public abstract class AbstractDecoratedTextEditor extends StatusTextEditor {
protected boolean isTabsToSpacesConversionEnabled() {
return getPreferenceStore() != null && getPreferenceStore().getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS);
}
+
+ @Override
+ protected boolean isSpacesAsTabsDeletionEnabled() {
+ return getPreferenceStore() != null && getPreferenceStore().getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_DELETE_SPACES_AS_TABS);
+ }
}
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditorPreferenceConstants.java b/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditorPreferenceConstants.java
index 7f71c18e1e9..8d428177804 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditorPreferenceConstants.java
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditorPreferenceConstants.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2018 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -91,6 +91,19 @@ public class AbstractDecoratedTextEditorPreferenceConstants {
public final static String EDITOR_SPACES_FOR_TABS= "spacesForTabs"; //$NON-NLS-1$
/**
+ * A named preference that specifies if the editor removes multiple spaces on delete/backspace
+ * key as if they were tabs. Only relevant when {@link #EDITOR_SPACES_FOR_TABS} preference is
+ * set to <code>true</code>.
+ * <p>
+ * Value is of type <code>Boolean</code>. If <code>true</code>, the editor removes multiple
+ * spaces.
+ * </p>
+ *
+ * @since 3.13
+ */
+ public final static String EDITOR_DELETE_SPACES_AS_TABS= "removeSpacesAsTabs"; //$NON-NLS-1$
+
+ /**
* A named preference that holds the size of the editor's undo history.
* <p>
* Value is of type <code>int</code>: 0 or positive int value specifying the size of
@@ -706,6 +719,7 @@ public class AbstractDecoratedTextEditorPreferenceConstants {
store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH, 4);
store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS, false);
+ store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_DELETE_SPACES_AS_TABS, false);
store.setDefault(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_UNDO_HISTORY_SIZE, 200);
diff --git a/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF b/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF
index d54a2a892f7..d0305f87d1e 100644
--- a/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF
+++ b/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.ui.workbench.texteditor; singleton:=true
-Bundle-Version: 3.13.100.qualifier
+Bundle-Version: 3.14.0.qualifier
Bundle-Activator: org.eclipse.ui.internal.texteditor.TextEditorPlugin
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
diff --git a/org.eclipse.ui.workbench.texteditor/pom.xml b/org.eclipse.ui.workbench.texteditor/pom.xml
index c8a4c9557f8..21141551320 100644
--- a/org.eclipse.ui.workbench.texteditor/pom.xml
+++ b/org.eclipse.ui.workbench.texteditor/pom.xml
@@ -18,6 +18,6 @@
</parent>
<groupId>org.eclipse.ui</groupId>
<artifactId>org.eclipse.ui.workbench.texteditor</artifactId>
- <version>3.13.100-SNAPSHOT</version>
+ <version>3.14.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java
index b3105d2de16..267c21201e4 100644
--- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java
@@ -7274,6 +7274,7 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit
TabsToSpacesConverter tabToSpacesConverter= new TabsToSpacesConverter();
tabToSpacesConverter.setLineTracker(new DefaultLineTracker());
tabToSpacesConverter.setNumberOfSpacesPerTab(tabWidth);
+ tabToSpacesConverter.setDeleteSpacesAsTab(isSpacesAsTabsDeletionEnabled());
((ITextViewerExtension7)fSourceViewer).setTabsToSpacesConverter(tabToSpacesConverter);
updateIndentPrefixes();
}
@@ -7308,6 +7309,22 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit
}
/**
+ * Tells whether delete and backspace keys should remove multiple spaces as
+ * if they were a tab. Only relevant when
+ * {@link #isTabsToSpacesConversionEnabled()} returns true.
+ *
+ * <p>
+ * Subclasses may override this method.
+ * </p>
+ *
+ * @return <code>true</code> if spaces should be removed as tabs
+ * @since 3.14
+ */
+ protected boolean isSpacesAsTabsDeletionEnabled() {
+ return false;
+ }
+
+ /**
* Updates the source viewer's indent prefixes with
* the values provided by the source viewer configuration.
*

Back to the top