use of org.eclipse.che.ide.api.editor.document.Document in project che by eclipse.
the class ParametersHintsPresenter method getLineStartOffset.
private int getLineStartOffset(TextEditor activeEditor, int offset) {
Document document = activeEditor.getDocument();
int lineIndex = document.getLineAtOffset(offset);
return document.getLineStart(lineIndex);
}
use of org.eclipse.che.ide.api.editor.document.Document in project che by eclipse.
the class JavaQuickAssistProcessor method computeQuickAssistProposals.
@Override
public void computeQuickAssistProposals(final QuickAssistInvocationContext quickAssistContext, final CodeAssistCallback callback) {
final TextEditor textEditor = quickAssistContext.getTextEditor();
final Document document = textEditor.getDocument();
LinearRange tempRange;
tempRange = textEditor.getSelectedLinearRange();
final LinearRange range = tempRange;
final boolean goToClosest = (range.getLength() == 0);
final QueryAnnotationsEvent.AnnotationFilter filter = new QueryAnnotationsEvent.AnnotationFilter() {
@Override
public boolean accept(final Annotation annotation) {
if (!(annotation instanceof JavaAnnotation)) {
return false;
} else {
JavaAnnotation javaAnnotation = (JavaAnnotation) annotation;
return (!javaAnnotation.isMarkedDeleted());
}
}
};
final QueryAnnotationsEvent.QueryCallback queryCallback = new QueryAnnotationsEvent.QueryCallback() {
@Override
public void respond(final Map<Annotation, Position> annotations) {
List<Problem> problems = new ArrayList<>();
/*final Map<Annotation, Position> problems =*/
int offset = collectQuickFixableAnnotations(range, document, annotations, goToClosest, problems);
if (offset != range.getStartOffset()) {
TextEditor presenter = ((TextEditor) textEditor);
presenter.getCursorModel().setCursorPosition(offset);
}
setupProposals(callback, textEditor, offset, problems);
}
};
final QueryAnnotationsEvent event = new QueryAnnotationsEvent.Builder().withFilter(filter).withCallback(queryCallback).build();
document.getDocumentHandle().getDocEventBus().fireEvent(event);
}
use of org.eclipse.che.ide.api.editor.document.Document 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);
}
}
Aggregations