public static void createGuardedBlocks(@NotNull final Editor editor, AnswerPlaceholder placeholder) { Document document = editor.getDocument(); if (document instanceof DocumentImpl) { DocumentImpl documentImpl = (DocumentImpl)document; List<RangeMarker> blocks = documentImpl.getGuardedBlocks(); Pair<Integer, Integer> offsets = StudyUtils.getPlaceholderOffsets(placeholder, editor.getDocument()); Integer start = offsets.first; Integer end = offsets.second; if (start != 0) { createGuardedBlock(editor, blocks, start - 1, start); } if (end != document.getTextLength()) { createGuardedBlock(editor, blocks, end, end + 1); } } }
public void releaseUnused() { int iMax = myMarkers.size(); RangeMarker[] markers = new RangeMarker[myStashLimit]; int index = 0; for (int i = iMax; i-- > 0; ) { RangeMarker marker = myMarkers.get(i); if (index < myStashLimit && marker.isValid()) { markers[index++] = marker; } else { if (marker != null) marker.dispose(); } } myMarkers.clear(); for (int i = index; i-- > 0; ) { myMarkers.add(markers[i]); } }
@Override @NotNull public RangeMarker createRangeMarker(@NotNull final VirtualFile file, final int line, final int column, final boolean persistent) { return ApplicationManager.getApplication().runReadAction(new Computable<RangeMarker>() { @Override public RangeMarker compute() { final Document document = FileDocumentManager.getInstance().getCachedDocument(file); if (document != null) { int myTabSize = CodeStyleFacade.getInstance(myProject).getTabSize(file.getFileType()); final int offset = calculateOffset(document, line, column, myTabSize); return document.createRangeMarker(offset, offset, persistent); } final LazyMarker marker = new LineColumnLazyMarker(myProject, file, line, column); addToLazyMarkersList(marker, file); return marker; } }); }
@Override public String toString() { final String value; List<GradleEditorSourceBinding> bindings = getDefinitionValueSourceBindings(); if (bindings.isEmpty()) { value = "<undefined>"; } else if (bindings.size() > 1) { value = "<ref>"; } else { Document document = FileDocumentManager.getInstance().getDocument(bindings.get(0).getFile()); RangeMarker rangeMarker = bindings.get(0).getRangeMarker(); if (document == null) { value = "<unexpected!>"; } else { value = '[' + document.getCharsSequence().subSequence(rangeMarker.getStartOffset(), rangeMarker.getEndOffset()).toString() + ']'; } } return getName() + " " + value; }
public void testXHTMLRangeMarkers2() throws Exception { XmlTag tag = createTag("file.xhtml", "<a>xyz</a>"); PsiFile psiFile = tag.getContainingFile(); Document document = PsiDocumentManager.getInstance(psiFile.getProject()).getDocument(psiFile); RangeMarker rangeMarker = document.createRangeMarker(5, 5); final XmlText text = (XmlText) tag.getValue().getChildren()[0]; ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { @Override public void run() { try{ text.removeText(2, 3); } catch(IncorrectOperationException ioe){} } }, "", null, UndoConfirmationPolicy.DO_NOT_REQUEST_CONFIRMATION); } }); assertEquals(5, rangeMarker.getStartOffset()); assertEquals(5, rangeMarker.getEndOffset()); }
public static RangeMarker insertTemporary(final int endOffset, final Document document, final String temporary) { final CharSequence chars = document.getCharsSequence(); final int length = chars.length(); final RangeMarker toDelete; if (endOffset < length && Character.isJavaIdentifierPart(chars.charAt(endOffset))){ document.insertString(endOffset, temporary); toDelete = document.createRangeMarker(endOffset, endOffset + 1); } else if (endOffset >= length) { toDelete = document.createRangeMarker(length, length); } else { toDelete = document.createRangeMarker(endOffset, endOffset); } toDelete.setGreedyToLeft(true); toDelete.setGreedyToRight(true); return toDelete; }
private static void extract(final Document document, final Map<String, RangeMarker> sliceUsageName2Offset, final String name) { WriteCommandAction.runWriteCommandAction(null, new Runnable() { @Override public void run() { for (int i = 1; i < 9; i++) { String newName = name + i; String s = "<flown" + newName + ">"; if (!document.getText().contains(s)) break; int off = document.getText().indexOf(s); document.deleteString(off, off + s.length()); RangeMarker prev = sliceUsageName2Offset.put(newName, document.createRangeMarker(off, off)); assertNull(prev); extract(document, sliceUsageName2Offset, newName); } } }); }
private void updatePreviewPanel() { if (myProject.isDisposed()) return; List<UsageInfo> infos = new ArrayList<UsageInfo>(); final TreePath path = myTree.getSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); Object userObject = node.getUserObject(); if (userObject instanceof NodeDescriptor) { Object element = ((NodeDescriptor)userObject).getElement(); TodoItemNode pointer = myTodoTreeBuilder.getFirstPointerForElement(element); if (pointer != null) { final SmartTodoItemPointer value = pointer.getValue(); final Document document = value.getDocument(); final PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(document); final RangeMarker rangeMarker = value.getRangeMarker(); if (psiFile != null) { infos.add(new UsageInfo(psiFile, rangeMarker.getStartOffset(), rangeMarker.getEndOffset())); } } } } myUsagePreviewPanel.updateLayout(infos.isEmpty() ? null : infos); }
public void bind(@NotNull Project project, @NotNull List<GradleEditorSourceBinding> sourceBindings) { myProjectRef = new WeakReference<Project>(project); ImmutableListMultimap<VirtualFile, GradleEditorSourceBinding> byFile = Multimaps.index(sourceBindings, GROUPER); List<VirtualFile> orderedFiles = Lists.newArrayList(byFile.keySet()); ContainerUtil.sort(orderedFiles, FILES_COMPARATOR); for (VirtualFile file : orderedFiles) { ImmutableList<GradleEditorSourceBinding> list = byFile.get(file); List<RangeMarker> rangeMarkers = Lists.newArrayList(); for (GradleEditorSourceBinding descriptor : list) { rangeMarkers.add(descriptor.getRangeMarker()); } if (!rangeMarkers.isEmpty()) { ContainerUtil.sort(rangeMarkers, RANGE_COMPARATOR); String name = getRepresentativeName(project, file); mySourceBindings.put(name, rangeMarkers); myFilesByName.put(name, file); } } }
@Override public void inlineUsage(@NotNull UsageInfo usage, @NotNull PsiElement referenced) { PsiElement element=usage.getElement(); if (!(element instanceof GrExpression && element.getParent() instanceof GrCallExpression)) return; final Editor editor = getCurrentEditorIfApplicable(element); GrCallExpression call = (GrCallExpression) element.getParent(); RangeMarker marker = inlineReferenceImpl(call, myMethod, isOnExpressionOrReturnPlace(call), GroovyInlineMethodUtil.isTailMethodCall(call), editor); // highlight replaced result if (marker != null) { Project project = referenced.getProject(); TextRange range = TextRange.create(marker); GroovyRefactoringUtil.highlightOccurrencesByRanges(project, editor, new TextRange[]{range}); WindowManager.getInstance().getStatusBar(project).setInfo(GroovyRefactoringBundle.message("press.escape.to.remove.the.highlighting")); if (editor != null) { editor.getCaretModel().moveToOffset(marker.getEndOffset()); } } }
@Override protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException { if (PsiImplUtil.isWhiteSpaceOrNls(element)) { element = PsiTreeUtil.prevLeaf(element); } LOG.assertTrue(GeeseUtil.isClosureRBrace(element) && GeeseUtil.isClosureContainLF(element)); PsiDocumentManager.getInstance(project).commitAllDocuments(); PsiFile file = element.getContainingFile(); Document document = PsiDocumentManager.getInstance(project).getDocument(file); TextRange textRange = findRange(element); int startOffset = textRange.getStartOffset(); int endOffset = textRange.getEndOffset(); RangeMarker rangeMarker = document.createRangeMarker(textRange); String text = document.getText(); for (int i = endOffset - 1; i >= startOffset; i--) { if (text.charAt(i) == '\n') document.deleteString(i, i + 1); } CodeStyleManager.getInstance(project).reformatText(file, rangeMarker.getStartOffset(), rangeMarker.getEndOffset()); }
public static void deleteGuardedBlocks(@NotNull final Document document) { if (document instanceof DocumentImpl) { final DocumentImpl documentImpl = (DocumentImpl)document; List<RangeMarker> blocks = documentImpl.getGuardedBlocks(); for (final RangeMarker block : blocks) { ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runWriteAction(() -> document.removeGuardedBlock(block))); } } }
public void recallLastSelection(int offsetFromTop, boolean removeSelection, boolean swapWithCurrent) { RangeMarker marker = removeSelection ? myRangeMarkers.pop(offsetFromTop) : myRangeMarkers.get(offsetFromTop); if (marker != null) { if (swapWithCurrent && canSaveSelection()) { RangeMarker nextSelectionMarker = getCurrentSelectionMarker(); myRangeMarkers.push(nextSelectionMarker); } // recall the selection myEditor.getSelectionModel().setSelection(marker.getStartOffset(), marker.getEndOffset()); } }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } DocumentFoldingInfo info = (DocumentFoldingInfo)o; if (myFile != null ? !myFile.equals(info.myFile) : info.myFile != null) { return false; } if (!myProject.equals(info.myProject) || !myPsiElements.equals(info.myPsiElements) || !mySerializedElements.equals(info.mySerializedElements)) { return false; } if (myRangeMarkers.size() != info.myRangeMarkers.size()) return false; for (int i = 0; i < myRangeMarkers.size(); i++) { RangeMarker marker = myRangeMarkers.get(i); RangeMarker other = info.myRangeMarkers.get(i); if (marker == other || !marker.isValid() || !other.isValid()) { continue; } if (!TextRange.areSegmentsEqual(marker, other)) return false; FoldingInfo fi = marker.getUserData(FOLDING_INFO_KEY); FoldingInfo ofi = other.getUserData(FOLDING_INFO_KEY); if (!Comparing.equal(fi, ofi)) return false; } return true; }
public void testRangeMarker2() throws IOException, IncorrectOperationException { final XmlTag root = createTag("file.xhtml", "<a>1<b>234</b>567</a>"); final XmlTag tag = root.findFirstSubTag("b"); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { @Override public void run() { Document document = PsiDocumentManager.getInstance(getProject()).getDocument(root.getContainingFile()); XmlTagChild child = tag.getValue().getChildren()[0]; assertTrue(child instanceof XmlText && child.getText().equals("234")); try { tag.getParent().addBefore(child, tag); assertEquals(7, tag.getTextOffset()); RangeMarker marker = document.createRangeMarker(4, 7); tag.delete(); assertEquals(4, marker.getStartOffset()); assertEquals(7, marker.getEndOffset()); } catch (IncorrectOperationException e) { } } }, "", null); } }); }
@Override @NotNull public RangeMarker createRangeMarker(final int startOffset, final int endOffset, final boolean surviveOnExternalChange) { if (!surviveOnExternalChange) { return createRangeMarker(startOffset, endOffset); } ProperTextRange hostRange = injectedToHost(new ProperTextRange(startOffset, endOffset)); //todo persistent? RangeMarker hostMarker = myDelegate.createRangeMarker(hostRange.getStartOffset(), hostRange.getEndOffset(), surviveOnExternalChange); int startShift = Math.max(0, hostToInjected(hostRange.getStartOffset()) - startOffset); int endShift = Math.max(0, endOffset - hostToInjected(hostRange.getEndOffset()) - startShift); return new RangeMarkerWindow(this, (RangeMarkerEx)hostMarker, startShift, endShift); }
@NotNull protected PsiElement[] restoreOccurrences() { List<PsiElement> result = ContainerUtil.map(getOccurrenceMarkers(), new Function<RangeMarker, PsiElement>() { @Override public PsiElement fun(RangeMarker marker) { return PsiImplUtil.findElementInRange(myFile, marker.getStartOffset(), marker.getEndOffset(), GrExpression.class); } }); return PsiUtilCore.toPsiElementArray(result); }
public int getStoredIndex(RangeMarker other) { int index = 0; for (int i = myMarkers.size(); i-- > 0;) { RangeMarker marker = myMarkers.get(i); if (marker == null || !marker.isValid()) continue; if (marker.getStartOffset() == other.getStartOffset() && marker.getEndOffset() == other.getEndOffset()) { return index; } index++; } return -1; }
public boolean isStored(RangeMarker other) { for (RangeMarker marker : myMarkers) { if (marker == null || !marker.isValid()) continue; if (marker.getStartOffset() == other.getStartOffset() && marker.getEndOffset() == other.getEndOffset()) { return true; } } return false; }
@Nullable final RangeMarker getOrCreateDelegate() { if (myDelegate == null) { Document document = FileDocumentManager.getInstance().getDocument(myFile); if (document == null) { return null; } myDelegate = createDelegate(myFile, document); removeFromLazyMarkersList(this, myFile); } return isDisposed() ? null : myDelegate; }
@Override public void unescape(Document document, RangeMarker range) { final int start = range.getStartOffset(); for (int i = range.getEndOffset(); i >= start; i--) { if (CharArrayUtil.regionMatches(document.getCharsSequence(), i, ESCAPED_DOUBLE_DASH)) { document.replaceString(i, i + ESCAPED_DOUBLE_DASH.length(), DOUBLE_DASH); } } if (CharArrayUtil.regionMatches(document.getCharsSequence(), start, ESCAPED_GT)) { document.replaceString(start, start + ESCAPED_GT.length(), GT); } }
public void add(int index, int start, int end, boolean isStartAnchor, boolean isLine) { releaseUnused(); if (index < 0 || index >= myStashLimit) { throw new IllegalArgumentException("index "+index+" out of range of [0, " + myStashLimit + ")"); } RangeMarker marker = myManager.getEditor().getDocument().createRangeMarker(start, end); StashedSelection stashedSelection = new StashedSelection(marker, isStartAnchor, isLine); myCarets.add(index, stashedSelection); }
public static Map<String, RangeMarker> extractSliceOffsetsFromDocument(final Document document) { Map<String, RangeMarker> sliceUsageName2Offset = new THashMap<String, RangeMarker>(); extract(document, sliceUsageName2Offset, ""); int index = document.getText().indexOf("<flown"); if(index!=-1) { fail(document.getText().substring(index, Math.min(document.getText().length(), index+50))); } assertTrue(!sliceUsageName2Offset.isEmpty()); return sliceUsageName2Offset; }
private void surroundWithCodeBlock(@NotNull final MoveInfo info, final boolean down) { try { final Document document = PsiDocumentManager.getInstance(statementToSurroundWithCodeBlock.getProject()).getDocument(statementToSurroundWithCodeBlock.getContainingFile()); int startOffset = document.getLineStartOffset(info.toMove.startLine); int endOffset = getLineStartSafeOffset(document, info.toMove.endLine); if (document.getText().charAt(endOffset-1) == '\n') endOffset--; final RangeMarker lineRangeMarker = document.createRangeMarker(startOffset, endOffset); final PsiElementFactory factory = JavaPsiFacade.getInstance(statementToSurroundWithCodeBlock.getProject()).getElementFactory(); PsiCodeBlock codeBlock = factory.createCodeBlock(); codeBlock.add(statementToSurroundWithCodeBlock); final PsiBlockStatement blockStatement = (PsiBlockStatement)factory.createStatementFromText("{}", statementToSurroundWithCodeBlock); blockStatement.getCodeBlock().replace(codeBlock); PsiBlockStatement newStatement = (PsiBlockStatement)statementToSurroundWithCodeBlock.replace(blockStatement); newStatement = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(newStatement); info.toMove = new LineRange(document.getLineNumber(lineRangeMarker.getStartOffset()), document.getLineNumber(lineRangeMarker.getEndOffset())+1); PsiCodeBlock newCodeBlock = newStatement.getCodeBlock(); if (down) { PsiElement blockChild = firstNonWhiteElement(newCodeBlock.getFirstBodyElement(), true); if (blockChild == null) blockChild = newCodeBlock.getRBrace(); info.toMove2 = new LineRange(info.toMove2.startLine, //document.getLineNumber(newCodeBlock.getParent().getTextRange().getStartOffset()), document.getLineNumber(blockChild.getTextRange().getStartOffset())); } else { int start = document.getLineNumber(newCodeBlock.getRBrace().getTextRange().getStartOffset()); int end = info.toMove.startLine; if (start > end) end = start; info.toMove2 = new LineRange(start, end); } } catch (IncorrectOperationException e) { LOG.error(e); } }
public static FoldRegion[] getFoldRegionsAtOffset(Editor editor, int offset){ List<FoldRegion> list = new ArrayList<FoldRegion>(); FoldRegion[] allRegions = editor.getFoldingModel().getAllFoldRegions(); for (FoldRegion region : allRegions) { if (region.getStartOffset() <= offset && offset <= region.getEndOffset()) { list.add(region); } } FoldRegion[] regions = list.toArray(new FoldRegion[list.size()]); Arrays.sort(regions, Collections.reverseOrder(RangeMarker.BY_START_OFFSET)); return regions; }
@Override public boolean isValid() { RangeMarker delegate = myDelegate; if (delegate == null) { Document document = FileDocumentManager.getInstance().getDocument(myFile); return document != null; } return super.isValid(); }
private static void removeJavaNewLines(Document document, List<RangeMarker> lineSeparators, boolean hasHtml) { CharSequence text = document.getCharsSequence(); int i = 0; while (true) { i = StringUtil.indexOf(text, '\n', i); if (i < 0) break; document.deleteString(i, i + 1); if (!hasHtml) { lineSeparators.add(document.createRangeMarker(TextRange.from(i, 0))); } } }
@Override @NotNull public Document getDocument() { RangeMarker delegate = getOrCreateDelegate(); if (delegate == null) { //noinspection ConstantConditions return FileDocumentManager.getInstance().getDocument(myFile); } return delegate.getDocument(); }
public void testZero() throws Exception { myFixture.configureByText("x.txt", "xxxx"); RangeMarker guard = createGuard(0, 0); guard.setGreedyToLeft(true); guard.setGreedyToRight(true); checkUnableToTypeIn(0); checkCanTypeIn(1); }
public void replaceSegmentAt(int index, int start, int end, boolean preserveGreediness) { RangeMarker rangeMarker = mySegments.get(index); boolean greedyToLeft = rangeMarker.isGreedyToLeft(); boolean greedyToRight = rangeMarker.isGreedyToRight(); rangeMarker.dispose(); Document doc = myEditor.getDocument(); rangeMarker = doc.createRangeMarker(start, end); rangeMarker.setGreedyToLeft(greedyToLeft || !preserveGreediness); rangeMarker.setGreedyToRight(greedyToRight || !preserveGreediness); mySegments.set(index, rangeMarker); }
private static void appendTypeCasts(List<RangeMarker> occurrenceMarkers, PsiFile file, Project project, @Nullable PsiVariable psiVariable) { if (occurrenceMarkers != null) { for (RangeMarker occurrenceMarker : occurrenceMarkers) { final PsiElement refVariableElement = file.findElementAt(occurrenceMarker.getStartOffset()); final PsiReferenceExpression referenceExpression = PsiTreeUtil.getParentOfType(refVariableElement, PsiReferenceExpression.class); if (referenceExpression != null) { final PsiElement parent = referenceExpression.getParent(); if (parent instanceof PsiVariable) { createCastInVariableDeclaration(project, (PsiVariable)parent); } else if (parent instanceof PsiReferenceExpression && psiVariable != null) { final PsiExpression initializer = psiVariable.getInitializer(); LOG.assertTrue(initializer != null); final PsiType type = initializer.getType(); if (((PsiReferenceExpression)parent).resolve() == null && type != null) { final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project); final PsiExpression castedExpr = elementFactory.createExpressionFromText("((" + type.getCanonicalText() + ")" + referenceExpression.getText() + ")", parent); JavaCodeStyleManager.getInstance(project).shortenClassReferences(referenceExpression.replace(castedExpr)); } } } } } if (psiVariable != null && psiVariable.isValid()) { createCastInVariableDeclaration(project, psiVariable); } }
public void replaceElement(PsiElement element, String varName, Expression expression, boolean alwaysStopAt, boolean skipOnStart) { final RangeMarker key = wrapElement(element); myAlwaysStopAtMap.put(key, alwaysStopAt ? Boolean.TRUE : Boolean.FALSE); myVariableNamesMap.put(key, varName); mySkipOnStartMap.put(key, Boolean.valueOf(skipOnStart)); replaceElement(key, expression); }
@Nullable public static RangeMarker createRange(@NotNull Document document, @Nullable PsiElement expression) { if (expression == null) { return null; } TextRange range = expression.getTextRange(); return document.createRangeMarker(range.getStartOffset(), range.getEndOffset(), false); }
@NotNull private MappedRange insertMapping(int tokenIndex, IElementType outerToken) { CharSequence tokenText = getTokenText(tokenIndex); final int length = tokenText.length(); MappedRange predecessor = findPredecessor(tokenIndex); int insertOffset = predecessor != null ? predecessor.range.getEndOffset() : 0; doc.insertString(insertOffset, new MergingCharSequence(mySeparator, tokenText)); insertOffset += mySeparator.length(); RangeMarker marker = doc.createRangeMarker(insertOffset, insertOffset + length); return new MappedRange(this, marker, outerToken); }
public FragmentContent(@NotNull DiffContent original, @NotNull TextRange range, Project project, FileType fileType, boolean forceReadOnly) { RangeMarker rangeMarker = original.getDocument().createRangeMarker(range.getStartOffset(), range.getEndOffset(), true); rangeMarker.setGreedyToLeft(true); rangeMarker.setGreedyToRight(true); mySynchonizer = new MyDocumentsSynchronizer(project, rangeMarker); myOriginal = original; myType = fileType; myForceReadOnly = forceReadOnly; }
private void combineScopesWith(@NotNull final TextRange scope, final int fileLength, @NotNull final Document document) { dirtyScopes.transformValues(new TObjectFunction<RangeMarker, RangeMarker>() { @Override public RangeMarker execute(RangeMarker oldScope) { RangeMarker newScope = combineScopes(oldScope, scope, fileLength, document); if (newScope != oldScope && oldScope != null) { oldScope.dispose(); } return newScope; } }); }
/** * Removes given entity from the underlying source file if possible. * <p/> * <b>Note:</b> this method tried to preserve code style after removing the entity. * * @param entity an entity to remove * @return <code>null</code> as an indication that given entity was successfully removed; an error message otherwise */ @Nullable public static String removeEntity(@NotNull GradleEditorEntity entity, boolean commit) { GradleEditorSourceBinding location = entity.getEntityLocation(); RangeMarker marker = location.getRangeMarker(); if (!marker.isValid()) { return "source mapping is outdated for entity " + entity; } Document document = FileDocumentManager.getInstance().getDocument(location.getFile()); if (document == null) { return "can't find a document for file " + location.getFile(); } int startLine = document.getLineNumber(marker.getStartOffset()); int endLine = document.getLineNumber(marker.getEndOffset()); CharSequence text = document.getCharsSequence(); String ws = " \t"; int start = CharArrayUtil.shiftBackward(text, document.getLineStartOffset(startLine), marker.getStartOffset() - 1, ws); int end = CharArrayUtil.shiftForward(text, marker.getEndOffset(), document.getLineEndOffset(endLine), ws); if (start == document.getLineStartOffset(startLine) && startLine > 0) { start--; // Remove line feed at the end of the previous line. } else if (end == document.getLineEndOffset(endLine) && endLine < document.getLineCount() - 1) { end++; //Remove trailing line feed. } document.deleteString(start, end); if (commit) { PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(location.getProject()); psiDocumentManager.commitDocument(document); } return null; }
private static void indentNewLines(DocumentImpl logDoc, List<RangeMarker> lineSeparators, RangeMarker afterTitle, boolean hasHtml, String indent) { if (!hasHtml) { int i = -1; while (true) { i = StringUtil.indexOf(logDoc.getText(), '\n', i + 1); if (i < 0) { break; } lineSeparators.add(logDoc.createRangeMarker(i, i + 1)); } } if (!lineSeparators.isEmpty() && afterTitle != null && afterTitle.isValid()) { lineSeparators.add(afterTitle); } int nextLineStart = -1; for (RangeMarker separator : lineSeparators) { if (separator.isValid()) { int start = separator.getStartOffset(); if (start == nextLineStart) { continue; } logDoc.replaceString(start, separator.getEndOffset(), "\n" + indent); nextLineStart = start + 1 + indent.length(); while (nextLineStart < logDoc.getTextLength() && Character.isWhitespace(logDoc.getCharsSequence().charAt(nextLineStart))) { logDoc.deleteString(nextLineStart, nextLineStart + 1); } } } }
@Override @Nullable public RangeMarker createDelegate(@NotNull VirtualFile file, @NotNull Document document) { if (document.getTextLength() == 0 && !(myLine == 0 && myColumn == 0)) { return null; } int offset = calculateOffset(document, myLine, myColumn, myTabSize); return document.createRangeMarker(offset, offset); }
@Override protected void doActionPerformed(@NotNull GradleEditorEntity entity, AnActionEvent event) { if (entity instanceof GradleEntityDefinitionValueLocationAware) { GradleEditorSourceBinding location = ((GradleEntityDefinitionValueLocationAware)entity).getDefinitionValueLocation(); if (location != null) { RangeMarker marker = location.getRangeMarker(); if (marker.isValid()) { OpenFileDescriptor descriptor = new OpenFileDescriptor(location.getProject(), location.getFile(), marker.getStartOffset()); if (descriptor.canNavigate()) { descriptor.navigate(true); } } } } }