Java Code Examples for com.intellij.openapi.editor.RangeMarker#setGreedyToRight()
The following examples show how to use
com.intellij.openapi.editor.RangeMarker#setGreedyToRight() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HaxeDocumentModel.java From intellij-haxe with Apache License 2.0 | 6 votes |
/** * Replace the text within the given range and reformat it according to the user's * code style/formatting rules. * * NOTE: The PSI may be entirely invalidated and re-created by this call. * * @param range Range of text or PsiElements to replace. * @param text Replacement text (may be null). */ public void replaceAndFormat(@NotNull final TextRange range, @Nullable String text) { if (null == text) { text = ""; } // Mark the beginning and end so that we have the proper range after adding text. // Greedy means that the text immediately added at the beginning/end of the marker are included. RangeMarker marker = document.createRangeMarker(range); marker.setGreedyToLeft(true); marker.setGreedyToRight(true); try { document.replaceString(range.getStartOffset(), range.getEndOffset(), text); //PsiDocumentManager.getInstance(file.getProject()).commitDocument(document); // force update PSI. if (marker.isValid()) { // If the range wasn't reduced to zero. CodeStyleManager.getInstance(file.getProject()).reformatText(file, marker.getStartOffset(), marker.getEndOffset()); } } finally { marker.dispose(); } }
Example 2
Source File: DocumentFragmentContent.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static RangeMarker createRangeMarker(@Nonnull Document document, @Nonnull TextRange range) { RangeMarker rangeMarker = document.createRangeMarker(range.getStartOffset(), range.getEndOffset(), true); rangeMarker.setGreedyToLeft(true); rangeMarker.setGreedyToRight(true); return rangeMarker; }
Example 3
Source File: GuardBlockTest.java From consulo with Apache License 2.0 | 5 votes |
public void testZero() throws Exception { configureFromFileText("x.txt", "xxxx"); RangeMarker guard = createGuard(0, 0); guard.setGreedyToLeft(true); guard.setGreedyToRight(true); checkUnableToTypeIn(0); checkCanTypeIn(1); }
Example 4
Source File: GuardBlockTest.java From consulo with Apache License 2.0 | 5 votes |
public void testGreedyEnd() throws Exception { configureFromFileText("x.txt", "012345678"); { RangeMarker guard = createGuard(0, 5); guard.setGreedyToLeft(true); guard.setGreedyToRight(true); } checkUnableToTypeIn(5); }
Example 5
Source File: TabOutScopesTrackerImpl.java From consulo with Apache License 2.0 | 5 votes |
private void registerScope(int offset, int caretShift) { RangeMarker marker = myEditor.getDocument().createRangeMarker(offset, offset); marker.setGreedyToLeft(true); marker.setGreedyToRight(true); if (caretShift > 1) marker.putUserData(CARET_SHIFT, caretShift); getCurrentScopes(true).add(marker); }
Example 6
Source File: TemplateSegments.java From consulo with Apache License 2.0 | 5 votes |
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); }
Example 7
Source File: TemplateSegments.java From consulo with Apache License 2.0 | 5 votes |
public void setNeighboursGreedy(final int segmentNumber, final boolean greedy) { if (segmentNumber > 0) { final RangeMarker left = mySegments.get(segmentNumber - 1); left.setGreedyToLeft(greedy); left.setGreedyToRight(greedy); } if (segmentNumber + 1 < mySegments.size()) { final RangeMarker right = mySegments.get(segmentNumber + 1); right.setGreedyToLeft(greedy); right.setGreedyToRight(greedy); } }
Example 8
Source File: TemplateSegments.java From consulo with Apache License 2.0 | 4 votes |
public void setSegmentsGreedy(boolean greedy) { for (final RangeMarker segment : mySegments) { segment.setGreedyToRight(greedy); segment.setGreedyToLeft(greedy); } }