Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2021-07-24 12:49:53 -0400
committerAndrey Loskutov2021-07-24 17:53:29 -0400
commitcc5a9e8582f2b91e676711c33b94f440390e4149 (patch)
tree689c0a513d5d2da9a789b5800a9f510125636fba
parent9e9fda599f36162554b017b469e0e32747ec963e (diff)
downloadeclipse.platform.text-I20210725-1800.tar.gz
eclipse.platform.text-I20210725-1800.tar.xz
eclipse.platform.text-I20210725-1800.zip
editors Don't browse backwards in history on closing or changing editor input. Change-Id: I14353a7b494bddd84ef5177b8801f208d27a1fd1 Signed-off-by: Andrey Loskutov <loskutov@gmx.de> Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.text/+/183341 Tested-by: Platform Bot <platform-bot@eclipse.org>
-rw-r--r--org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/EditPosition.java22
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/HistoryTracker.java30
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java23
4 files changed, 65 insertions, 12 deletions
diff --git a/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF b/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF
index 5d2171a27..a2c871e90 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.16.100.qualifier
+Bundle-Version: 3.16.200.qualifier
Bundle-Activator: org.eclipse.ui.internal.texteditor.TextEditorPlugin
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/EditPosition.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/EditPosition.java
index c59ffc836..012ee48cc 100644
--- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/EditPosition.java
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/EditPosition.java
@@ -71,6 +71,28 @@ public final class EditPosition {
return fEditorId;
}
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("EditPosition ["); //$NON-NLS-1$
+ if (fEditorInput != null) {
+ builder.append("input="); //$NON-NLS-1$
+ builder.append(fEditorInput);
+ builder.append(", "); //$NON-NLS-1$
+ }
+ if (fEditorId != null) {
+ builder.append("editorId="); //$NON-NLS-1$
+ builder.append(fEditorId);
+ builder.append(", "); //$NON-NLS-1$
+ }
+ if (fPosition != null) {
+ builder.append("position="); //$NON-NLS-1$
+ builder.append(fPosition);
+ }
+ builder.append("]"); //$NON-NLS-1$
+ return builder.toString();
+ }
+
/**
* Returns the position.
*
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/HistoryTracker.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/HistoryTracker.java
index 422a2a69a..8488a31f6 100644
--- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/HistoryTracker.java
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/HistoryTracker.java
@@ -15,6 +15,9 @@
package org.eclipse.ui.internal.texteditor;
import java.lang.reflect.Array;
+import java.util.Arrays;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
/**
* @author Ari Kast
@@ -348,6 +351,33 @@ public class HistoryTracker<T> {
}
/**
+ * @return Stream with all non-null history elements, may be empty
+ */
+ public Stream<T> rawHistory() {
+ return Arrays.asList(fHistory).stream().filter(x -> x != null);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("HistoryTracker ["); //$NON-NLS-1$
+ builder.append("history="); //$NON-NLS-1$
+ builder.append(rawHistory().map(x -> x.toString()).collect(Collectors.joining(", "))); //$NON-NLS-1$
+ builder.append(", "); //$NON-NLS-1$
+ if (fBrowsePoint != null) {
+ builder.append("browsePoint="); //$NON-NLS-1$
+ builder.append(fBrowsePoint);
+ builder.append(", "); //$NON-NLS-1$
+ }
+ builder.append("size="); //$NON-NLS-1$
+ builder.append(fSize);
+ builder.append(", circular="); //$NON-NLS-1$
+ builder.append(fUseCircularNavigation);
+ builder.append("]"); //$NON-NLS-1$
+ return builder.toString();
+ }
+
+ /**
* for easy traversing thru history
*/
public static class Navigator<T> {
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 840af786a..cda1fcfdb 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
@@ -33,6 +33,7 @@ import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Stream;
import org.osgi.framework.Bundle;
@@ -682,25 +683,25 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit
@Override
public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
- HistoryTracker<EditPosition> positionHistory = TextEditorPlugin.getDefault().getEditPositionHistory();
- if (oldInput != null && !positionHistory.isEmpty()) {
- for (int i = 0; i < positionHistory.getSize(); i++)
- oldInput.removePosition(positionHistory.browseBackward().getPosition());
- }
+ discardHistoryFor(oldInput, newInput);
}
@Override
public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
- discardHistoryFor(oldInput);
+ discardHistoryFor(oldInput, newInput);
}
- private void discardHistoryFor(IDocument input) {
+ private void discardHistoryFor(IDocument oldInput, IDocument newInput) {
+ // Only discard history from document if it is replaced by other real document,
+ // don't care otherwise
+ if (oldInput == null || newInput == null) {
+ return;
+ }
HistoryTracker<EditPosition> positionHistory = TextEditorPlugin.getDefault().getEditPositionHistory();
- if (input != null && !positionHistory.isEmpty()) {
- for (int i = 0; i < positionHistory.getSize(); i++)
- input.removePosition(positionHistory.browseBackward().getPosition());
+ if (!positionHistory.isEmpty()) {
+ Stream<EditPosition> rawHistory = positionHistory.rawHistory();
+ rawHistory.forEach(p -> oldInput.removePosition(p.getPosition()));
}
-
}
}

Back to the top