Search in sources :

Example 1 with TextPosition

use of org.eclipse.che.ide.api.editor.text.TextPosition in project che by eclipse.

the class BasicActiveFileHandler method scrollToLine.

protected void scrollToLine(EditorPartPresenter editor, int lineNumber) {
    if (editor instanceof TextEditor) {
        TextEditor textEditor = (TextEditor) editor;
        Document document = textEditor.getDocument();
        if (document != null) {
            TextPosition newPosition = new TextPosition(lineNumber, 0);
            document.setCursorPosition(newPosition);
        }
    }
}
Also used : TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) Document(org.eclipse.che.ide.api.editor.document.Document)

Example 2 with TextPosition

use of org.eclipse.che.ide.api.editor.text.TextPosition in project che by eclipse.

the class TestResultViewImpl method gotoClass.

@Override
public void gotoClass(String packagePath, int line) {
    lastWentLine = line;
    final Project project = appContext.getRootProject();
    String testSrcPath = project.getPath() + "/" + DEFAULT_TEST_SOURCE_FOLDER;
    appContext.getWorkspaceRoot().getFile(testSrcPath + packagePath).then(new Operation<Optional<File>>() {

        @Override
        public void apply(Optional<File> file) throws OperationException {
            if (file.isPresent()) {
                eventBus.fireEvent(FileEvent.createOpenFileEvent(file.get()));
                Timer t = new Timer() {

                    @Override
                    public void run() {
                        EditorPartPresenter editorPart = editorAgent.getActiveEditor();
                        Document doc = ((TextEditor) editorPart).getDocument();
                        doc.setCursorPosition(new TextPosition(lastWentLine - 1, 0));
                    }
                };
                t.schedule(500);
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            Log.info(TestResultViewImpl.class, error);
        }
    });
}
Also used : Optional(com.google.common.base.Optional) Operation(org.eclipse.che.api.promises.client.Operation) Document(org.eclipse.che.ide.api.editor.document.Document) Project(org.eclipse.che.ide.api.resources.Project) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) Timer(com.google.gwt.user.client.Timer) PromiseError(org.eclipse.che.api.promises.client.PromiseError) TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) File(org.eclipse.che.ide.api.resources.File) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 3 with TextPosition

use of org.eclipse.che.ide.api.editor.text.TextPosition in project che by eclipse.

the class CloseCStyleCommentChangeInterceptorTest method testStartNotEmptyLine.

@Test
public void testStartNotEmptyLine() {
    doReturn("whatever").when(document).getLineContent(0);
    doReturn("s/*").when(document).getLineContent(1);
    doReturn(" *").when(document).getLineContent(2);
    final TextChange input = new TextChange.Builder().from(new TextPosition(1, 3)).to(new TextPosition(2, 2)).insert("\n *").build();
    final TextChange output = interceptor.processChange(input, document);
    assertNull(output);
}
Also used : TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) TextChange(org.eclipse.che.ide.api.editor.changeintercept.TextChange) Test(org.junit.Test)

Example 4 with TextPosition

use of org.eclipse.che.ide.api.editor.text.TextPosition in project che by eclipse.

the class CloseCStyleCommentChangeInterceptorTest method testPasteWholeCommentStart.

@Test
public void testPasteWholeCommentStart() {
    doReturn("/**").when(document).getLineContent(0);
    doReturn(" *").when(document).getLineContent(1);
    final TextChange input = new TextChange.Builder().from(new TextPosition(0, 0)).to(new TextPosition(1, 2)).insert("/**\n *").build();
    final TextChange output = interceptor.processChange(input, document);
    assertNull(output);
}
Also used : TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) TextChange(org.eclipse.che.ide.api.editor.changeintercept.TextChange) Test(org.junit.Test)

Example 5 with TextPosition

use of org.eclipse.che.ide.api.editor.text.TextPosition in project che by eclipse.

the class CloseCStyleCommentChangeInterceptorTest method testWithLeading.

private void testWithLeading(final String lead) {
    doReturn(lead + "/*").when(document).getLineContent(1);
    doReturn(lead + " *").when(document).getLineContent(2);
    final TextChange input = new TextChange.Builder().from(new TextPosition(1, 2 + lead.length())).to(new TextPosition(2, 2 + lead.length())).insert("\n" + lead + " *").build();
    final TextChange output = interceptor.processChange(input, document);
    assertNotNull(output);
    final TextChange expected = new TextChange.Builder().from(new TextPosition(1, 2 + lead.length())).to(new TextPosition(3, 3 + lead.length())).insert("\n" + lead + " * " + "\n" + lead + " */").build();
    Assert.assertEquals(expected, output);
}
Also used : TextPosition(org.eclipse.che.ide.api.editor.text.TextPosition) TextChange(org.eclipse.che.ide.api.editor.changeintercept.TextChange)

Aggregations

TextPosition (org.eclipse.che.ide.api.editor.text.TextPosition)34 Position (org.eclipse.che.ide.api.editor.text.Position)9 TextChange (org.eclipse.che.ide.api.editor.changeintercept.TextChange)8 TextRange (org.eclipse.che.ide.api.editor.text.TextRange)7 Test (org.junit.Test)7 Document (org.eclipse.che.ide.api.editor.document.Document)6 RangeDTO (org.eclipse.che.api.languageserver.shared.lsapi.RangeDTO)5 Ignore (org.junit.Ignore)4 Annotation (org.eclipse.che.ide.api.editor.text.annotation.Annotation)3 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)3 Element (elemental.dom.Element)2 ArrayList (java.util.ArrayList)2 PositionDTO (org.eclipse.che.api.languageserver.shared.lsapi.PositionDTO)2 SymbolInformationDTO (org.eclipse.che.api.languageserver.shared.lsapi.SymbolInformationDTO)2 DocumentHandle (org.eclipse.che.ide.api.editor.document.DocumentHandle)2 TypedPosition (org.eclipse.che.ide.api.editor.text.TypedPosition)2 File (org.eclipse.che.ide.api.resources.File)2 Match (org.eclipse.che.plugin.languageserver.ide.filters.Match)2 Optional (com.google.common.base.Optional)1 Timer (com.google.gwt.user.client.Timer)1