use of com.intellij.openapi.editor.richcopy.model.MarkupHandler in project intellij-community by JetBrains.
the class SyntaxInfoConstructionTest method getSyntaxInfo.
private static String getSyntaxInfo(Editor editor, PsiFile psiFile) {
final StringBuilder builder = new StringBuilder();
SelectionModel selectionModel = editor.getSelectionModel();
String selectedText = selectionModel.getSelectedText(true);
assertNotNull(selectedText);
final String text = StringUtil.convertLineSeparators(selectedText);
TextWithMarkupProcessor processor = new TextWithMarkupProcessor() {
@Override
void createResult(SyntaxInfo syntaxInfo, Editor editor) {
final ColorRegistry colorRegistry = syntaxInfo.getColorRegistry();
assertEquals(JBColor.BLACK, colorRegistry.dataById(syntaxInfo.getDefaultForeground()));
assertEquals(JBColor.WHITE, colorRegistry.dataById(syntaxInfo.getDefaultBackground()));
assertEquals((float) editor.getColorsScheme().getEditorFontSize(), syntaxInfo.getFontSize(), 0.01f);
syntaxInfo.processOutputInfo(new MarkupHandler() {
@Override
public void handleText(int startOffset, int endOffset) throws Exception {
builder.append("text=").append(text.substring(startOffset, endOffset)).append('\n');
}
@Override
public void handleForeground(int foregroundId) throws Exception {
builder.append("foreground=").append(colorRegistry.dataById(foregroundId)).append(',');
}
@Override
public void handleBackground(int backgroundId) throws Exception {
builder.append("background=").append(colorRegistry.dataById(backgroundId)).append(',');
}
@Override
public void handleFont(int fontNameId) throws Exception {
assertEquals(1, fontNameId);
}
@Override
public void handleStyle(int style) throws Exception {
builder.append("fontStyle=").append(style).append(',');
}
@Override
public boolean canHandleMore() {
return true;
}
});
}
};
processor.collectTransferableData(psiFile, editor, selectionModel.getBlockSelectionStarts(), selectionModel.getBlockSelectionEnds());
return builder.toString();
}
Aggregations