Java Code Examples for com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil#getDocumentWindow()
The following examples show how to use
com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil#getDocumentWindow() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompletionInitializationUtil.java From consulo with Apache License 2.0 | 6 votes |
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; }
Example 2
Source File: QuickEditAction.java From consulo with Apache License 2.0 | 5 votes |
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; }
Example 3
Source File: QuickEditAction.java From consulo with Apache License 2.0 | 5 votes |
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; }