Example #1
0
 private void onTextLayoutPerformed(int startOffset, int endOffset) {
   if (checkDirty()) return;
   boolean purePaintingMode = myEditor.isPurePaintingMode();
   boolean foldingEnabled = myEditor.getFoldingModel().isFoldingEnabled();
   myEditor.setPurePaintingMode(false);
   myEditor.getFoldingModel().setFoldingEnabled(true);
   try {
     int startVisualLine = myView.offsetToVisualLine(startOffset, false);
     int endVisualLine = myView.offsetToVisualLine(endOffset, true);
     boolean sizeInvalidated = false;
     for (int i = startVisualLine; i <= endVisualLine; i++) {
       if (myLineWidths.get(i) < 0) {
         myLineWidths.set(i, UNKNOWN_WIDTH);
         sizeInvalidated = true;
       }
     }
     if (sizeInvalidated) {
       myWidthInPixels = -1;
       myEditor.getContentComponent().revalidate();
     }
   } finally {
     myEditor.setPurePaintingMode(purePaintingMode);
     myEditor.getFoldingModel().setFoldingEnabled(foldingEnabled);
   }
 }
  private boolean paintPlaceholderText(Graphics2D g) {
    CharSequence hintText = myEditor.getPlaceholder();
    EditorComponentImpl editorComponent = myEditor.getContentComponent();
    if (myDocument.getTextLength() > 0
        || hintText == null
        || hintText.length() == 0
        || KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == editorComponent
            && !myEditor.getShowPlaceholderWhenFocused()) {
      return false;
    }

    hintText =
        SwingUtilities.layoutCompoundLabel(
            g.getFontMetrics(),
            hintText.toString(),
            null,
            0,
            0,
            0,
            0,
            editorComponent.getBounds(),
            new Rectangle(),
            new Rectangle(),
            0);
    g.setColor(myEditor.getFoldingModel().getPlaceholderAttributes().getForegroundColor());
    g.setFont(myEditor.getColorsScheme().getFont(EditorFontType.PLAIN));
    g.drawString(hintText.toString(), 0, myView.getAscent());
    return true;
  }
Example #3
0
 int getVisualLineWidth(
     VisualLinesIterator visualLinesIterator, @Nullable Runnable quickEvaluationListener) {
   assert !visualLinesIterator.atEnd();
   int visualLine = visualLinesIterator.getVisualLine();
   FoldRegion[] topLevelRegions = myEditor.getFoldingModel().fetchTopLevel();
   if (quickEvaluationListener != null
       && (topLevelRegions == null || topLevelRegions.length == 0)
       && myEditor.getSoftWrapModel().getRegisteredSoftWraps().isEmpty()
       && !myView.getTextLayoutCache().hasCachedLayoutFor(visualLine)) {
     // fast path - speeds up editor opening
     quickEvaluationListener.run();
     return myView
             .getLogicalPositionCache()
             .offsetToLogicalColumn(
                 visualLine,
                 myDocument.getLineEndOffset(visualLine)
                     - myDocument.getLineStartOffset(visualLine))
         * myView.getMaxCharWidth();
   }
   float x = 0;
   int maxOffset = visualLinesIterator.getVisualLineStartOffset();
   for (VisualLineFragmentsIterator.Fragment fragment :
       VisualLineFragmentsIterator.create(myView, visualLinesIterator, quickEvaluationListener)) {
     x = fragment.getEndX();
     maxOffset = Math.max(maxOffset, fragment.getMaxOffset());
   }
   if (myEditor.getSoftWrapModel().getSoftWrap(maxOffset) != null) {
     x +=
         myEditor
             .getSoftWrapModel()
             .getMinDrawingWidthInPixels(SoftWrapDrawingType.BEFORE_SOFT_WRAP_LINE_FEED);
   }
   return (int) x;
 }
 EditorSizeManager(EditorView view) {
   myView = view;
   myEditor = view.getEditor();
   myDocument = myEditor.getDocument();
   myDocument.addDocumentListener(this, this);
   myEditor.getFoldingModel().addListener(this, this);
   myEditor.getSoftWrapModel().getApplianceManager().addListener(mySoftWrapChangeListener);
 }
Example #5
0
 void textLayoutPerformed(int startOffset, int endOffset) {
   if (myDocument.isInBulkUpdate()) return;
   if (myEditor.getFoldingModel().isInBatchFoldingOperation()) {
     myDeferredRanges.add(new TextRange(startOffset, endOffset));
   } else {
     onTextLayoutPerformed(startOffset, endOffset);
   }
 }
 private EditorWindow(
     @NotNull DocumentWindowImpl documentWindow,
     @NotNull final EditorImpl delegate,
     @NotNull PsiFile injectedFile,
     boolean oneLine) {
   myDocumentWindow = documentWindow;
   myDelegate = delegate;
   myInjectedFile = injectedFile;
   myOneLine = oneLine;
   myCaretModelDelegate = new CaretModelWindow(myDelegate.getCaretModel(), this);
   mySelectionModelDelegate = new SelectionModelWindow(myDelegate, myDocumentWindow, this);
   myMarkupModelDelegate =
       new MarkupModelWindow((MarkupModelEx) myDelegate.getMarkupModel(), myDocumentWindow);
   myFoldingModelWindow = new FoldingModelWindow(delegate.getFoldingModel(), documentWindow, this);
 }
Example #7
0
 private void onSoftWrapRecalculationEnd(IncrementalCacheUpdateEvent event) {
   if (myDocument.isInBulkUpdate()) return;
   boolean invalidate = true;
   if (myEditor.getFoldingModel().isInBatchFoldingOperation()) {
     myFoldingChangeStartOffset = Math.min(myFoldingChangeStartOffset, event.getStartOffset());
     myFoldingChangeEndOffset = Math.max(myFoldingChangeEndOffset, event.getActualEndOffset());
     invalidate = false;
   }
   if (myDocument.isInEventsHandling()) {
     myDocumentChangeStartOffset = Math.min(myDocumentChangeStartOffset, event.getStartOffset());
     myDocumentChangeEndOffset = Math.max(myDocumentChangeEndOffset, event.getActualEndOffset());
     invalidate = false;
   }
   if (invalidate) {
     doInvalidateRange(event.getStartOffset(), event.getActualEndOffset());
   }
 }
 private void paintHighlighterAfterEndOfLine(Graphics2D g, RangeHighlighterEx highlighter) {
   if (!highlighter.isAfterEndOfLine()) {
     return;
   }
   int startOffset = highlighter.getStartOffset();
   int lineEndOffset = myDocument.getLineEndOffset(myDocument.getLineNumber(startOffset));
   if (myEditor.getFoldingModel().isOffsetCollapsed(lineEndOffset)) return;
   Point lineEnd = myView.offsetToXY(lineEndOffset, true, false);
   int x = lineEnd.x;
   int y = lineEnd.y;
   TextAttributes attributes = highlighter.getTextAttributes();
   paintBackground(g, attributes, x, y, myView.getPlainSpaceWidth());
   if (attributes != null
       && hasTextEffect(attributes.getEffectColor(), attributes.getEffectType())) {
     paintTextEffect(
         g,
         x,
         x + myView.getPlainSpaceWidth() - 1,
         y + myView.getAscent(),
         attributes.getEffectColor(),
         attributes.getEffectType());
   }
 }
 private TextAttributes getFoldRegionAttributes(FoldRegion foldRegion) {
   TextAttributes foldAttributes = myEditor.getFoldingModel().getPlaceholderAttributes();
   TextAttributes selectionAttributes =
       isSelected(foldRegion) ? myEditor.getSelectionModel().getTextAttributes() : null;
   return mergeAttributes(selectionAttributes, foldAttributes);
 }