use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.
the class LightPlatformCodeInsightTestCase method checkResultByText.
/**
* Same as checkResultByFile but text is provided directly.
* @param message - this check specific message. Added to text, caret position, selection checking. May be null
* @param ignoreTrailingSpaces - whether trailing spaces in editor in data file should be stripped prior to comparing.
*/
protected void checkResultByText(final String message, @NotNull String expectedFileText, final boolean ignoreTrailingSpaces, final String filePath) {
bringRealEditorBack();
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
ApplicationManager.getApplication().runWriteAction(() -> {
final Document document = EditorFactory.getInstance().createDocument(expectedFileText);
if (ignoreTrailingSpaces) {
((DocumentImpl) document).stripTrailingSpaces(getProject());
}
EditorTestUtil.CaretAndSelectionState carets = EditorTestUtil.extractCaretAndSelectionMarkers(document);
PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
String newFileText = document.getText();
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
String fileText1 = myFile.getText();
String failMessage = getMessage("Text mismatch", message);
if (filePath != null && !newFileText.equals(fileText1)) {
throw new FileComparisonFailure(failMessage, newFileText, fileText1, filePath);
}
assertEquals(failMessage, newFileText, fileText1);
EditorTestUtil.verifyCaretAndSelectionState(myEditor, carets, message);
});
}
use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.
the class MultiHostRegistrarImpl method createDocument.
@NotNull
private static DocumentEx createDocument(@NotNull LightVirtualFile virtualFile) {
CharSequence content = virtualFile.getContent();
DocumentImpl document = new DocumentImpl(content, StringUtil.indexOf(content, '\r') >= 0, false);
FileDocumentManagerImpl.registerDocument(document, virtualFile);
return document;
}
use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.
the class EventLog method getStatusText.
private static String getStatusText(DocumentImpl logDoc, AtomicBoolean showMore, List<RangeMarker> lineSeparators, String indent, boolean hasHtml) {
DocumentImpl statusDoc = new DocumentImpl(logDoc.getImmutableCharSequence(), true);
List<RangeMarker> statusSeparators = new ArrayList<>();
for (RangeMarker separator : lineSeparators) {
if (separator.isValid()) {
statusSeparators.add(statusDoc.createRangeMarker(separator.getStartOffset(), separator.getEndOffset()));
}
}
removeJavaNewLines(statusDoc, statusSeparators, indent, hasHtml);
insertNewLineSubstitutors(statusDoc, showMore, statusSeparators);
return statusDoc.getText();
}
use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.
the class EventLog method formatForLog.
public static LogEntry formatForLog(@NotNull final Notification notification, final String indent) {
DocumentImpl logDoc = new DocumentImpl("", true);
AtomicBoolean showMore = new AtomicBoolean(false);
Map<RangeMarker, HyperlinkInfo> links = new LinkedHashMap<>();
List<RangeMarker> lineSeparators = new ArrayList<>();
String title = notification.getTitle();
String subtitle = notification.getSubtitle();
if (StringUtil.isNotEmpty(title) && StringUtil.isNotEmpty(subtitle)) {
title += " (" + subtitle + ")";
}
title = truncateLongString(showMore, title);
String content = truncateLongString(showMore, notification.getContent());
RangeMarker afterTitle = null;
boolean hasHtml = parseHtmlContent(addIndents(title, indent), notification, logDoc, showMore, links, lineSeparators);
if (StringUtil.isNotEmpty(title)) {
if (StringUtil.isNotEmpty(content)) {
appendText(logDoc, ": ");
afterTitle = logDoc.createRangeMarker(logDoc.getTextLength() - 2, logDoc.getTextLength());
}
}
int titleLength = logDoc.getTextLength();
hasHtml |= parseHtmlContent(addIndents(content, indent), notification, logDoc, showMore, links, lineSeparators);
List<AnAction> actions = notification.getActions();
if (!actions.isEmpty()) {
String text = "<p>" + StringUtil.join(actions, new Function<AnAction, String>() {
private int index;
@Override
public String fun(AnAction action) {
return "<a href=\"" + index++ + "\">" + action.getTemplatePresentation().getText() + "</a>";
}
}, isLongLine(actions) ? "<br>" : " ") + "</p>";
Notification n = new Notification("", "", ".", NotificationType.INFORMATION, new NotificationListener() {
@Override
public void hyperlinkUpdate(@NotNull Notification n, @NotNull HyperlinkEvent event) {
Notification.fire(notification, notification.getActions().get(Integer.parseInt(event.getDescription())));
}
});
if (title.length() > 0 || content.length() > 0) {
lineSeparators.add(logDoc.createRangeMarker(TextRange.from(logDoc.getTextLength(), 0)));
}
hasHtml |= parseHtmlContent(text, n, logDoc, showMore, links, lineSeparators);
}
String status = getStatusText(logDoc, showMore, lineSeparators, indent, hasHtml);
indentNewLines(logDoc, lineSeparators, afterTitle, hasHtml, indent);
ArrayList<Pair<TextRange, HyperlinkInfo>> list = new ArrayList<>();
for (RangeMarker marker : links.keySet()) {
if (!marker.isValid()) {
showMore.set(true);
continue;
}
list.add(Pair.create(new TextRange(marker.getStartOffset(), marker.getEndOffset()), links.get(marker)));
}
if (showMore.get()) {
String sb = "show balloon";
if (!logDoc.getText().endsWith(" ")) {
appendText(logDoc, " ");
}
appendText(logDoc, "(" + sb + ")");
list.add(new Pair<>(TextRange.from(logDoc.getTextLength() - 1 - sb.length(), sb.length()), new ShowBalloon(notification)));
}
return new LogEntry(logDoc.getText(), status, list, titleLength);
}
use of com.intellij.openapi.editor.impl.DocumentImpl in project intellij-community by JetBrains.
the class SyntaxInfoConstructionTest method initWithCustomLineSeparators.
private void initWithCustomLineSeparators(final String text) {
myFixture.configureByText(getTestName(true) + ".java", "");
final DocumentImpl document = (DocumentImpl) myFixture.getEditor().getDocument();
document.setAcceptSlashR(true);
ApplicationManager.getApplication().runWriteAction(() -> document.setText(text));
myFixture.doHighlighting();
}
Aggregations