com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil#getDocumentWindow ( )源码实例Demo

下面列出了com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil#getDocumentWindow ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: consulo   文件: CompletionInitializationUtil.java
static OffsetsInFile toInjectedIfAny(PsiFile originalFile, OffsetsInFile hostCopyOffsets) {
  CompletionAssertions.assertHostInfo(hostCopyOffsets.getFile(), hostCopyOffsets.getOffsets());

  int hostStartOffset = hostCopyOffsets.getOffsets().getOffset(CompletionInitializationContext.START_OFFSET);
  OffsetsInFile translatedOffsets = hostCopyOffsets.toInjectedIfAny(hostStartOffset);
  if (translatedOffsets != hostCopyOffsets) {
    PsiFile injected = translatedOffsets.getFile();
    if (originalFile != injected && injected instanceof PsiFileImpl && InjectedLanguageManager.getInstance(originalFile.getProject()).isInjectedFragment(originalFile)) {
      ((PsiFileImpl)injected).setOriginalFile(originalFile);
    }
    DocumentWindow documentWindow = InjectedLanguageUtil.getDocumentWindow(injected);
    CompletionAssertions.assertInjectedOffsets(hostStartOffset, injected, documentWindow);

    if (injected.getTextRange().contains(translatedOffsets.getOffsets().getOffset(CompletionInitializationContext.START_OFFSET))) {
      return translatedOffsets;
    }
  }

  return hostCopyOffsets;
}
 
源代码2 项目: consulo   文件: QuickEditAction.java
public QuickEditHandler invokeImpl(@Nonnull final Project project, final Editor editor, PsiFile file) throws IncorrectOperationException {
  int offset = editor.getCaretModel().getOffset();
  Pair<PsiElement, TextRange> pair = ObjectUtils.assertNotNull(getRangePair(file, editor));

  PsiFile injectedFile = (PsiFile)pair.first;
  QuickEditHandler handler = getHandler(project, injectedFile, editor, file);

  if (!ApplicationManager.getApplication().isUnitTestMode()) {
    DocumentWindow documentWindow = InjectedLanguageUtil.getDocumentWindow(injectedFile);
    if (documentWindow != null) {
      handler.navigate(InjectedLanguageUtil.hostToInjectedUnescaped(documentWindow, offset));
    }
  }
  return handler;
}
 
源代码3 项目: consulo   文件: QuickEditAction.java
public static QuickEditHandler getExistingHandler(@Nonnull PsiFile injectedFile) {
  Place shreds = InjectedLanguageUtil.getShreds(injectedFile);
  DocumentWindow documentWindow = InjectedLanguageUtil.getDocumentWindow(injectedFile);
  if (shreds == null || documentWindow == null) return null;

  TextRange hostRange = TextRange.create(shreds.get(0).getHostRangeMarker().getStartOffset(),
                                         shreds.get(shreds.size() - 1).getHostRangeMarker().getEndOffset());
  for (Editor editor : EditorFactory.getInstance().getAllEditors()) {
    if (editor.getDocument() != documentWindow.getDelegate()) continue;
    QuickEditHandler handler = editor.getUserData(QUICK_EDIT_HANDLER);
    if (handler != null && handler.changesRange(hostRange)) return handler;
  }
  return null;
}