Dimension getPreferredSize() { int width = getPreferredWidth(); if (!myDocument.isInBulkUpdate()) { for (Caret caret : myEditor.getCaretModel().getAllCarets()) { if (caret.isUpToDate()) { int caretX = myView.visualPositionToXY(caret.getVisualPosition()).x; width = Math.max(caretX, width); } } } width += myEditor.getSettings().getAdditionalColumnsCount() * myView.getPlainSpaceWidth(); return new Dimension(width, myEditor.getPreferredHeight()); }
Dimension getPreferredSize() { int widthWithoutCaret = getPreferredWidth(); int width = widthWithoutCaret; if (!myDocument.isInBulkUpdate()) { for (Caret caret : myEditor.getCaretModel().getAllCarets()) { if (caret.isUpToDate()) { int caretX = myView.visualPositionToXY(caret.getVisualPosition()).x; width = Math.max(caretX, width); } } } if (shouldRespectAdditionalColumns(widthWithoutCaret)) { width += myEditor.getSettings().getAdditionalColumnsCount() * myView.getPlainSpaceWidth(); } Insets insets = myView.getInsets(); return new Dimension(width + insets.left + insets.right, getPreferredHeight()); }
private void notifyBatchFoldingProcessingDone(final boolean moveCaretFromCollapsedRegion) { rebuild(); for (FoldingListener listener : myListeners) { listener.onFoldProcessingEnd(); } myEditor.updateCaretCursor(); myEditor.recalculateSizeAndRepaint(); myEditor.getGutterComponentEx().updateSize(); myEditor.getGutterComponentEx().repaint(); for (Caret caret : myEditor.getCaretModel().getAllCarets()) { // There is a possible case that caret position is already visual position aware. But visual // position depends on number of folded // logical lines as well, hence, we can't be sure that target logical position defines correct // visual position because fold // regions have just changed. Hence, we use 'raw' logical position instead. LogicalPosition caretPosition = caret.getLogicalPosition().withoutVisualPositionInfo(); int caretOffset = myEditor.logicalPositionToOffset(caretPosition); int selectionStart = caret.getSelectionStart(); int selectionEnd = caret.getSelectionEnd(); LogicalPosition positionToUse = null; int offsetToUse = -1; FoldRegion collapsed = myFoldTree.fetchOutermost(caretOffset); LogicalPosition savedPosition = caret.getUserData(SAVED_CARET_POSITION); if (savedPosition != null) { int savedOffset = myEditor.logicalPositionToOffset(savedPosition); FoldRegion collapsedAtSaved = myFoldTree.fetchOutermost(savedOffset); if (collapsedAtSaved == null) { positionToUse = savedPosition; } else { offsetToUse = collapsedAtSaved.getStartOffset(); } } if (collapsed != null && positionToUse == null) { positionToUse = myEditor.offsetToLogicalPosition(collapsed.getStartOffset()); } if (moveCaretFromCollapsedRegion && caret.isUpToDate()) { if (offsetToUse >= 0) { caret.moveToOffset(offsetToUse); } else if (positionToUse != null) { caret.moveToLogicalPosition(positionToUse); } else { caret.moveToLogicalPosition(caretPosition); } } caret.putUserData(SAVED_CARET_POSITION, savedPosition); if (isOffsetInsideCollapsedRegion(selectionStart) || isOffsetInsideCollapsedRegion(selectionEnd)) { caret.removeSelection(); } else if (selectionStart < myEditor.getDocument().getTextLength()) { caret.setSelection(selectionStart, selectionEnd); } } if (mySavedCaretShift > 0) { final ScrollingModel scrollingModel = myEditor.getScrollingModel(); scrollingModel.disableAnimation(); scrollingModel.scrollVertically( myEditor.visibleLineToY(myEditor.getCaretModel().getVisualPosition().line) - mySavedCaretShift); scrollingModel.enableAnimation(); } }