本文整理汇总了Java中com.intellij.util.DocumentUtil类的典型用法代码示例。如果您正苦于以下问题:Java DocumentUtil类的具体用法?Java DocumentUtil怎么用?Java DocumentUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DocumentUtil类属于com.intellij.util包,在下文中一共展示了DocumentUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: saveIndent
import com.intellij.util.DocumentUtil; //导入依赖的package包/类
private static void saveIndent(AnswerPlaceholder placeholder, CCState state, boolean visible) {
Document document = state.getEditor().getDocument();
int offset = placeholder.getOffset();
int lineNumber = document.getLineNumber(offset);
int nonSpaceCharOffset = DocumentUtil.getFirstNonSpaceCharOffset(document, lineNumber);
int newOffset = offset;
int endOffset = offset + placeholder.getRealLength();
if (!visible && nonSpaceCharOffset == offset) {
newOffset = document.getLineStartOffset(lineNumber);
}
if (visible) {
newOffset = DocumentUtil.getFirstNonSpaceCharOffset(document, offset, endOffset);
}
placeholder.setOffset(newOffset);
int delta = offset - newOffset;
placeholder.setPossibleAnswer(document.getText(TextRange.create(newOffset, newOffset + delta + placeholder.getRealLength())));
String oldTaskText = placeholder.getTaskText();
if (delta >= 0) {
placeholder.setTaskText(StringUtil.repeat(" ", delta) + oldTaskText);
}
else {
String newTaskText = oldTaskText.substring(Math.abs(delta));
placeholder.setTaskText(newTaskText);
}
}
开发者ID:medvector,项目名称:educational-plugin,代码行数:26,代码来源:CCChangePlaceholderVisibility.java
示例2: actionPerformed
import com.intellij.util.DocumentUtil; //导入依赖的package包/类
public void actionPerformed(AnActionEvent e) {
Project project = e.getData(CommonDataKeys.PROJECT);
if (project == null) {
return;
}
DebuggerManagerEx debugManager = DebuggerManagerEx.getInstanceEx(project);
if (debugManager == null) {
return;
}
final BreakpointManager manager = debugManager.getBreakpointManager();
final PlaceInDocument place = getPlace(e);
if(place != null && DocumentUtil.isValidOffset(place.getOffset(), place.getDocument())) {
Breakpoint breakpoint = manager.findBreakpoint(place.getDocument(), place.getOffset(), MethodBreakpoint.CATEGORY);
if(breakpoint == null) {
manager.addMethodBreakpoint(place.getDocument(), place.getDocument().getLineNumber(place.getOffset()));
}
else {
manager.removeBreakpoint(breakpoint);
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:ToggleMethodBreakpointAction.java
示例3: getFirstElementOnTheLine
import com.intellij.util.DocumentUtil; //导入依赖的package包/类
@Nullable
public static PsiElement getFirstElementOnTheLine(PsiLambdaExpression lambda, Document document, int line) {
ApplicationManager.getApplication().assertReadAccessAllowed();
TextRange lineRange = DocumentUtil.getLineTextRange(document, line);
if (!intersects(lineRange, lambda)) return null;
PsiElement body = lambda.getBody();
if (body == null || !intersects(lineRange, body)) return null;
if (body instanceof PsiCodeBlock) {
for (PsiStatement statement : ((PsiCodeBlock)body).getStatements()) {
if (intersects(lineRange, statement)) {
return statement;
}
}
return null;
}
return body;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:DebuggerUtilsEx.java
示例4: createLineMarker
import com.intellij.util.DocumentUtil; //导入依赖的package包/类
@NotNull
public static List<RangeHighlighter> createLineMarker(@NotNull final Editor editor, int line, @NotNull final SeparatorPlacement placement,
@Nullable TextDiffType type, @NotNull LineSeparatorRenderer renderer, boolean applied) {
// We won't use addLineHighlighter as it will fail to add marker into empty document.
//RangeHighlighter highlighter = editor.getMarkupModel().addLineHighlighter(line, HighlighterLayer.SELECTION - 1, null);
int offset = DocumentUtil.getFirstNonSpaceCharOffset(editor.getDocument(), line);
RangeHighlighter highlighter = editor.getMarkupModel()
.addRangeHighlighter(offset, offset, LINE_MARKER_LAYER, null, HighlighterTargetArea.LINES_IN_RANGE);
highlighter.setLineSeparatorPlacement(placement);
highlighter.setLineSeparatorRenderer(renderer);
if (type == null || applied) return Collections.singletonList(highlighter);
TextAttributes stripeAttributes = getStripeTextAttributes(type, editor);
RangeHighlighter stripeHighlighter = editor.getMarkupModel()
.addRangeHighlighter(offset, offset, STRIPE_LAYER, stripeAttributes, HighlighterTargetArea.LINES_IN_RANGE);
return ContainerUtil.list(highlighter, stripeHighlighter);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:DiffDrawUtil.java
示例5: visit
import com.intellij.util.DocumentUtil; //导入依赖的package包/类
/**
* Read action will be taken automatically
*/
public static <RESULT> RESULT visit(@NotNull XSourcePosition position, @NotNull Project project, @NotNull Visitor<RESULT> visitor, RESULT defaultResult) {
AccessToken token = ReadAction.start();
try {
Document document = FileDocumentManager.getInstance().getDocument(position.getFile());
PsiFile file = document == null || document.getTextLength() == 0 ? null : PsiDocumentManager.getInstance(project).getPsiFile(document);
if (file == null) {
return defaultResult;
}
int positionOffset;
int column = position instanceof SourceInfo ? Math.max(((SourceInfo)position).getColumn(), 0) : 0;
try {
positionOffset = column == 0 ? DocumentUtil.getFirstNonSpaceCharOffset(document, position.getLine()) : document.getLineStartOffset(position.getLine()) + column;
}
catch (IndexOutOfBoundsException ignored) {
return defaultResult;
}
PsiElement element = file.findElementAt(positionOffset);
return element == null ? defaultResult : visitor.visit(element, positionOffset, document);
}
finally {
token.finish();
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:PsiVisitors.java
示例6: changedUpdateImpl
import com.intellij.util.DocumentUtil; //导入依赖的package包/类
@Override
protected void changedUpdateImpl(@NotNull DocumentEvent e) {
// todo Denis Zhdanov
DocumentEventImpl event = (DocumentEventImpl)e;
final boolean shouldTranslateViaDiff = isValid() && PersistentRangeMarkerUtil.shouldTranslateViaDiff(event, this);
boolean wasTranslatedViaDiff = shouldTranslateViaDiff;
if (shouldTranslateViaDiff) {
wasTranslatedViaDiff = translatedViaDiff(e, event);
}
if (!wasTranslatedViaDiff) {
super.changedUpdateImpl(e);
if (isValid()) {
myLine = getDocument().getLineNumber(getStartOffset());
int endLine = getDocument().getLineNumber(getEndOffset());
if (endLine != myLine) {
setIntervalEnd(getDocument().getLineEndOffset(myLine));
}
}
}
if (isValid() && getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) {
setIntervalStart(DocumentUtil.getFirstNonSpaceCharOffset(getDocument(), myLine));
setIntervalEnd(getDocument().getLineEndOffset(myLine));
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:PersistentRangeHighlighterImpl.java
示例7: executeWriteAction
import com.intellij.util.DocumentUtil; //导入依赖的package包/类
@Override
public void executeWriteAction(Editor editor, Caret caret, DataContext dataContext) {
if (editor.getSelectionModel().hasSelection()) {
int selStart = editor.getSelectionModel().getSelectionStart();
int selEnd = editor.getSelectionModel().getSelectionEnd();
if (selEnd > selStart && DocumentUtil.isAtLineStart(selEnd, editor.getDocument())) {
selEnd--;
}
VisualPosition rangeStart = editor.offsetToVisualPosition(Math.min(selStart, selEnd));
VisualPosition rangeEnd = editor.offsetToVisualPosition(Math.max(selStart, selEnd));
final Couple<Integer> copiedRange =
DuplicateAction.duplicateLinesRange(editor, editor.getDocument(), rangeStart, rangeEnd);
if (copiedRange != null) {
editor.getSelectionModel().setSelection(copiedRange.first, copiedRange.second);
}
}
else {
VisualPosition caretPos = editor.getCaretModel().getVisualPosition();
DuplicateAction.duplicateLinesRange(editor, editor.getDocument(), caretPos, caretPos);
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:DuplicateLinesAction.java
示例8: updateTextElement
import com.intellij.util.DocumentUtil; //导入依赖的package包/类
private void updateTextElement(final PsiElement elt) {
final String newText = getNewText(elt);
if (newText == null || Comparing.strEqual(newText, myEditor.getDocument().getText())) return;
DocumentUtil.writeInRunUndoTransparentAction(new Runnable() {
@Override
public void run() {
Document fragmentDoc = myEditor.getDocument();
fragmentDoc.setReadOnly(false);
fragmentDoc.replaceString(0, fragmentDoc.getTextLength(), newText);
fragmentDoc.setReadOnly(true);
myEditor.getCaretModel().moveToOffset(0);
myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
}
});
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:ImplementationViewComponent.java
示例9: reformatBlock
import com.intellij.util.DocumentUtil; //导入依赖的package包/类
private static void reformatBlock(final Project project, final Editor editor, final int startOffset, final int endOffset) {
PsiDocumentManager.getInstance(project).commitAllDocuments();
Runnable task = new Runnable() {
@Override
public void run() {
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
try {
CodeStyleManager.getInstance(project).reformatRange(file, startOffset, endOffset, true);
}
catch (IncorrectOperationException e) {
LOG.error(e);
}
}
};
if (endOffset - startOffset > 1000) {
DocumentUtil.executeInBulk(editor.getDocument(), true, task);
}
else {
task.run();
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:PasteHandler.java
示例10: addToHistoryInner
import com.intellij.util.DocumentUtil; //导入依赖的package包/类
@NotNull
protected String addToHistoryInner(@NotNull final TextRange textRange, @NotNull final EditorEx editor, boolean erase, final boolean preserveMarkup) {
ApplicationManager.getApplication().assertIsDispatchThread();
String result = addTextRangeToHistory(textRange, editor, preserveMarkup);
if (erase) {
DocumentUtil.writeInRunUndoTransparentAction(new Runnable() {
@Override
public void run() {
editor.getDocument().deleteString(textRange.getStartOffset(), textRange.getEndOffset());
}
});
}
// always scroll to end on user input
scrollToEnd();
return result;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:LanguageConsoleImpl.java
示例11: updateText
import com.intellij.util.DocumentUtil; //导入依赖的package包/类
public void updateText(@NotNull final Producer<String> contentProducer) {
myAlarm.cancelAllRequests();
myAlarm.addRequest(new Runnable() {
@Override
public void run() {
if (!isDisposed) {
final String newText = contentProducer.produce();
if (StringUtil.isEmpty(newText)) {
hide();
}
else if (!myEditor.getDocument().getText().equals(newText)) {
DocumentUtil.writeInRunUndoTransparentAction(new Runnable() {
@Override
public void run() {
myEditor.getDocument().setText(newText);
}
});
}
}
}
}, 100);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:EmmetPreviewHint.java
示例12: invokeOnTheFlyImportOptimizer
import com.intellij.util.DocumentUtil; //导入依赖的package包/类
public static void invokeOnTheFlyImportOptimizer(@NotNull final Runnable runnable,
@NotNull final PsiFile file,
@NotNull final Editor editor) {
final long stamp = editor.getDocument().getModificationStamp();
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
if (file.getProject().isDisposed() || editor.isDisposed() || editor.getDocument().getModificationStamp() != stamp) return;
//no need to optimize imports on the fly during undo/redo
final UndoManager undoManager = UndoManager.getInstance(editor.getProject());
if (undoManager.isUndoInProgress() || undoManager.isRedoInProgress()) return;
PsiDocumentManager.getInstance(file.getProject()).commitAllDocuments();
String beforeText = file.getText();
final long oldStamp = editor.getDocument().getModificationStamp();
DocumentUtil.writeInRunUndoTransparentAction(runnable);
if (oldStamp != editor.getDocument().getModificationStamp()) {
String afterText = file.getText();
if (Comparing.strEqual(beforeText, afterText)) {
String path = file.getViewProvider().getVirtualFile().getPath();
LOG.error("Import optimizer hasn't optimized any imports", new Attachment(path, afterText));
}
}
}
});
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:GroovyOptimizeImportsFix.java
示例13: reset
import com.intellij.util.DocumentUtil; //导入依赖的package包/类
public void reset() {
myDisplayName = myCopyrightProfile.getName();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
DocumentUtil.writeInRunUndoTransparentAction(new Runnable() {
@Override
public void run() {
myEditor.getDocument().setText(EntityUtil.decode(myCopyrightProfile.getNotice()));
}
});
}
});
myKeywordTf.setText(myCopyrightProfile.getKeyword());
myAllowReplaceTextField.setText(myCopyrightProfile.getAllowReplaceKeyword());
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:CopyrightConfigurable.java
示例14: done
import com.intellij.util.DocumentUtil; //导入依赖的package包/类
@Nonnull
public List<RangeHighlighter> done() {
// We won't use addLineHighlighter as it will fail to add marker into empty document.
//RangeHighlighter highlighter = editor.getMarkupModel().addLineHighlighter(line, HighlighterLayer.SELECTION - 1, null);
int offset = DocumentUtil.getFirstNonSpaceCharOffset(editor.getDocument(), line);
RangeHighlighter highlighter = editor.getMarkupModel()
.addRangeHighlighter(offset, offset, LINE_MARKER_LAYER, null, HighlighterTargetArea.LINES_IN_RANGE);
highlighter.setLineSeparatorPlacement(placement);
highlighter.setLineSeparatorRenderer(renderer);
highlighter.setLineMarkerRenderer(gutterRenderer);
if (type == null || resolved) return Collections.singletonList(highlighter);
TextAttributes stripeAttributes = getStripeTextAttributes(type, editor);
RangeHighlighter stripeHighlighter = editor.getMarkupModel()
.addRangeHighlighter(offset, offset, STRIPE_LAYER, stripeAttributes, HighlighterTargetArea.LINES_IN_RANGE);
return ContainerUtil.list(highlighter, stripeHighlighter);
}
开发者ID:consulo,项目名称:consulo,代码行数:22,代码来源:DiffDrawUtil.java
示例15: executeWriteCommand
import com.intellij.util.DocumentUtil; //导入依赖的package包/类
@RequiredDispatchThread
public static void executeWriteCommand(@javax.annotation.Nullable Project project,
@Nonnull Document document,
@javax.annotation.Nullable String commandName,
@javax.annotation.Nullable String commandGroupId,
@Nonnull UndoConfirmationPolicy confirmationPolicy,
boolean underBulkUpdate,
@Nonnull Runnable task) {
if (!makeWritable(project, document)) {
VirtualFile file = FileDocumentManager.getInstance().getFile(document);
LOG.warn("Document is read-only" + (file != null ? ": " + file.getPresentableName() : ""));
return;
}
ApplicationManager.getApplication().runWriteAction(() -> {
CommandProcessor.getInstance().executeCommand(project, () -> {
if (underBulkUpdate) {
DocumentUtil.executeInBulk(document, true, task);
}
else {
task.run();
}
}, commandName, commandGroupId, confirmationPolicy, document);
});
}
开发者ID:consulo,项目名称:consulo,代码行数:26,代码来源:DiffUtil.java
示例16: changedUpdateImpl
import com.intellij.util.DocumentUtil; //导入依赖的package包/类
@Override
protected void changedUpdateImpl(@Nonnull DocumentEvent e) {
// todo Denis Zhdanov
DocumentEventImpl event = (DocumentEventImpl)e;
final boolean shouldTranslateViaDiff = isValid() && PersistentRangeMarkerUtil.shouldTranslateViaDiff(event, getStartOffset(), getEndOffset());
boolean wasTranslatedViaDiff = shouldTranslateViaDiff;
if (shouldTranslateViaDiff) {
wasTranslatedViaDiff = translatedViaDiff(e, event);
}
if (!wasTranslatedViaDiff) {
super.changedUpdateImpl(e);
if (isValid()) {
myLine = getDocument().getLineNumber(getStartOffset());
int endLine = getDocument().getLineNumber(getEndOffset());
if (endLine != myLine) {
setIntervalEnd(getDocument().getLineEndOffset(myLine));
}
}
}
if (isValid() && getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) {
setIntervalStart(DocumentUtil.getFirstNonSpaceCharOffset(getDocument(), myLine));
setIntervalEnd(getDocument().getLineEndOffset(myLine));
}
}
开发者ID:consulo,项目名称:consulo,代码行数:25,代码来源:PersistentRangeHighlighterImpl.java
示例17: visualLineStartOffset
import com.intellij.util.DocumentUtil; //导入依赖的package包/类
private int visualLineStartOffset(int offset, boolean leanForward) {
EditorImpl editor = myView.getEditor();
offset = DocumentUtil.alignToCodePointBoundary(myDocument, offset);
int result = EditorUtil.getNotFoldedLineStartOffset(editor, offset);
SoftWrapModelImpl softWrapModel = editor.getSoftWrapModel();
List<? extends SoftWrap> softWraps = softWrapModel.getRegisteredSoftWraps();
int currentOrPrevWrapIndex = softWrapModel.getSoftWrapIndex(offset);
SoftWrap currentOrPrevWrap;
if (currentOrPrevWrapIndex < 0) {
currentOrPrevWrapIndex = - currentOrPrevWrapIndex - 2;
currentOrPrevWrap = currentOrPrevWrapIndex < 0 || currentOrPrevWrapIndex >= softWraps.size() ? null :
softWraps.get(currentOrPrevWrapIndex);
}
else {
currentOrPrevWrap = leanForward ? softWraps.get(currentOrPrevWrapIndex) : null;
}
if (currentOrPrevWrap != null && currentOrPrevWrap.getStart() > result) {
result = currentOrPrevWrap.getStart();
}
return result;
}
开发者ID:consulo,项目名称:consulo,代码行数:23,代码来源:EditorCoordinateMapper.java
示例18: calcOffset
import com.intellij.util.DocumentUtil; //导入依赖的package包/类
private static int calcOffset(@Nonnull Document document, int column, int startColumn, int startOffset, int endOffset, int tabSize) {
int currentColumn = startColumn;
CharSequence text = document.getImmutableCharSequence();
for (int i = startOffset; i < endOffset; i++) {
if (text.charAt(i) == '\t') {
currentColumn = (currentColumn / tabSize + 1) * tabSize;
}
else if (DocumentUtil.isSurrogatePair(document, i)) {
if (currentColumn == column) return i;
}
else {
currentColumn++;
}
if (currentColumn > column) return i;
}
return endOffset;
}
开发者ID:consulo,项目名称:consulo,代码行数:18,代码来源:LogicalPositionCache.java
示例19: changedUpdateImpl
import com.intellij.util.DocumentUtil; //导入依赖的package包/类
@Override
protected void changedUpdateImpl(@Nonnull DocumentEvent e) {
super.changedUpdateImpl(e);
if (isValid()) {
int startOffset = intervalStart();
int endOffset = intervalEnd();
if (DocumentUtil.isInsideSurrogatePair(getDocument(), startOffset)) setIntervalStart(startOffset - 1);
if (DocumentUtil.isInsideSurrogatePair(getDocument(), endOffset)) setIntervalStart(endOffset - 1);
}
if (endVirtualOffset > 0 && isValid()) {
Document document = e.getDocument();
int startAfter = intervalStart();
int endAfter = intervalEnd();
if (!DocumentUtil.isAtLineEnd(endAfter, document) || document.getLineNumber(startAfter) != document.getLineNumber(endAfter)) {
resetVirtualSelection();
}
}
}
开发者ID:consulo,项目名称:consulo,代码行数:19,代码来源:CaretImpl.java
示例20: validateState
import com.intellij.util.DocumentUtil; //导入依赖的package包/类
@TestOnly
public void validateState() {
Document document = myEditor.getDocument();
if (myEditor.getDocument().isInBulkUpdate()) return;
FoldingModel foldingModel = myEditor.getFoldingModel();
List<? extends SoftWrap> softWraps = getRegisteredSoftWraps();
int lastSoftWrapOffset = -1;
for (SoftWrap wrap : softWraps) {
int softWrapOffset = wrap.getStart();
LOG.assertTrue(softWrapOffset > lastSoftWrapOffset, "Soft wraps are not ordered");
LOG.assertTrue(softWrapOffset < document.getTextLength(), "Soft wrap is after document's end");
FoldRegion foldRegion = foldingModel.getCollapsedRegionAtOffset(softWrapOffset);
LOG.assertTrue(foldRegion == null || foldRegion.getStartOffset() == softWrapOffset, "Soft wrap is inside fold region");
LOG.assertTrue(softWrapOffset != DocumentUtil.getLineEndOffset(softWrapOffset, document)
|| foldRegion != null, "Soft wrap before line break");
LOG.assertTrue(softWrapOffset != DocumentUtil.getLineStartOffset(softWrapOffset, document) ||
foldingModel.isOffsetCollapsed(softWrapOffset - 1), "Soft wrap after line break");
LOG.assertTrue(!DocumentUtil.isInsideSurrogatePair(document, softWrapOffset), "Soft wrap inside a surrogate pair");
lastSoftWrapOffset = softWrapOffset;
}
}
开发者ID:consulo,项目名称:consulo,代码行数:22,代码来源:SoftWrapModelImpl.java
注:本文中的com.intellij.util.DocumentUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论