Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger file saving operation on editor closing only when file has changes #4077

Merged
merged 3 commits into from
Feb 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ public void onActiveEditorChanged(@NotNull EditorPartPresenter activeEditor) {

@Override
public void removeEditor(EditorPartPresenter editor) {
editor.doSave();
if (editor.isDirty()) {
editor.doSave();
}

HandlerRegistration handlerRegistration = synchronizedEditors.remove(editor);
if (handlerRegistration != null) {
handlerRegistration.removeHandler();
Expand Down Expand Up @@ -137,6 +140,11 @@ public void onFileContentUpdate(final FileContentUpdateEvent event) {
return;
}

if (virtualFile instanceof File && ((File)virtualFile).getModificationStamp().equals(event.getModificationStamp())) {
//skip same content which we've got from the server
return;
}

documentStorage.getDocument(virtualFile, new DocumentStorage.DocumentCallback() {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,17 @@ public void shouldRemoveEditorFromGroup() {

editorGroupSynchronization.removeEditor(activeEditor);

//should save content before closing (autosave will not have time to do it)
verify(activeEditor, never()).doSave();
verify(handlerRegistration).removeHandler();
}

@Test
public void shouldRemoveEditorFromGroupAndSaveEditorIfDirty() {
when(activeEditor.isDirty()).thenReturn(true);
editorGroupSynchronization.addEditor(activeEditor);

editorGroupSynchronization.removeEditor(activeEditor);

verify(activeEditor).doSave();
verify(handlerRegistration).removeHandler();
}
Expand Down