Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Schindl2016-05-04 07:25:10 -0400
committerTom Schindl2016-05-04 07:25:10 -0400
commitc7cadfc21eba4b708441c6b110c85dd31858f604 (patch)
tree7e36133f70bdbb0a79433ed8f02321edd68ef5fb
parent5e74f84fd802c5e0144157d6f1ae703d3392342e (diff)
downloadorg.eclipse.efxclipse-c7cadfc21eba4b708441c6b110c85dd31858f604.tar.gz
org.eclipse.efxclipse-c7cadfc21eba4b708441c6b110c85dd31858f604.tar.xz
org.eclipse.efxclipse-c7cadfc21eba4b708441c6b110c85dd31858f604.zip
Bug 492980 - Undo/redo behave wrong in regard of tab-indenting
-rw-r--r--bundles/code/org.eclipse.fx.text.ui/src/org/eclipse/fx/text/ui/DefaultUndoManager.java18
-rw-r--r--bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/styledtext/TriggerActionMapping.java4
-rw-r--r--bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/styledtext/behavior/StyledTextBehavior.java47
3 files changed, 46 insertions, 23 deletions
diff --git a/bundles/code/org.eclipse.fx.text.ui/src/org/eclipse/fx/text/ui/DefaultUndoManager.java b/bundles/code/org.eclipse.fx.text.ui/src/org/eclipse/fx/text/ui/DefaultUndoManager.java
index a1be9ac32..bf0302ee4 100644
--- a/bundles/code/org.eclipse.fx.text.ui/src/org/eclipse/fx/text/ui/DefaultUndoManager.java
+++ b/bundles/code/org.eclipse.fx.text.ui/src/org/eclipse/fx/text/ui/DefaultUndoManager.java
@@ -110,8 +110,11 @@ public class DefaultUndoManager implements IUndoManager {
StyledTextArea widget= fTextViewer.getTextWidget();
// TODO select?
// if (widget != null && !widget.isDisposed() && (widget.isFocusControl()))// || fTextViewer.getTextWidget() == control))
-
- selectAndReveal(event.getOffset(), event.getText() == null ? 0 : event.getText().length());
+ if( (eventType & DocumentUndoEvent.UNDONE) != 0 ) {
+ reveal(event.getOffset(), event.getText() == null ? 0 : event.getText().length());
+ } else {
+ selectAndReveal(event.getOffset(), event.getText() == null ? 0 : event.getText().length());
+ }
}
}
}
@@ -135,6 +138,17 @@ public class DefaultUndoManager implements IUndoManager {
// fTextViewer.revealRange(offset, length);
}
+ private void reveal(int offset, int length) {
+ if (fTextViewer instanceof ITextViewerExtension5) {
+ ITextViewerExtension5 extension= (ITextViewerExtension5) fTextViewer;
+ extension.exposeModelRange(new Region(offset, length));
+ } else if (!fTextViewer.overlapsWithVisibleRegion(offset, length))
+ fTextViewer.resetVisibleRegion();
+
+ fTextViewer.getTextWidget().setCaretOffset(offset);
+// fTextViewer.revealRange(offset, length);
+ }
+
private void connectDocumentUndoManager(IDocument document) {
disconnectDocumentUndoManager();
if (document != null) {
diff --git a/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/styledtext/TriggerActionMapping.java b/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/styledtext/TriggerActionMapping.java
index cda9cc589..790edcf07 100644
--- a/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/styledtext/TriggerActionMapping.java
+++ b/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/styledtext/TriggerActionMapping.java
@@ -257,6 +257,10 @@ public class TriggerActionMapping {
return optional.map(a->handle(a, context)).orElse(false);
}
+ public boolean exists(KeyEvent event) {
+ return get(event).isPresent();
+ }
+
public boolean triggerAction(char typedChar, Context context) {
Optional<TextEditAction> optional = get(typedChar);
return optional.map(a->handle(a, context)).orElse(false);
diff --git a/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/styledtext/behavior/StyledTextBehavior.java b/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/styledtext/behavior/StyledTextBehavior.java
index 9c7fbf2b0..59d196846 100644
--- a/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/styledtext/behavior/StyledTextBehavior.java
+++ b/bundles/runtime/org.eclipse.fx.ui.controls/src/org/eclipse/fx/ui/controls/styledtext/behavior/StyledTextBehavior.java
@@ -199,16 +199,18 @@ public class StyledTextBehavior {
private void onKeyPressed(KeyEvent event) {
- getControl().fireEvent(UndoHintEvent.createBeginCompoundChangeEvent());
- try {
- boolean handled = this.keyTriggerMapping.triggerAction(event, new Context(getControl()));
- if (handled) {
- event.consume();
- return;
+ if( this.keyTriggerMapping.exists(event) ) {
+ getControl().fireEvent(UndoHintEvent.createBeginCompoundChangeEvent());
+ try {
+ boolean handled = this.keyTriggerMapping.triggerAction(event, new Context(getControl()));
+ if (handled) {
+ event.consume();
+ return;
+ }
+ }
+ finally {
+ getControl().fireEvent(UndoHintEvent.createEndCompoundChangeEvent());
}
- }
- finally {
- getControl().fireEvent(UndoHintEvent.createEndCompoundChangeEvent());
}
if( this.dragMoveTextMode ) {
@@ -290,16 +292,16 @@ public class StyledTextBehavior {
// check for typed char action
- getControl().fireEvent(UndoHintEvent.createBeginCompoundChangeEvent());
- try {
- this.keyTriggerMapping.triggerAction(character.charAt(0), new Context(getControl()));
- }
- finally {
- getControl().fireEvent(UndoHintEvent.createEndCompoundChangeEvent());
+ if( this.keyTriggerMapping.exists(event) ) {
+ getControl().fireEvent(UndoHintEvent.createBeginCompoundChangeEvent());
+ try {
+ this.keyTriggerMapping.triggerAction(character.charAt(0), new Context(getControl()));
+ }
+ finally {
+ getControl().fireEvent(UndoHintEvent.createEndCompoundChangeEvent());
+ }
}
-
}
-
}
}
@@ -1121,6 +1123,7 @@ public class StyledTextBehavior {
int added = 0;
int firstLineDelta = 0;
+ int indentLength = getControl().isInsertSpacesForTab() ? getControl().getTabAdvance() : 1;
String insertString = "\t"; //$NON-NLS-1$
if( getControl().isInsertSpacesForTab() ) {
@@ -1137,16 +1140,18 @@ public class StyledTextBehavior {
added += insertString.length();
if (lineNumber == firstLine) {
if (selectionOffset > lineStart) {
- firstLineDelta = 1;
+ firstLineDelta = selectionOffset - lineStart;
}
}
}
- String data = dataBuffer.toString();
+ int start = selectionOffset - firstLineDelta;
+ int length = selectionLength + added + firstLineDelta;
+ String replaced = dataBuffer.substring(start,start+length);
- getControl().getContent().setText(data == null ? "" : data); //$NON-NLS-1$
+ getControl().getContent().replaceTextRange(start, length-added, replaced);
getControl().setCaretOffset(caret + added);
- getControl().setSelectionRange(selectionOffset + firstLineDelta, selectionLength + added - firstLineDelta);
+ getControl().setSelectionRange(selectionOffset + indentLength, selectionLength + added - indentLength);
}
}

Back to the top