Java Code Examples for com.intellij.openapi.editor.RangeMarker#getDocument()
The following examples show how to use
com.intellij.openapi.editor.RangeMarker#getDocument() .
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: Change.java From consulo with Apache License 2.0 | 6 votes |
/** * Applies the text from the original marker to the target marker. * @return the resulting TextRange from the target document, or null if the document if not writable. */ @Nullable private static TextRange modifyDocument(@Nonnull Project project, @Nonnull RangeMarker original, @Nonnull RangeMarker target) { Document document = target.getDocument(); if (!ReadonlyStatusHandler.ensureDocumentWritable(project, document)) { return null; } if (DocumentUtil.isEmpty(original)) { int offset = target.getStartOffset(); document.deleteString(offset, target.getEndOffset()); } String text = DocumentUtil.getText(original); int startOffset = target.getStartOffset(); if (DocumentUtil.isEmpty(target)) { document.insertString(startOffset, text); } else { document.replaceString(startOffset, target.getEndOffset(), text); } return new TextRange(startOffset, startOffset + text.length()); }
Example 2
Source File: DocumentUtil.java From consulo with Apache License 2.0 | 5 votes |
public static int getEndLine(RangeMarker range) { Document document = range.getDocument(); int endOffset = range.getEndOffset(); int endLine = document.getLineNumber(endOffset); if (document.getTextLength() == endOffset && lastLineIsNotEmpty(document, endLine)) { return document.getLineCount(); } return endLine; }
Example 3
Source File: LazyRangeMarkerFactoryImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nonnull public Document getDocument() { RangeMarker delegate = getOrCreateDelegate(); if (delegate == null) { //noinspection ConstantConditions return FileDocumentManager.getInstance().getDocument(myFile); } return delegate.getDocument(); }
Example 4
Source File: Bookmark.java From consulo with Apache License 2.0 | 5 votes |
public int getLine() { RangeMarker marker = myTarget.getRangeMarker(); if (marker != null && marker.isValid()) { Document document = marker.getDocument(); return document.getLineNumber(marker.getStartOffset()); } return myTarget.getLine(); }
Example 5
Source File: FragmentContent.java From consulo with Apache License 2.0 | 4 votes |
public static FragmentContent fromRangeMarker(RangeMarker rangeMarker, Project project) { Document document = rangeMarker.getDocument(); VirtualFile file = FileDocumentManager.getInstance().getFile(document); FileType type = file.getFileType(); return new FragmentContent(new DocumentContent(project, document), TextRange.create(rangeMarker), project, type); }
Example 6
Source File: DocumentUtil.java From consulo with Apache License 2.0 | 4 votes |
public static int getStartLine(RangeMarker range) { final Document doc = range.getDocument(); if (doc.getTextLength() == 0) return 0; return doc.getLineNumber(range.getStartOffset()); }