use of com.intellij.openapi.editor.FoldRegion in project intellij-community by JetBrains.
the class VisualLineFragmentsIterator method init.
private void init(EditorView view, int startOffset, int startLogicalLine, int currentOrPrevWrapIndex, int nextFoldingIndex, @Nullable Runnable quickEvaluationListener) {
myQuickEvaluationListener = quickEvaluationListener;
myView = view;
EditorImpl editor = view.getEditor();
myDocument = editor.getDocument();
FoldingModelEx foldingModel = editor.getFoldingModel();
FoldRegion[] regions = foldingModel.fetchTopLevel();
myRegions = regions == null ? FoldRegion.EMPTY_ARRAY : regions;
SoftWrapModelImpl softWrapModel = editor.getSoftWrapModel();
List<? extends SoftWrap> softWraps = softWrapModel.getRegisteredSoftWraps();
SoftWrap currentOrPrevWrap = currentOrPrevWrapIndex < 0 || currentOrPrevWrapIndex >= softWraps.size() ? null : softWraps.get(currentOrPrevWrapIndex);
SoftWrap followingWrap = (currentOrPrevWrapIndex + 1) < 0 || (currentOrPrevWrapIndex + 1) >= softWraps.size() ? null : softWraps.get(currentOrPrevWrapIndex + 1);
myVisualLineStartOffset = mySegmentStartOffset = startOffset;
myCurrentFoldRegionIndex = nextFoldingIndex;
myCurrentEndLogicalLine = startLogicalLine;
myCurrentX = myView.getInsets().left;
if (mySegmentStartOffset == 0) {
myCurrentX += myView.getPrefixTextWidthInPixels();
} else if (currentOrPrevWrap != null && mySegmentStartOffset == currentOrPrevWrap.getStart()) {
myCurrentX += currentOrPrevWrap.getIndentInPixels();
myCurrentVisualColumn = currentOrPrevWrap.getIndentInColumns();
}
myNextWrapOffset = followingWrap == null ? Integer.MAX_VALUE : followingWrap.getStart();
setInlaysAndFragmentIterator();
}
use of com.intellij.openapi.editor.FoldRegion in project intellij-community by JetBrains.
the class PyConsoleStartFolding method addFolding.
private void addFolding(DocumentEvent event) {
Document document = myConsoleView.getEditor().getDocument();
if (doNotAddFoldingAgain || document.getTextLength() == 0) {
return;
}
if (myNumberOfCommandExecuted >= myNumberOfCommandToStop) {
document.removeDocumentListener(this);
return;
}
FoldingModel foldingModel = myConsoleView.getEditor().getFoldingModel();
foldingModel.runBatchFoldingOperation(() -> {
int start = myStartLineOffset;
int finish = document.getTextLength() - 1;
String placeholderText = DEFAULT_FOLDING_MESSAGE;
int firstLine = document.getLineNumber(myStartLineOffset);
for (int line = firstLine; line < document.getLineCount(); line++) {
String lineText = document.getText(DocumentUtil.getLineTextRange(document, line));
if (lineText.startsWith("Python")) {
if (start == myStartLineOffset) {
start = document.getLineStartOffset(line);
}
placeholderText = lineText;
break;
}
if (lineText.startsWith("PyDev console")) {
start = document.getLineStartOffset(line);
}
}
String newFragment = event.getNewFragment().toString();
if (newFragment.startsWith("In[") || newFragment.startsWith(PyConsoleUtil.ORDINARY_PROMPT)) {
finish = event.getOffset() - 1;
doNotAddFoldingAgain = true;
}
if (myStartFoldRegion != null) {
foldingModel.removeFoldRegion(myStartFoldRegion);
}
FoldRegion foldRegion = foldingModel.addFoldRegion(start, finish, placeholderText);
if (foldRegion != null) {
foldRegion.setExpanded(false);
myStartFoldRegion = foldRegion;
}
});
}
Aggregations