Java 类com.intellij.openapi.editor.textarea.TextComponentEditor 实例源码

项目:intellij-ce-playground    文件:TextComponentEditorAction.java   
@Nullable
public static Editor getEditorFromContext(@NotNull DataContext dataContext) {
  final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
  if (editor != null) return editor;
  final Object data = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);
  if (data instanceof JTextComponent) {
    return new TextComponentEditor(CommonDataKeys.PROJECT.getData(dataContext), (JTextComponent) data);
  }
  return null;
}
项目:tools-idea    文件:TextComponentEditorAction.java   
@Nullable
public static Editor getEditorFromContext(final DataContext dataContext) {
  final Editor editor = PlatformDataKeys.EDITOR.getData(dataContext);
  if (editor != null) return editor;
  final Object data = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);
  if (data instanceof JTextComponent) {
    return new TextComponentEditor(PlatformDataKeys.PROJECT.getData(dataContext), (JTextComponent) data);
  }
  return null;
}
项目:consulo    文件:EditorModificationUtil.java   
/**
 * @return true when not viewer
 *         false otherwise, additionally information hint with warning would be shown
 */
public static boolean checkModificationAllowed(Editor editor) {
  if (!editor.isViewer()) return true;
  if (ApplicationManager.getApplication().isHeadlessEnvironment() || editor instanceof TextComponentEditor) return false;

  HintManager.getInstance().showInformationHint(editor, EditorBundle.message("editing.viewer.hint"));
  return false;
}
项目:intellij-ce-playground    文件:EditorUtil.java   
public static int calcColumnNumber(@Nullable Editor editor, @NotNull CharSequence text, final int start, final int offset, final int tabSize) {
  if (editor instanceof TextComponentEditor) {
    return offset - start;
  }
  boolean useOptimization = true;
  if (editor != null) {
    SoftWrap softWrap = editor.getSoftWrapModel().getSoftWrap(start);
    useOptimization = softWrap == null;
  }
  boolean hasTabs = true;
  if (useOptimization) {
    if (editor instanceof EditorImpl && !((EditorImpl)editor).hasTabs()) {
      hasTabs = false;
    }
    else {
      boolean hasNonTabs = false;
      for (int i = start; i < offset; i++) {
        if (text.charAt(i) == '\t') {
          if (hasNonTabs) {
            useOptimization = false;
            break;
          }
        }
        else {
          hasNonTabs = true;
        }
      }
    }
  }

  if (editor == null || useOptimization) {
    Document document = editor == null ? null : editor.getDocument();
    if (document != null && start < offset-1 && document.getLineNumber(start) != document.getLineNumber(offset-1)) {
      String editorInfo = editor instanceof EditorImpl ? ". Editor info: " + ((EditorImpl)editor).dumpState() : "";
      String documentInfo;
      if (text instanceof Dumpable) {
        documentInfo = ((Dumpable)text).dumpState();
      }
      else {
        documentInfo = "Text holder class: " + text.getClass();
      }
      LogMessageEx.error(
        LOG, "detected incorrect offset -> column number calculation",
        "start: " + start + ", given offset: " + offset+", given tab size: " + tabSize + ". "+documentInfo+ editorInfo);
    }
    int shift = 0;
    if (hasTabs) {
      for (int i = start; i < offset; i++) {
        char c = text.charAt(i);
        if (c == '\t') {
          shift += getTabLength(i + shift - start, tabSize) - 1;
        }
      }
    }
    return offset - start + shift;
  }

  EditorEx editorImpl = (EditorEx) editor;
  return editorImpl.calcColumnNumber(text, start, offset, tabSize);
}
项目:intellij-ce-playground    文件:LineEndWithSelectionAction.java   
@Override
protected void doExecute(Editor editor, Caret caret, DataContext dataContext) {
  EditorActionUtil.moveCaretToLineEnd(editor, true, !(editor instanceof TextComponentEditor));
}
项目:intellij-ce-playground    文件:LineEndAction.java   
@Override
protected void doExecute(Editor editor, Caret caret, DataContext dataContext) {
  EditorActionUtil.moveCaretToLineEnd(editor, false, !(editor instanceof TextComponentEditor));
}
项目:consulo    文件:EditorUtil.java   
public static int calcColumnNumber(@Nullable Editor editor, @Nonnull CharSequence text, final int start, final int offset, final int tabSize) {
  if (editor instanceof TextComponentEditor) {
    return offset - start;
  }
  boolean useOptimization = true;
  if (editor != null) {
    SoftWrap softWrap = editor.getSoftWrapModel().getSoftWrap(start);
    useOptimization = softWrap == null;
  }
  if (useOptimization) {
    boolean hasNonTabs = false;
    for (int i = start; i < offset; i++) {
      if (text.charAt(i) == '\t') {
        if (hasNonTabs) {
          useOptimization = false;
          break;
        }
      }
      else {
        hasNonTabs = true;
      }
    }
  }

  if (editor != null && useOptimization) {
    Document document = editor.getDocument();
    if (start < offset - 1 && document.getLineNumber(start) != document.getLineNumber(offset - 1)) {
      String editorInfo = editor instanceof EditorImpl ? ". Editor info: " + ((EditorImpl)editor).dumpState() : "";
      String documentInfo;
      if (text instanceof Dumpable) {
        documentInfo = ((Dumpable)text).dumpState();
      }
      else {
        documentInfo = "Text holder class: " + text.getClass();
      }
      LogMessageEx.error(
              LOG, "detected incorrect offset -> column number calculation",
              "start: " + start + ", given offset: " + offset+", given tab size: " + tabSize + ". "+documentInfo+ editorInfo);
    }
  }

  int shift = 0;
  for (int i = start; i < offset; i++) {
    char c = text.charAt(i);
    if (c == '\t') {
      shift += getTabLength(i + shift - start, tabSize) - 1;
    }
  }
  return offset - start + shift;
}