blob: 2daa475762fb078dcb9cf46bce511316ad8469a7 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2014 Google, Inc 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:
* Sergey Prigogin (Google) - 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.Document;
import org.eclipse.jface.text.TextViewer;
/**
* Basic tests for TextViewer.
*/
public class TextViewerTest {
@Test
public void testSetRedraw_Bug441827() throws Exception {
Shell shell= new Shell();
try {
TextViewer textViewer= new TextViewer(shell, SWT.NONE);
Document document= new Document("abc");
textViewer.setDocument(document);
int len= document.getLength();
// Select the whole document with the caret at the beginning.
textViewer.setSelectedRange(len, -len);
assertEquals(0, textViewer.getSelectedRange().x);
assertEquals(len, textViewer.getSelectedRange().y);
assertEquals(0, textViewer.getTextWidget().getCaretOffset());
textViewer.setRedraw(false);
textViewer.setRedraw(true);
// Check that the selection and the caret position are preserved.
assertEquals(0, textViewer.getSelectedRange().x);
assertEquals(len, textViewer.getSelectedRange().y);
assertEquals(0, textViewer.getTextWidget().getCaretOffset());
} finally {
shell.dispose();
}
}
}