Skip to content

Commit

Permalink
[FIX][I] #711 Ignore non-text editors for editor state
Browse files Browse the repository at this point in the history
Adjusts the logic sharing the local editor state to ignore the opening
of non-text editors.

Adjusts the logic sharing the local editor state to ignore the closing
of editors not known to the editor pool.

With this change, non-text editors are completely ignored by Saros/I.
This was done to match the Eclipse handling of such non-text editors.

Partial fix for #711.
  • Loading branch information
tobous committed Feb 21, 2020
1 parent 83fc70f commit fdea0cd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
22 changes: 18 additions & 4 deletions intellij/src/saros/intellij/editor/LocalEditorHandler.java
Expand Up @@ -2,6 +2,8 @@

import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.TextEditor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.apache.log4j.Logger;
Expand Down Expand Up @@ -153,15 +155,20 @@ private Editor openEditor(
}

/**
* Removes a file from the editorPool and calls {@link EditorManager#generateEditorClosed(SPath)}
* Removes a file from the editorPool and calls {@link EditorManager#generateEditorClosed(SPath)}.
*
* <p>Does nothing if the file is not shared or not known to the editor pool.
*
* @param project the project in which to close the editor
* @param virtualFile the file for which to close the editor
*/
public void closeEditor(@NotNull Project project, @NotNull VirtualFile virtualFile) {
SPath path = VirtualFileConverter.convertToSPath(project, virtualFile);

if (path != null && sarosSession.isShared(path.getResource())) {
if (path != null
&& sarosSession.isShared(path.getResource())
&& editorPool.getEditor(path) != null) {

editorPool.removeEditor(path);
manager.generateEditorClosed(path);
}
Expand Down Expand Up @@ -217,8 +224,9 @@ public void saveDocument(@NotNull SPath path) {
* @param project the project in which to activate the editor
* @param file the file whose editor was activated or <code>null</code> if there is no editor open
*/
public void activateEditor(@NotNull Project project, @Nullable VirtualFile file) {
if (file == null) {
public void activateEditor(
@NotNull Project project, @Nullable VirtualFile file, @Nullable FileEditor fileEditor) {
if (file == null || fileEditor == null) {

if (manager.hasSession()) {
manager.generateEditorActivated(null);
Expand All @@ -227,6 +235,12 @@ public void activateEditor(@NotNull Project project, @Nullable VirtualFile file)
return;
}

if (!(fileEditor instanceof TextEditor)) {
LOG.debug("Ignoring opened non-text editor for file " + file);

return;
}

SPath path = VirtualFileConverter.convertToSPath(project, file);

if (path != null && sarosSession.isShared(path.getResource())) {
Expand Down
@@ -1,5 +1,6 @@
package saros.intellij.eventhandler.editor.editorstate;

import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.FileEditorManagerEvent;
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
Expand Down Expand Up @@ -53,13 +54,13 @@ private void generateEditorClosedActivity(@NotNull VirtualFile virtualFile) {
}

/**
* Calls {@link LocalEditorHandler#activateEditor(Project, VirtualFile)}.
* Calls {@link LocalEditorHandler#activateEditor(Project, VirtualFile, FileEditor)}.
*
* @param event the event to react to
* @see FileEditorManagerListener#selectionChanged(FileEditorManagerEvent)
*/
private void generateEditorActivatedActivity(@NotNull FileEditorManagerEvent event) {
localEditorHandler.activateEditor(project, event.getNewFile());
localEditorHandler.activateEditor(project, event.getNewFile(), event.getNewEditor());
}

@Override
Expand Down

0 comments on commit fdea0cd

Please sign in to comment.