Package com.intellij.openapi.editor

Examples of com.intellij.openapi.editor.Document


                selectedText = selection.getSelectedText();
            }

            if (selectedText != null && selectedText.trim().length() > 0) {

                Document doc = editor.getDocument();
                VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(doc);
                String extension = null;
                if (virtualFile.getName().lastIndexOf(".") != -1) {
                    extension = virtualFile.getName().substring(virtualFile.getName().lastIndexOf(".") + 1, virtualFile.getName().length());
                }
View Full Code Here


      presentation.setIcon(DartIcons.Dart_16);
    }

    @Override
    public void handleInsert(InsertionContext context) {
      Document document = context.getDocument();
      int start = context.getStartOffset();
      int end = context.getTailOffset();
      if (start < 1 || end > document.getTextLength() - 1) return;
      CharSequence sequence = document.getCharsSequence();
      boolean left = sequence.charAt(start - 1) == sequence.charAt(start);
      boolean right = sequence.charAt(end - 1) == sequence.charAt(end);
      if (left || right) {
        document.replaceString(start, end, sequence.subSequence(left ? start + 1 : start, right ? end - 1 : end));
        if (right) {
          context.getEditor().getCaretModel().moveCaretRelatively(1, 0, false, false, true);
        }
      }
    }
View Full Code Here

    else {
      if (smartIntroduce(operation)) {
        return;
      }
      final CaretModel caretModel = editor.getCaretModel();
      final Document document = editor.getDocument();
      int lineNumber = document.getLineNumber(caretModel.getOffset());
      if ((lineNumber >= 0) && (lineNumber < document.getLineCount())) {
        element1 = file.findElementAt(document.getLineStartOffset(lineNumber));
        element2 = file.findElementAt(document.getLineEndOffset(lineNumber) - 1);
      }
    }
    final Project project = operation.getProject();
    if (element1 == null || element2 == null) {
      showCannotPerformError(project, editor);
View Full Code Here

        ApplicationManager.getApplication().runWriteAction(new Runnable() {
          @Override
          public void run() {
            VirtualFile virtualFile = VfsUtil.findFileByIoFile(configurationFile, false);
            if (virtualFile != null && virtualFile.isValid()) {
              Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
              if (document != null) {
                document.addDocumentListener(new DocumentAdapter() {
                  @Override
                  public void documentChanged(DocumentEvent e) {
                    myConfigChanged.set(true);
                  }
                }, parentDisposable);
View Full Code Here

  static Map<String, Object> getPubspecYamlInfo(final @NotNull VirtualFile pubspecYamlFile) {
    // do not use Yaml plugin here - IntelliJ IDEA Community Edition doesn't contain it.
    Pair<Long, Map<String, Object>> data = pubspecYamlFile.getUserData(MOD_STAMP_TO_PUBSPEC_NAME);

    final FileDocumentManager documentManager = FileDocumentManager.getInstance();
    final Document cachedDocument = documentManager.getCachedDocument(pubspecYamlFile);
    final Long currentTimestamp = cachedDocument != null ? cachedDocument.getModificationStamp() : pubspecYamlFile.getModificationCount();
    final Long cachedTimestamp = data == null ? null : data.first;

    if (cachedTimestamp == null || !cachedTimestamp.equals(currentTimestamp)) {
      data = null;
      pubspecYamlFile.putUserData(MOD_STAMP_TO_PUBSPEC_NAME, null);
      try {
        final Map<String, Object> pubspecYamlInfo;
        if (cachedDocument != null) {
          pubspecYamlInfo = loadPubspecYamlInfo(cachedDocument.getText());
        }
        else {
          pubspecYamlInfo = loadPubspecYamlInfo(VfsUtilCore.loadText(pubspecYamlFile));
        }
View Full Code Here

  public void beforeCharDeleted(char c, PsiFile file, Editor editor) {
    if (file.getLanguage() != CfmlLanguage.INSTANCE) return;
    if (c == '#') {
      if (CfmlEditorUtil.countSharpsBalance(editor) == 0) {
        final int offset = editor.getCaretModel().getOffset();
        final Document doc = editor.getDocument();
        char charAtOffset = DocumentUtils.getCharAt(doc, offset);
        if (charAtOffset == '#') {
          doc.deleteString(offset, offset + 1);
        }
      }
    }
    else if (c == '{' && file.findElementAt(editor.getCaretModel().getOffset()) == CfscriptTokenTypes.L_CURLYBRACKET) {
      final int offset = editor.getCaretModel().getOffset();
      final Document doc = editor.getDocument();
      char charAtOffset = DocumentUtils.getCharAt(doc, offset);
      if (charAtOffset == '}') {
        doc.deleteString(offset, offset + 1);
      }
    }
  }
View Full Code Here

    }
    return Result.CONTINUE;
  }

  public static boolean insertCloseTagIfNeeded(Editor editor, PsiFile file, Project project) {
    final Document document = editor.getDocument();
    final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);

    int offset = editor.getCaretModel().getOffset();
    documentManager.commitDocument(document);
    char charAtOffset = DocumentUtils.getCharAt(document, offset);

    if (charAtOffset != '>') {
      EditorModificationUtil.insertStringAtCaret(editor, ">", true, 0);
    }
    EditorModificationUtil.moveCaretRelatively(editor, 1);
    ++offset;
    if (DocumentUtils.getCharAt(document, offset - 2) == '/') {
      return false;
    }
    HighlighterIterator iterator = ((EditorEx)editor).getHighlighter().createIterator(offset - 2);

    while (!iterator.atEnd() && !iterator.getTokenType().equals(CfmlTokenTypes.CF_TAG_NAME)) {
      if (CfmlUtil.isControlToken(iterator.getTokenType())) {
        return false;
      }
      iterator.retreat();
    }
    if (!iterator.atEnd()) {
      iterator.retreat();
      if (!iterator.atEnd() && iterator.getTokenType().equals(CfmlTokenTypes.LSLASH_ANGLEBRACKET)) {
        return false;
      }
      iterator.advance();
    }
    if (iterator.atEnd()) {
      return false;
    }
    String tagName = document.getCharsSequence().subSequence(iterator.getStart(), iterator.getEnd()).toString();
    if (CfmlUtil.isSingleCfmlTag(tagName, project) || CfmlUtil.isUserDefined(tagName)) {
      return false;
    }
    PsiElement tagElement = file.findElementAt(iterator.getStart());
    while (tagElement != null && !(tagElement instanceof CfmlTag)) {
      tagElement = tagElement.getParent();
    }
    if (tagElement == null) {
      return false;
    }
    boolean doInsertion = false;
    if (tagElement.getLastChild() instanceof PsiErrorElement) {
      doInsertion = true;
    }
    else {
      iterator = ((EditorEx)editor).getHighlighter().createIterator(0);
      while (!iterator.atEnd() && iterator.getStart() < offset) {
        if (iterator.getTokenType() == CfmlTokenTypes.CF_TAG_NAME) {
          String currentTagName = document.getCharsSequence().subSequence(iterator.getStart(), iterator.getEnd()).toString();
          if (tagName.equals(currentTagName)) {
            PsiElement currentTagElement = file.findElementAt(iterator.getStart());
            currentTagElement = PsiTreeUtil.getParentOfType(currentTagElement, CfmlTag.class);
            if (currentTagElement.getLastChild() instanceof PsiErrorElement) {
              doInsertion = true;
View Full Code Here

  public static GrStepDefinition getStepDefinition(final GrMethodCall statement) {
    return CachedValuesManager.getCachedValue(statement, new CachedValueProvider<GrStepDefinition>() {
      @Nullable
      @Override
      public Result<GrStepDefinition> compute() {
        final Document document = PsiDocumentManager.getInstance(statement.getProject()).getDocument(statement.getContainingFile());
        return Result.create(new GrStepDefinition(statement), document);
      }
    });
  }
View Full Code Here

                                            final @NotNull String sdkPath) {
    AnalysisContext analysisContext = SoftReference.dereference(myAnalysisContextRef);

    final DartUrlResolver dartUrlResolver = DartUrlResolver.getInstance(myProject, annotatedFile);
    final VirtualFile yamlFile = dartUrlResolver.getPubspecYamlFile();
    final Document cachedDocument = yamlFile == null ? null : FileDocumentManager.getInstance().getCachedDocument(yamlFile);
    final long pubspecYamlTimestamp = yamlFile == null ? -1
                                                       : cachedDocument == null ? yamlFile.getModificationCount()
                                                                                : cachedDocument.getModificationStamp();

    final VirtualFile[] packageRoots = dartUrlResolver.getPackageRoots();

    final VirtualFile contentRoot = ProjectRootManager.getInstance(myProject).getFileIndex().getContentRootForFile(annotatedFile);
    final Module module = ModuleUtilCore.findModuleForFile(annotatedFile, myProject);
View Full Code Here

    return myFile.getPath();
  }

  @Override
  public long getModificationStamp() {
    final Document cachedDocument = FileDocumentManager.getInstance().getCachedDocument(myFile);
    if (cachedDocument != null) {
      return cachedDocument.getModificationStamp();
    }
    else {
      return myFile.getModificationStamp();
    }
  }
View Full Code Here

TOP

Related Classes of com.intellij.openapi.editor.Document

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.