Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2014-08-14 22:54:18 -0400
committerSergey Prigogin2014-08-18 14:47:57 -0400
commit90d747a70773d55259e1fb0a14800a495d503761 (patch)
tree068fd698abd25dc98fa4d716a6793f21ba543712 /org.eclipse.jface.text.tests
parenta6c3fcd0d01212acee000c36c1f9d18f9224978f (diff)
downloadeclipse.platform.text-90d747a70773d55259e1fb0a14800a495d503761.tar.gz
eclipse.platform.text-90d747a70773d55259e1fb0a14800a495d503761.tar.xz
eclipse.platform.text-90d747a70773d55259e1fb0a14800a495d503761.zip
Bug 441827 - TextViewer.ViewerState.restore method looses caret position
Change-Id: I89be1f8a6712f390f2cd8e6a5b8ea3d329c5fb4d Signed-off-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
Diffstat (limited to 'org.eclipse.jface.text.tests')
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/JFaceTextTestSuite.java1
-rw-r--r--org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java60
2 files changed, 61 insertions, 0 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 e8dae5280..18f225fa0 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
@@ -30,6 +30,7 @@ public class JFaceTextTestSuite extends TestSuite {
suite.addTest(TextHoverPopupTest.suite());
suite.addTest(TextPresentationTest.suite());
suite.addTest(DefaultUndoManagerTest.suite());
+ suite.addTest(TextViewerTest.suite());
suite.addTest(TextViewerUndoManagerTest.suite());
suite.addTest(RulesTestSuite.suite());
suite.addTest(ReconcilerTestSuite.suite());
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
new file mode 100644
index 000000000..3b529ff08
--- /dev/null
+++ b/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Google, Inc and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sergey Prigogin (Google) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jface.text.tests;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Shell;
+
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.TextViewer;
+
+/**
+ * Basic tests for TextViewer.
+ */
+public class TextViewerTest extends TestCase {
+ public static Test suite() {
+ return new TestSuite(TextViewerTest.class);
+ }
+
+ private Shell fShell;
+ private TextViewer fTextViewer;
+ private Document fDocument;
+
+ protected void setUp() {
+ fShell= new Shell();
+ fTextViewer= new TextViewer(fShell, SWT.NONE);
+ }
+
+ protected void tearDown() {
+ fShell.dispose();
+ }
+
+ public void testSetRedraw_Bug441827() throws Exception {
+ fDocument= new Document("abc");
+ fTextViewer.setDocument(fDocument);
+ int len= fDocument.getLength();
+ // Select the whole document with the caret at the beginning.
+ fTextViewer.setSelectedRange(len, -len);
+ assertEquals(0, fTextViewer.getSelectedRange().x);
+ assertEquals(len, fTextViewer.getSelectedRange().y);
+ assertEquals(0, fTextViewer.getTextWidget().getCaretOffset());
+ fTextViewer.setRedraw(false);
+ fTextViewer.setRedraw(true);
+ // Check that the selection and the caret position are preserved.
+ assertEquals(0, fTextViewer.getSelectedRange().x);
+ assertEquals(len, fTextViewer.getSelectedRange().y);
+ assertEquals(0, fTextViewer.getTextWidget().getCaretOffset());
+ }
+}

Back to the top