From 6a18f36447870a7f0c45de09f1f67d06dbfc6e21 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Fri, 25 Mar 2022 09:06:58 +0100 Subject: [PATCH] documents.md: improve "how do i get..." section --- .../architectural_overview/documents.md | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/topics/basics/architectural_overview/documents.md b/topics/basics/architectural_overview/documents.md index 4bc627b66..b013d4ce7 100644 --- a/topics/basics/architectural_overview/documents.md +++ b/topics/basics/architectural_overview/documents.md @@ -1,6 +1,6 @@ [//]: # (title: Documents) - + A [`Document`](upsource:///platform/core-api/src/com/intellij/openapi/editor/Document.java) is an editable sequence of Unicode characters, typically corresponding to the text contents of a [virtual file](virtual_file.md). @@ -9,18 +9,11 @@ The IntelliJ Platform handles encoding and line break conversions when loading a ## How do I get a Document? -#### From an Action - -`AnActionEvent.getData(CommonDataKeys.EDITOR).getDocument()` - -#### From a Virtual File - -`FileDocumentManager.getDocument()`. This call forces the document content to be loaded from disk if it wasn't loaded previously. -If only open documents or documents which may have been modified are considered relevant, use `FileDocumentManager.getCachedDocument()` instead. - -#### From a PSI File - -`PsiDocumentManager.getInstance().getDocument()` or `PsiDocumentManager.getInstance().getCachedDocument()` +| Context | API | +|----------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| [Action](basic_action_system.md) | [`AnActionEvent.getData(CommonDataKeys.EDITOR).getDocument()`](upsource:///platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnActionEvent.java) | +| [PSI File](psi_files.md) | [`PsiDocumentManager.getInstance(project).getDocument()`/`getCachedDocument()`](upsource:///platform/core-api/src/com/intellij/psi/PsiDocumentManager.java) | +| [Virtual File](virtual_file.md) | [`FileDocumentManager.getDocument()`](upsource:///platform/core-api/src/com/intellij/openapi/fileEditor/FileDocumentManager.java) (forces the document content to be loaded from a disk if it wasn't loaded previously)
[`FileDocumentManager.getCachedDocument()`](upsource:///platform/core-api/src/com/intellij/openapi/fileEditor/FileDocumentManager.java) (use if only open or possibly modified documents are relevant) | ## What can I do with a Document?