diff --git a/spellchecker/src/com/intellij/spellchecker/SpellCheckerManager.java b/spellchecker/src/com/intellij/spellchecker/SpellCheckerManager.java index 097258050ddb..d81dc80b8e2a 100644 --- a/spellchecker/src/com/intellij/spellchecker/SpellCheckerManager.java +++ b/spellchecker/src/com/intellij/spellchecker/SpellCheckerManager.java @@ -318,42 +318,31 @@ public class SpellCheckerManager implements Disposable { } private void removeCustomDictionaries(@NotNull String path) { - path = toSystemDependentName(path); - if (spellChecker.isDictionaryLoad(path)) { - spellChecker.removeDictionary(path); + final String systemDependentPath = toSystemDependentName(path); + if (locatedInDictFolders(path)) { + spellChecker.removeDictionariesRecursively(systemDependentPath); + mySettings.getDictionaryFoldersPaths().removeIf(dict -> isAncestor(systemDependentPath, dict, false)); + mySettings.getDisabledDictionariesPaths().removeIf(dict -> isAncestor(systemDependentPath, dict, false)); restartInspections(); } - else if (locatedInDictFolders(path)) { - spellChecker.removeDictionariesRecursively(path); - restartInspections(); - } - if (mySettings.getDictionaryFoldersPaths().contains(path)) { - mySettings.getDictionaryFoldersPaths().remove(path); - } } private void loadCustomDictionaries(@NotNull VirtualFile file) { final String path = toSystemDependentName(file.getPath()); if (!locatedInDictFolders(path)) return; - if (file.isDirectory()) { - visitChildrenRecursively(file, new VirtualFileVisitor() { - @Override - public boolean visitFile(@NotNull VirtualFile file) { - final boolean isDirectory = file.isDirectory(); - final String path = file.getPath(); - if (!isDirectory && isDic(path)) { - loadDictionary(path); - restartInspections(); - } - return isDirectory; + visitChildrenRecursively(file, new VirtualFileVisitor() { + @Override + public boolean visitFile(@NotNull VirtualFile file) { + final boolean isDirectory = file.isDirectory(); + final String path = file.getPath(); + if (!isDirectory && isDic(path)) { + loadDictionary(path); + restartInspections(); } - }); - } - else if (isDic(path)) { - loadDictionary(path); - restartInspections(); - } + return isDirectory; + } + }); } private boolean isDic(String path) { diff --git a/spellchecker/src/com/intellij/spellchecker/engine/BaseSpellChecker.java b/spellchecker/src/com/intellij/spellchecker/engine/BaseSpellChecker.java index 99b99d357e73..6816c9bfb751 100644 --- a/spellchecker/src/com/intellij/spellchecker/engine/BaseSpellChecker.java +++ b/spellchecker/src/com/intellij/spellchecker/engine/BaseSpellChecker.java @@ -213,7 +213,7 @@ public class BaseSpellChecker implements SpellCheckerEngine { public void removeDictionariesRecursively(@NotNull String directory) { bundledDictionaries.stream() .map(Dictionary::getName) - .filter(dict -> isAncestor(directory, dict, true) && isDictionaryLoad(dict)) + .filter(dict -> isAncestor(directory, dict, false) && isDictionaryLoad(dict)) .forEach(this::removeDictionary); } diff --git a/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettingsPane.java b/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettingsPane.java index 8aea893c04fe..6af6a2804d76 100644 --- a/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettingsPane.java +++ b/spellchecker/src/com/intellij/spellchecker/settings/SpellCheckerSettingsPane.java @@ -168,7 +168,7 @@ public class SpellCheckerSettingsPane implements Disposable { optionalChooserComponent.apply(); pathsChooserComponent.apply(); - settings.setDictionaryFoldersPaths(pathsChooserComponent.getValues()); + settings.setDictionaryFoldersPaths(new ArrayList<>(pathsChooserComponent.getValues())); final HashSet disabledDictionaries = new HashSet<>(); final HashSet bundledDisabledDictionaries = new HashSet<>(); diff --git a/spellchecker/testSrc/com/intellij/spellchecker/dictionary/CustomDictionaryTest.java b/spellchecker/testSrc/com/intellij/spellchecker/dictionary/CustomDictionaryTest.java index fa61afe55ee1..0408697f045a 100644 --- a/spellchecker/testSrc/com/intellij/spellchecker/dictionary/CustomDictionaryTest.java +++ b/spellchecker/testSrc/com/intellij/spellchecker/dictionary/CustomDictionaryTest.java @@ -27,11 +27,13 @@ import com.intellij.spellchecker.settings.SpellCheckerSettings; import java.io.File; import java.io.IOException; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import static com.intellij.openapi.util.io.FileUtil.createTempDirectory; import static com.intellij.openapi.vfs.VfsUtil.findFileByIoFile; +import static java.util.Collections.singletonList; public class CustomDictionaryTest extends SpellcheckerInspectionTestCase { private static final String TEST_DIC = "test.dic"; @@ -51,7 +53,7 @@ public class CustomDictionaryTest extends SpellcheckerInspectionTestCase { settings = SpellCheckerSettings.getInstance(getProject()); spellCheckerManager = SpellCheckerManager.getInstance(getProject()); oldPaths = settings.getDictionaryFoldersPaths(); - settings.setDictionaryFoldersPaths(Collections.singletonList(getTestDictDirectory())); + settings.setDictionaryFoldersPaths(new ArrayList<>(singletonList(getTestDictDirectory()))); spellCheckerManager.fullConfigurationReload(); }