mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed bug when no stripping happens if two files modified in the same line
This commit is contained in:
+15
-8
@@ -73,7 +73,8 @@ public final class TrailingSpacesStripper extends FileDocumentManagerAdapter {
|
||||
|
||||
final String overrideStripTrailingSpacesData = file.getUserData(OVERRIDE_STRIP_TRAILING_SPACES_KEY);
|
||||
final Boolean overrideEnsureNewlineData = file.getUserData(OVERRIDE_ENSURE_NEWLINE_KEY);
|
||||
final String stripTrailingSpaces = overrideStripTrailingSpacesData != null ? overrideStripTrailingSpacesData : settings.getStripTrailingSpaces();
|
||||
@EditorSettingsExternalizable.StripTrailingSpaces
|
||||
String stripTrailingSpaces = overrideStripTrailingSpacesData != null ? overrideStripTrailingSpacesData : settings.getStripTrailingSpaces();
|
||||
final boolean doStrip = !stripTrailingSpaces.equals(EditorSettingsExternalizable.STRIP_TRAILING_SPACES_NONE);
|
||||
final boolean ensureEOL = overrideEnsureNewlineData != null ? overrideEnsureNewlineData.booleanValue() : settings.isEnsureNewLineAtEOF();
|
||||
|
||||
@@ -120,10 +121,7 @@ public final class TrailingSpacesStripper extends FileDocumentManagerAdapter {
|
||||
return;
|
||||
}
|
||||
|
||||
Component focusOwner = IdeFocusManager.getGlobalInstance().getFocusOwner();
|
||||
DataContext dataContext = DataManager.getInstance().getDataContext(focusOwner);
|
||||
boolean isDisposeInProgress = ApplicationManager.getApplication().isDisposeInProgress(); // ignore caret placing when exiting
|
||||
Editor activeEditor = isDisposeInProgress ? null : CommonDataKeys.EDITOR.getData(dataContext);
|
||||
Editor activeEditor = getActiveEditor(document);
|
||||
|
||||
// when virtual space enabled, we can strip whitespace anywhere
|
||||
boolean isVirtualSpaceEnabled = activeEditor == null || activeEditor.getSettings().isVirtualSpace();
|
||||
@@ -151,6 +149,17 @@ public final class TrailingSpacesStripper extends FileDocumentManagerAdapter {
|
||||
((DocumentImpl)document).clearLineModificationFlagsExcept(caretLines);
|
||||
}
|
||||
|
||||
private static Editor getActiveEditor(@NotNull Document document) {
|
||||
Component focusOwner = IdeFocusManager.getGlobalInstance().getFocusOwner();
|
||||
DataContext dataContext = DataManager.getInstance().getDataContext(focusOwner);
|
||||
boolean isDisposeInProgress = ApplicationManager.getApplication().isDisposeInProgress(); // ignore caret placing when exiting
|
||||
Editor activeEditor = isDisposeInProgress ? null : CommonDataKeys.EDITOR.getData(dataContext);
|
||||
if (activeEditor != null && activeEditor.getDocument() != document) {
|
||||
activeEditor = null;
|
||||
}
|
||||
return activeEditor;
|
||||
}
|
||||
|
||||
public static boolean stripIfNotCurrentLine(@NotNull Document document, boolean inChangedLinesOnly) {
|
||||
if (document instanceof DocumentWindow) {
|
||||
document = ((DocumentWindow)document).getDelegate();
|
||||
@@ -158,9 +167,7 @@ public final class TrailingSpacesStripper extends FileDocumentManagerAdapter {
|
||||
if (!(document instanceof DocumentImpl)) {
|
||||
return true;
|
||||
}
|
||||
DataContext dataContext = DataManager.getInstance().getDataContext(IdeFocusManager.getGlobalInstance().getFocusOwner());
|
||||
boolean isDisposeInProgress = ApplicationManager.getApplication().isDisposeInProgress(); // ignore caret placing when exiting
|
||||
Editor activeEditor = isDisposeInProgress ? null : CommonDataKeys.EDITOR.getData(dataContext);
|
||||
Editor activeEditor = getActiveEditor(document);
|
||||
|
||||
// when virtual space enabled, we can strip whitespace anywhere
|
||||
boolean isVirtualSpaceEnabled = activeEditor == null || activeEditor.getSettings().isVirtualSpace();
|
||||
|
||||
+34
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,11 +19,16 @@ import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.impl.ApplicationImpl;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ex.DocumentEx;
|
||||
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.EditorTestUtil;
|
||||
import com.intellij.testFramework.LightPlatformCodeInsightTestCase;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
@@ -32,7 +37,7 @@ import java.io.IOException;
|
||||
/**
|
||||
* User: cdr
|
||||
*/
|
||||
public class StripTrailingSpacesTest extends LightPlatformCodeInsightTestCase {
|
||||
public class TrailingSpacesStripperTest extends LightPlatformCodeInsightTestCase {
|
||||
private EditorSettingsExternalizable.OptionSet oldSettings;
|
||||
|
||||
@Override
|
||||
@@ -196,4 +201,31 @@ public class StripTrailingSpacesTest extends LightPlatformCodeInsightTestCase {
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
checkResultByText("XXX <caret>\nYYY\n");
|
||||
}
|
||||
|
||||
public void testModifySameLineInTwoFilesAndSaveAllShouldStripAtLeastOneFile() throws IOException {
|
||||
EditorSettingsExternalizable settings = EditorSettingsExternalizable.getInstance();
|
||||
settings.setStripTrailingSpaces(EditorSettingsExternalizable.STRIP_TRAILING_SPACES_CHANGED);
|
||||
|
||||
Editor editor1 = createHeavyEditor("x1.txt", "x11 <caret>\nyyy\n");
|
||||
Editor editor2 = createHeavyEditor("x2.txt", "x22 <caret>\nyyy\n");
|
||||
|
||||
type(' ', editor1, getProject());
|
||||
type(' ', editor2, getProject());
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
assertEquals("x11\nyyy\n", editor1.getDocument().getText());
|
||||
assertEquals("x22 \nyyy\n", editor2.getDocument().getText()); // caret in the way in second but not in the first
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Editor createHeavyEditor(@NotNull String name, @NotNull String text) throws IOException {
|
||||
VirtualFile myVFile = getSourceRoot().createChildData(null, name);
|
||||
VfsUtil.saveText(myVFile, text);
|
||||
final FileDocumentManager manager = FileDocumentManager.getInstance();
|
||||
final Document document = manager.getDocument(myVFile);
|
||||
manager.reloadFromDisk(document);
|
||||
Editor editor = createEditor(myVFile);
|
||||
EditorTestUtil.CaretAndSelectionState caretsState = EditorTestUtil.extractCaretAndSelectionMarkers(document);
|
||||
EditorTestUtil.setCaretsAndSelection(editor, caretsState);
|
||||
return editor;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user