Search in sources :

Example 1 with MarkupHandler

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();
}
Also used : SyntaxInfo(com.intellij.openapi.editor.richcopy.model.SyntaxInfo) MarkupHandler(com.intellij.openapi.editor.richcopy.model.MarkupHandler) ColorRegistry(com.intellij.openapi.editor.richcopy.model.ColorRegistry)

Aggregations

ColorRegistry (com.intellij.openapi.editor.richcopy.model.ColorRegistry)1 MarkupHandler (com.intellij.openapi.editor.richcopy.model.MarkupHandler)1 SyntaxInfo (com.intellij.openapi.editor.richcopy.model.SyntaxInfo)1