@Override public void documentChanged(@NotNull DocumentEvent event) { templatesListPanel.updateContent(event.getDocument().getText()); } });
/** * This event indicates that a document was just changed. We use this event to update all the editor's * marks if text was just added. * * @param event The change event */ public void documentChanged(@NotNull DocumentEvent event) { if (!VimPlugin.isEnabled()) return; if (logger.isDebugEnabled()) logger.debug("MarkUpdater after, event = " + event); if (event.getNewLength() == 0 || (event.getNewLength() == 1 && event.getNewFragment().charAt(0) != '\n')) return; Document doc = event.getDocument(); updateMarkFromInsert(getAnEditor(doc), VimPlugin.getMark().getAllFileMarks(doc), event.getOffset(), event.getNewLength()); // TODO - update jumps }
/** * This event indicates that a document is about to be changed. We use this event to update all the * editor's marks if text is about to be deleted. * * @param event The change event */ public void beforeDocumentChange(@NotNull DocumentEvent event) { if (!VimPlugin.isEnabled()) return; if (logger.isDebugEnabled()) logger.debug("MarkUpdater before, event = " + event); if (event.getOldLength() == 0) return; Document doc = event.getDocument(); updateMarkFromDelete(getAnEditor(doc), VimPlugin.getMark().getAllFileMarks(doc), event.getOffset(), event.getOldLength()); // TODO - update jumps }
Editor[] editors = EditorFactory.getInstance().getEditors(event.getDocument(), proj); for (Editor editor : editors) { Collection hls = EditorData.getLastHighlights(editor);
private void addFileFromEventToChangedFiles(DocumentEvent e) { final Optional<VirtualFile> file = Optional.ofNullable(FileDocumentManager.getInstance().getFile(e.getDocument())); file.ifPresent(CHANGED_FILES::add); } }
@Override public void documentChanged(DocumentEvent event) { if (!globalSettings.isAutoTrigger()) { return; } VirtualFile file = docManager.getFile(event.getDocument()); if (file == null) { return; } Project project = utils.guessProjectForFile(file); if (project == null || !project.equals(myProject)) { return; } eventMap.put(file, System.currentTimeMillis()); }
/** removes issues without highlighter (highlighter was removed in editor) by iterating over all issues from remaining highlighters and updating the issues index @param documentEvent triggered the change of the document @param project the document belongs to */ private Optional<VirtualFile> removeIssuesDeletedInEditor(DocumentEvent documentEvent,Project project) { final Optional<VirtualFile> file = Optional.ofNullable(FileDocumentManager.getInstance().getFile( documentEvent.getDocument() )); if (file.isPresent()) { Set<SonarIssue> issuesFromHighlighters = Sets.newLinkedHashSet(); Set<RangeHighlighter> highlighters = Finders.findAllRangeHighlightersFrom(documentEvent.getDocument()); retrieveIssuesFromHighlighters(issuesFromHighlighters,highlighters); final Optional<IssuesByFileIndexProjectComponent> indexComponent = IssuesByFileIndexProjectComponent.getInstance(project); if (indexComponent.isPresent()) { final Map<String,Set<SonarIssue>> index = indexComponent.get().getIndex(); index.put(file.get().getPath(),issuesFromHighlighters); } } return file; }
@Override public void documentChanged(DocumentEvent event) { Document document = event.getDocument(); VirtualFile file = FileDocumentManager.getInstance().getFile(document); if (file != null) { soyCacheUpdater.updateCache(file); } } });
private void updateIssuesPositions(final DocumentEvent e,final Project project) { final Optional<Document> document = Optional.ofNullable(e.getDocument()); final List<Editor> editors = Finders.findEditorsFrom(document.get()); for (final Editor editor : editors) { ApplicationManager.getApplication().invokeLater( () -> { updateIssueLines(document,editor); final Optional<VirtualFile> file = removeIssuesDeletedInEditor(e,project); updateHighlightingFor(file,project); } ); } }
@Test public void dont_trigger_if_no_vfile() { Document doc = mock(Document.class); DocumentEvent event = mock(DocumentEvent.class); when(event.getDocument()).thenReturn(doc); when(docManager.getFile(doc)).thenReturn(null); listener.documentChanged(event); verifyZeroInteractions(submitter); }
@Override public void documentChanged(DocumentEvent e) { Document document = e.getDocument(); VirtualFile file = fileManager.getFile(document); PsiFile psiFile = file == null ? null : psiManager.findFile(file); if (psiFile instanceof BnfFile) { LIVE_PREVIEW_ALARM.getValue(project).cancelAndRequest(); } } }, project);
@Test public void dont_trigger_if_no_project() { VirtualFile file = mock(VirtualFile.class); Document doc = mock(Document.class); DocumentEvent event = mock(DocumentEvent.class); when(file.isValid()).thenReturn(true); when(event.getDocument()).thenReturn(doc); when(docManager.getFile(doc)).thenReturn(file); when(utils.guessProjectForFile(file)).thenReturn(null); listener.documentChanged(event); verifyZeroInteractions(submitter); }
@Test public void dont_trigger_if_check_fails() { Module m1 = mock(Module.class); VirtualFile file = mock(VirtualFile.class); Document doc = mock(Document.class); DocumentEvent event = mock(DocumentEvent.class); when(file.isValid()).thenReturn(true); when(event.getDocument()).thenReturn(doc); when(docManager.getFile(doc)).thenReturn(file); when(utils.guessProjectForFile(file)).thenReturn(project); when(utils.findModuleForFile(file, project)).thenReturn(m1); listener.documentChanged(event); verifyZeroInteractions(submitter); }
@Test public void dont_trigger_if_auto_disabled() { globalSettings.setAutoTrigger(false); Module m1 = mock(Module.class); VirtualFile file = mock(VirtualFile.class); Document doc = mock(Document.class); DocumentEvent event = mock(DocumentEvent.class); when(file.isValid()).thenReturn(true); when(event.getDocument()).thenReturn(doc); when(docManager.getFile(doc)).thenReturn(file); when(utils.guessProjectForFile(file)).thenReturn(project); when(utils.findModuleForFile(file, project)).thenReturn(m1); listener.documentChanged(event); verifyZeroInteractions(submitter); }
@Override public void documentChanged(DocumentEvent event) { Document document = event.getDocument(); Editor[] editors = editorFactory.getEditors(document); for (Editor editor : editors) { Project project = editor.getProject(); if (project == null) { return; } PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document); syncedElementHighlighter.highlightStatement(editor, psiFile); } } }
@Test public void should_trigger() { Module m1 = mock(Module.class); VirtualFile file = mock(VirtualFile.class); Document doc = mock(Document.class); DocumentEvent event = mock(DocumentEvent.class); when(file.isValid()).thenReturn(true); when(event.getDocument()).thenReturn(doc); when(docManager.getFile(doc)).thenReturn(file); when(utils.guessProjectForFile(file)).thenReturn(project); when(utils.findModuleForFile(file, project)).thenReturn(m1); when(utils.isOpenFile(project, file)).thenReturn(true); listener.documentChanged(event); assertThat(listener.getEvents()).hasSize(1); verify(submitter, timeout(1000)).submitFiles(Collections.singleton(file), TriggerType.EDITOR_CHANGE, true); verifyNoMoreInteractions(submitter); }
@Test public void clear_and_dispose() { Module m1 = mock(Module.class); VirtualFile file = mock(VirtualFile.class); Document doc = mock(Document.class); DocumentEvent event = mock(DocumentEvent.class); when(file.isValid()).thenReturn(true); when(event.getDocument()).thenReturn(doc); when(docManager.getFile(doc)).thenReturn(file); when(utils.guessProjectForFile(file)).thenReturn(project); when(utils.findModuleForFile(file, project)).thenReturn(m1); listener.documentChanged(event); listener.disposeComponent(); assertThat(listener.getEvents()).isEmpty(); } }