Package com.intellij.openapi.editor

Examples of com.intellij.openapi.editor.Document


        ApplicationManager.getApplication().runWriteAction(new Runnable() {

          public void run() {

            final Document document = editor.getDocument();

            CommandProcessor.getInstance().executeCommand(editor.getProject(), new Runnable() {
              public void run() {
                document.replaceString(0, document.getTextLength(), stringPropertyConverter.mergeComments(newDocumentContent, fileText));
              }
            }, "Property Sorter Plugin", null, UndoConfirmationPolicy.DO_NOT_REQUEST_CONFIRMATION);
          }
        });
        messageWindowComponent.say("Properties were sorted.");
View Full Code Here


      }
    }

    HaxeExpression haxeReturnStatementExpression = haxeReturnStatement.getExpression();
    if (haxeReturnStatementExpression != null) {
      Document doc = editor.getDocument();
      int offset = haxeReturnStatementExpression.getTextRange().getEndOffset();
      doc.insertString(offset, ";");
      editor.getCaretModel().moveToOffset(offset + 1);
      return true;
    }

    return false;
View Full Code Here

    if (StringUtil.endsWithChar(psiElement.getText(), ';')) {
      return false;
    }

    Document doc = editor.getDocument();
    int offset = psiElement.getTextRange().getEndOffset();
    doc.insertString(offset, ";");
    editor.getCaretModel().moveToOffset(offset + 1);
    return true;
  }
View Full Code Here

    return PsiDocumentManager.getInstance(project).getDocument(codeFragment);
  }

  @Nullable
  public static PsiElement getContextElement(VirtualFile virtualFile, int offset, final @NotNull Project project) {
    Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
    PsiFile file = PsiManager.getInstance(project).findFile(virtualFile);
    if (file == null || document == null) {
      return null;
    }

    if (offset < 0) offset = 0;
    if (offset > document.getTextLength()) offset = document.getTextLength();
    int startOffset = offset;

    int lineEndOffset = document.getLineEndOffset(document.getLineNumber(offset));
    PsiElement result = null;
    do {
      PsiElement element = file.findElementAt(offset);
      if (!(element instanceof PsiWhiteSpace) && !(element instanceof PsiComment)) {
        result = element;
View Full Code Here

public class Finders {

  public static Optional<PsiElement> findFirstElementAtLine(@NotNull final PsiFile file, Integer line) {
    if (line == null) return Optional.absent();
    int ijLine = line - 1;
    final Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
    Optional<PsiElement> element = Optional.absent();
    try {
      if (document != null) {
        final int offset = document.getLineStartOffset(ijLine);
        element = fromNullable(file.getViewProvider().findElementAt(offset));
        if (element.isPresent() && document.getLineNumber(element.get().getTextOffset()) != ijLine) {
          element = fromNullable(element.get().getNextSibling());
        }
      }
    } catch (@NotNull final IndexOutOfBoundsException ignore) {
      // Ignore this exception
    }

    while (element.isPresent() && element.get().getTextLength() == 0) {
      element = fromNullable(element.get().getNextSibling());
    }

    if (document != null && element.isPresent() && document.getLineNumber(element.get().getTextOffset()) != ijLine) {
      element = Optional.absent();
    }
    return element;
  }
View Full Code Here

  @NotNull
  public static TextRange getLineRange(@NotNull PsiFile psiFile, Integer line) {
    if (line == null) return TextRange.EMPTY_RANGE;
    Project project = psiFile.getProject();
    PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
    Document document = documentManager.getDocument(psiFile.getContainingFile());
    if (document == null) {
      return TextRange.EMPTY_RANGE;
    }
    int ijLine = line > 0 ? line - 1 : 0;
    return getTextRangeForLine(document, ijLine);
View Full Code Here

  }

  public static TextRange getLineRange(@NotNull PsiElement psiElement) {
    Project project = psiElement.getProject();
    PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
    Document document = documentManager.getDocument(psiElement.getContainingFile().getContainingFile());
    if (document == null) {
      return TextRange.EMPTY_RANGE;
    }
    int line = document.getLineNumber(psiElement.getTextOffset());
    int lineEndOffset = document.getLineEndOffset(line);
    return new TextRange(psiElement.getTextOffset(), lineEndOffset);
  }
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

    if (myUpdateOpenMustache != (targetBlockMustache instanceof HbOpenBlockMustache)) {
      targetBlockMustache = blockMustache.getPairedElement();
    }

    HbPath path = PsiTreeUtil.findChildOfType(targetBlockMustache, HbPath.class);
    final Document document = PsiDocumentManager.getInstance(project).getDocument(file);
    if (path != null && document != null) {
      final TextRange textRange = path.getTextRange();
      document.replaceString(textRange.getStartOffset(), textRange.getEndOffset(), myCorrectedName);
    }
  }
View Full Code Here

            return;
        }

        Editor editor = (Editor)event.getDataContext().getData(DataConstants.EDITOR);
        ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
        Document document = editor.getDocument();
        CaretModel caret = editor.getCaretModel();

        String componentName = findComponentName(document, caret.getOffset());
        if (componentName == null) {
            showError("cannot figure out component name", project);
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.