コード例 #1
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;
 }
コード例 #2
0
 private int calculatePreferredWidth() {
   if (checkDirty()) return 1;
   assertValidState();
   VisualLinesIterator iterator = new VisualLinesIterator(myView, 0);
   int maxWidth = 0;
   while (!iterator.atEnd()) {
     int visualLine = iterator.getVisualLine();
     int width = myLineWidths.get(visualLine);
     if (width == UNKNOWN_WIDTH) {
       final Ref<Boolean> approximateValue = new Ref<Boolean>(Boolean.FALSE);
       width = getVisualLineWidth(iterator, () -> approximateValue.set(Boolean.TRUE));
       if (approximateValue.get()) width = -width;
       myLineWidths.set(visualLine, width);
     }
     maxWidth = Math.max(maxWidth, Math.abs(width));
     iterator.advance();
   }
   return maxWidth;
 }