当前位置: 首页>>代码示例>>Java>>正文


Java Editor.getDocument方法代码示例

本文整理汇总了Java中com.intellij.openapi.editor.Editor.getDocument方法的典型用法代码示例。如果您正苦于以下问题:Java Editor.getDocument方法的具体用法?Java Editor.getDocument怎么用?Java Editor.getDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.openapi.editor.Editor的用法示例。


在下文中一共展示了Editor.getDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: insertClosingTag

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
private static void insertClosingTag(@NotNull Editor editor, int offset, String tag) {
  Document document = editor.getDocument();
  CharSequence charSequence = document.getImmutableCharSequence();
  int startPosition = offset - 2;
  // Consume second left brace if present.
  if (offset > 0 && charSequence.charAt(startPosition - 1) == '{') {
    startPosition--;
  }
  int endPosition = offset;
  // Consume at most 2 right braces if present.
  while (endPosition < charSequence.length()
      && charSequence.charAt(endPosition) == '}'
      && endPosition < offset + 2) {
    endPosition++;
  }
  editor.getDocument().replaceString(startPosition, endPosition, tag);
  editor.getCaretModel().moveToOffset(startPosition + tag.length());

}
 
开发者ID:google,项目名称:bamboo-soy,代码行数:20,代码来源:ClosingTagHandler.java

示例2: handleEnterInComment

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
private static void handleEnterInComment(
    PsiElement element, @NotNull PsiFile file, @NotNull Editor editor) {
  if (element.getText().startsWith("/*")) {
    Document document = editor.getDocument();

    int caretOffset = editor.getCaretModel().getOffset();
    int lineNumber = document.getLineNumber(caretOffset);

    String lineTextBeforeCaret =
        document.getText(new TextRange(document.getLineStartOffset(lineNumber), caretOffset));
    String lineTextAfterCaret =
        document.getText(new TextRange(caretOffset, document.getLineEndOffset(lineNumber)));

    if (lineTextAfterCaret.equals("*/")) {
      return;
    }

    String toInsert = lineTextBeforeCaret.equals("") ? " * " : "* ";
    insertText(file, editor, toInsert, toInsert.length());
  }
}
 
开发者ID:google,项目名称:bamboo-soy,代码行数:22,代码来源:EnterHandler.java

示例3: postProcessEnter

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
@Override
public Result postProcessEnter(
    @NotNull PsiFile file, @NotNull Editor editor, @NotNull DataContext dataContext) {
  if (file.getFileType() != SoyFileType.INSTANCE) {
    return Result.Continue;
  }

  int caretOffset = editor.getCaretModel().getOffset();
  PsiElement element = file.findElementAt(caretOffset);
  Document document = editor.getDocument();

  int lineNumber = document.getLineNumber(caretOffset) - 1;
  int lineStartOffset = document.getLineStartOffset(lineNumber);
  String lineTextBeforeCaret = document.getText(new TextRange(lineStartOffset, caretOffset));

  if (element instanceof PsiComment && element.getTextOffset() < caretOffset) {
    handleEnterInComment(element, file, editor);
  } else if (lineTextBeforeCaret.startsWith("/*")) {
    insertText(file, editor, " * \n ", 3);
  }

  return Result.Continue;
}
 
开发者ID:google,项目名称:bamboo-soy,代码行数:24,代码来源:EnterHandler.java

示例4: actionPerformed

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
/**
 * Inserts the string generated by {@link #generateString()} at the caret(s) in the editor.
 *
 * @param event the performed action
 */
@Override
public final void actionPerformed(final AnActionEvent event) {
    final Editor editor = event.getData(CommonDataKeys.EDITOR);
    if (editor == null) {
        return;
    }
    final Project project = event.getData(CommonDataKeys.PROJECT);
    final Document document = editor.getDocument();
    final CaretModel caretModel = editor.getCaretModel();

    final Runnable replaceCaretSelections = () -> caretModel.getAllCarets().forEach(caret -> {
        final int start = caret.getSelectionStart();
        final int end = caret.getSelectionEnd();

        final String string = generateString();
        final int newEnd = start + string.length();

        document.replaceString(start, end, string);
        caret.setSelection(start, newEnd);
    });

    WriteCommandAction.runWriteCommandAction(project, replaceCaretSelections);
}
 
开发者ID:FWDekker,项目名称:intellij-randomness,代码行数:29,代码来源:DataInsertAction.java

示例5: drawAllAnswerPlaceholders

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
public static void drawAllAnswerPlaceholders(Editor editor, TaskFile taskFile) {
  editor.getMarkupModel().removeAllHighlighters();
  final Project project = editor.getProject();
  if (project == null) return;
  final StudyTaskManager taskManager = StudyTaskManager.getInstance(project);
  for (AnswerPlaceholder answerPlaceholder : taskFile.getAnswerPlaceholders()) {
    final JBColor color = taskManager.getColor(answerPlaceholder);
    EduAnswerPlaceholderPainter.drawAnswerPlaceholder(editor, answerPlaceholder, color);
  }

  final Document document = editor.getDocument();
  EditorActionManager.getInstance()
    .setReadonlyFragmentModificationHandler(document, new EduAnswerPlaceholderDeleteHandler(editor));
  EduAnswerPlaceholderPainter.createGuardedBlocks(editor, taskFile);
  editor.getColorsScheme().setColor(EditorColors.READONLY_FRAGMENT_BACKGROUND_COLOR, null);
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:17,代码来源:StudyUtils.java

示例6: createGuardedBlocks

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
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);
    }
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:17,代码来源:EduAnswerPlaceholderPainter.java

示例7: actionPerformed

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
    super.actionPerformed(e);
    dialog.show();
    int exitCode = dialog.getExitCode();
    if (exitCode != CANCEL_EXIT_CODE) {
        String key = dialog.getKeyText();
        String value = dialog.getValueText();
        currentLang = dialog.getSelectedLangauge();
        if (currentLang != null && !currentLang.isEmpty()) {
            Editor ieditor = editorMap.get(currentLang);
            Document document = ieditor.getDocument();
            WriteCommandAction.runWriteCommandAction(fileEditor.getProject(), () -> updateDocumentHook(document, ieditor.getProject(), currentLang, key, value, model));
        } else {
            NotificationHelper.showBaloon("No language file available", MessageType.WARNING, fileEditor.getProject());
        }
    }
}
 
开发者ID:PioBeat,项目名称:GravSupport,代码行数:19,代码来源:LanguageFileStrategy.java

示例8: applyFix

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor problemDescriptor) {
        List<PhpDocPropertyTag> propertyTags = this.comment.getPropertyTags();

        Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
        if (editor == null)
            return;
        Document document = editor.getDocument();
        PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document);
        TemplateManager templateManager = TemplateManager.getInstance(project);
        Template template = templateManager.createTemplate("", "");
        template.setToReformat(true);
        for (VirtualProperty missingProperty: this.missingProperties)
        {

            String propertyText = "* @property "+ (missingProperty.getType() != null ? missingProperty.getType() : "") + " $" +missingProperty.getName();
            if ( missingProperty.getComment() != null) {
                propertyText += " " + missingProperty.getComment();
            }
            template.addTextSegment("\n" + propertyText);
        }
        template.addTextSegment("\n");

        int offset =  comment.getLastChild().getTextOffset();
        if (propertyTags.size() > 0) {
            PhpDocPropertyTag phpDocPropertyTag = propertyTags.get(comment.getPropertyTags().size() - 1);
            offset = phpDocPropertyTag.getTextOffset() + phpDocPropertyTag.getTextLength();
        }
        editor.getCaretModel().moveToOffset(offset);
        PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(document);
        templateManager.startTemplate(editor, template);
}
 
开发者ID:nvlad,项目名称:yii2support,代码行数:33,代码来源:MissingPropertiesQuickFix.java

示例9: handleInsert

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
@Override
public void handleInsert(final InsertionContext context) {
    if (element.getParent() instanceof FieldReference) {
        final Editor     editor     = context.getEditor();
        final CaretModel caretModel = editor.getCaretModel();
        final Document   document   = editor.getDocument();

        document.insertString(caretModel.getOffset(), "()");
        caretModel.moveCaretRelatively(1, 0, false, false, false);
    }
}
 
开发者ID:rentalhost,项目名称:laravel-insight,代码行数:12,代码来源:ScopeCompletionContributor.java

示例10: actionPerformed

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
    super.actionPerformed(e);
    dialog.show();
    int exitCode = dialog.getExitCode();
    if (exitCode != CANCEL_EXIT_CODE) {
        String key = dialog.getKeyText();
        String value = dialog.getValueText();
        currentLang = dialog.getSelectedLangauge();
        if (currentLang != null && !currentLang.isEmpty()) {
            Editor ieditor = editorMap.get(currentLang);
            Document document = ieditor.getDocument();

            WriteCommandAction.runWriteCommandAction(fileEditor.getProject(), () -> {
                updateDocumentHook(document, ieditor.getProject(), currentLang, key, value, model);
                for (String eachLang : model.getLanguages()) {
                    if (!eachLang.equalsIgnoreCase(currentLang)) {
                        Editor ieditor1 = editorMap.get(eachLang);
                        Document document1 = ieditor1.getDocument();
                        updateDocumentHook(document1, ieditor1.getProject(), eachLang, key, "", model);
                    }
                }
                model.fireChange();
            });
        } else {
            NotificationHelper.showBaloon("No language file available", MessageType.WARNING, fileEditor.getProject());
        }
    }
}
 
开发者ID:PioBeat,项目名称:GravSupport,代码行数:30,代码来源:LanguageFolderStrategy.java

示例11: getSelectedText

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
/**
 * Returns the selected text if there is any selection. If not return all based on parameter
 *
 * @param defaultToAll If no selection, then this decides whether to return all text
 */
String getSelectedText(boolean defaultToAll) {
    ConsoleView console = this.getConsole();
    Editor myEditor = console != null ? (Editor) CommonDataKeys.EDITOR.getData((DataProvider) console) : null;
    if (myEditor != null) {
        Document document = myEditor.getDocument();
        final SelectionModel selectionModel = myEditor.getSelectionModel();
        if (selectionModel.hasSelection()) {
            return selectionModel.getSelectedText();
        } else if (defaultToAll) {
            return document.getText();
        }
    }
    return null;
}
 
开发者ID:josesamuel,项目名称:logviewer,代码行数:20,代码来源:LogView.java

示例12: getCurrentWords

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
private String getCurrentWords(Editor editor) {
    Document document = editor.getDocument();
    CaretModel caretModel = editor.getCaretModel();
    int caretOffset = caretModel.getOffset();
    int lineNum = document.getLineNumber(caretOffset);
    int lineStartOffset = document.getLineStartOffset(lineNum);
    int lineEndOffset = document.getLineEndOffset(lineNum);
    String lineContent = document.getText(new TextRange(lineStartOffset, lineEndOffset));
    char[] chars = lineContent.toCharArray();
    int start = 0, end = 0, cursor = caretOffset - lineStartOffset;

    if (!Character.isLetter(chars[cursor])) {
        return null;
    }

    for (int ptr = cursor; ptr >= 0; ptr--) {
        if (!Character.isLetter(chars[ptr])) {
            start = ptr + 1;
            break;
        }
    }

    int lastLetter = 0;
    for (int ptr = cursor; ptr < lineEndOffset - lineStartOffset; ptr++) {
        lastLetter = ptr;
        if (!Character.isLetter(chars[ptr])) {
            end = ptr;
            break;
        }
    }
    if (end == 0) {
        end = lastLetter + 1;
    }

    return new String(chars, start, end - start);
}
 
开发者ID:a483210,项目名称:GoogleTranslation,代码行数:37,代码来源:GoogleTranslation.java

示例13: editorCreated

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
@Override
public void editorCreated(@NotNull final EditorFactoryEvent event) {
  final Editor editor = event.getEditor();
  final Project project = editor.getProject();
  if (project == null) {
    return;
  }

  final Document document = editor.getDocument();
  final VirtualFile openedFile = FileDocumentManager.getInstance().getFile(document);
  if (openedFile != null) {
    final TaskFile taskFile = StudyUtils.getTaskFile(project, openedFile);
    if (taskFile != null) {
      WolfTheProblemSolver.getInstance(project).clearProblems(openedFile);
      final ToolWindow studyToolWindow = ToolWindowManager.getInstance(project).getToolWindow(StudyToolWindowFactory.STUDY_TOOL_WINDOW);
      if (studyToolWindow != null) {
        StudyUtils.updateToolWindows(project);
        studyToolWindow.show(null);
      }
      Course course = StudyTaskManager.getInstance(project).getCourse();
      if (course == null) {
        return;
      }

      StudyEditor.addDocumentListener(document, new EduDocumentListener(taskFile, true));

      if (!taskFile.getAnswerPlaceholders().isEmpty()) {
        StudyNavigator.navigateToFirstAnswerPlaceholder(editor, taskFile);
        boolean isStudyProject = EduNames.STUDY.equals(course.getCourseMode());
        StudyUtils.drawAllAnswerPlaceholders(editor, taskFile);
        if (isStudyProject) {
          editor.addEditorMouseListener(new WindowSelectionListener(taskFile));
        }
      }
    }
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:38,代码来源:StudyEditorFactoryListener.java

示例14: editorReleased

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
@Override
public void editorReleased(@NotNull EditorFactoryEvent event) {
  final Editor editor = event.getEditor();
  final Document document = editor.getDocument();
  StudyEditor.removeListener(document);
  editor.getMarkupModel().removeAllHighlighters();
  editor.getSelectionModel().removeSelection();
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:9,代码来源:StudyEditorFactoryListener.java

示例15: addPlaceholder

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
private void addPlaceholder(@NotNull CCState state) {
  Editor editor = state.getEditor();
  Project project = state.getProject();
  Document document = editor.getDocument();
  FileDocumentManager.getInstance().saveDocument(document);
  final SelectionModel model = editor.getSelectionModel();
  final int offset = model.hasSelection() ? model.getSelectionStart() : editor.getCaretModel().getOffset();
  TaskFile taskFile = state.getTaskFile();
  final Task task = state.getTaskFile().getTask();
  int subtaskIndex = task instanceof TaskWithSubtasks ? ((TaskWithSubtasks)task).getActiveSubtaskIndex() : 0;
  final AnswerPlaceholder answerPlaceholder = new AnswerPlaceholder();
  AnswerPlaceholderSubtaskInfo info = new AnswerPlaceholderSubtaskInfo();
  answerPlaceholder.getSubtaskInfos().put(subtaskIndex, info);
  int index = taskFile.getAnswerPlaceholders().size();
  answerPlaceholder.setIndex(index);
  answerPlaceholder.setTaskFile(taskFile);
  taskFile.sortAnswerPlaceholders();
  answerPlaceholder.setOffset(offset);
  answerPlaceholder.setUseLength(false);

  String defaultPlaceholderText = "type here";
  CCCreateAnswerPlaceholderDialog dlg = createDialog(project, answerPlaceholder);
  if (!dlg.showAndGet()) {
    return;
  }
  String answerPlaceholderText = dlg.getTaskText();
  answerPlaceholder.setPossibleAnswer(model.hasSelection() ? model.getSelectedText() : defaultPlaceholderText);
  answerPlaceholder.setTaskText(StringUtil.notNullize(answerPlaceholderText));
  answerPlaceholder.setLength(StringUtil.notNullize(answerPlaceholderText).length());
  answerPlaceholder.setHints(dlg.getHints());

  if (!model.hasSelection()) {
    DocumentUtil.writeInRunUndoTransparentAction(() -> document.insertString(offset, defaultPlaceholderText));
  }

  answerPlaceholder.setPossibleAnswer(model.hasSelection() ? model.getSelectedText() : defaultPlaceholderText);
  AddAction action = new AddAction(answerPlaceholder, taskFile, editor);
  EduUtils.runUndoableAction(project, "Add Answer Placeholder", action);
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:40,代码来源:CCAddAnswerPlaceholder.java


注:本文中的com.intellij.openapi.editor.Editor.getDocument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。