use of org.eclipse.che.ide.api.editor.document.DocumentHandle in project che by eclipse.
the class LanguageServerAnnotationModel method createPositionFromDiagnostic.
protected Position createPositionFromDiagnostic(final DiagnosticDTO diagnostic) {
DocumentHandle documentHandle = getDocumentHandle();
Document document = documentHandle.getDocument();
RangeDTO range = diagnostic.getRange();
int start = document.getIndexFromPosition(new TextPosition(range.getStart().getLine(), range.getStart().getCharacter()));
int end = document.getIndexFromPosition(new TextPosition(range.getEnd().getLine(), range.getEnd().getCharacter()));
if (start == -1 && end == -1) {
return new Position(0);
}
if (start == -1) {
return new Position(end);
}
if (end == -1) {
return new Position(start);
}
int length = end - start;
if (length < 0) {
return null;
}
return new Position(start, length);
}
use of org.eclipse.che.ide.api.editor.document.DocumentHandle in project che by eclipse.
the class EditorGroupSynchronizationImpl method updateContent.
private void updateContent(String newContent, String oldStamp, VirtualFile virtualFile) {
final DocumentHandle documentHandle = getDocumentHandleFor(groupLeaderEditor);
if (documentHandle == null) {
return;
}
final Document document = documentHandle.getDocument();
final String oldContent = document.getContents();
final TextPosition cursorPosition = document.getCursorPosition();
if (!(virtualFile instanceof File)) {
replaceContent(document, newContent, oldContent, cursorPosition);
return;
}
final File file = (File) virtualFile;
final String newStamp = file.getModificationStamp();
if (oldStamp == null && !Objects.equals(newContent, oldContent)) {
replaceContent(document, newContent, oldContent, cursorPosition);
return;
}
if (!Objects.equals(oldStamp, newStamp)) {
replaceContent(document, newContent, oldContent, cursorPosition);
notificationManager.notify("External operation", "File '" + file.getName() + "' is updated", SUCCESS, EMERGE_MODE);
}
}
use of org.eclipse.che.ide.api.editor.document.DocumentHandle in project che by eclipse.
the class EditorGroupSynchronizationImpl method addEditor.
@Override
public void addEditor(EditorPartPresenter editor) {
DocumentHandle documentHandle = getDocumentHandleFor(editor);
if (documentHandle != null) {
HandlerRegistration handlerRegistration = documentHandle.getDocEventBus().addHandler(DocumentChangeEvent.TYPE, this);
synchronizedEditors.put(editor, handlerRegistration);
}
}
use of org.eclipse.che.ide.api.editor.document.DocumentHandle in project che by eclipse.
the class EditorGroupSynchronizationImplTest method shouldNotApplyChangesFromNotActiveEditor.
@Test
public void shouldNotApplyChangesFromNotActiveEditor() {
DocumentHandle documentHandle1 = mock(DocumentHandle.class);
when(documentChangeEvent.getDocument()).thenReturn(documentHandle1);
when(documentHandle1.isSameAs(documentHandle)).thenReturn(false);
editorGroupSynchronization.onDocumentChange(documentChangeEvent);
verify(document, never()).replace(anyInt(), anyInt(), anyString());
}
use of org.eclipse.che.ide.api.editor.document.DocumentHandle in project che by eclipse.
the class EditorGroupSynchronizationImplTest method shouldApplyChangesFromActiveEditor.
@Test
public void shouldApplyChangesFromActiveEditor() {
int offset = 10;
int removeCharCount = 100;
String text = "someText";
when(documentChangeEvent.getOffset()).thenReturn(offset);
when(documentChangeEvent.getRemoveCharCount()).thenReturn(removeCharCount);
when(documentChangeEvent.getText()).thenReturn(text);
DocumentHandle documentHandle1 = mock(DocumentHandle.class);
when(documentChangeEvent.getDocument()).thenReturn(documentHandle1);
when(documentHandle1.isSameAs(documentHandle)).thenReturn(true);
editorGroupSynchronization.onDocumentChange(documentChangeEvent);
verify(document, times(2)).replace(eq(offset), eq(removeCharCount), eq(text));
}
Aggregations