Repository: hannah-sten/texify-idea
Issue: Automatic Soft-wrap ignored when reopening a project

<!-- **Note**: you can discard the template below if you are requesting support or proposing a new feature. -->

#### Type of JetBrains IDE (IntelliJ, PyCharm, etc.) and version
IntelliJ 2019.2.2

#### TeXiFy IDEA version
0.6.6

#### What I did (steps to reproduce)
- Activate automatic soft wrap in Texify settings (see issue #243 and PR #244)
- Open some latex files in the project (correctly soft-wrapped)
- Close IntelliJ
- Open IntelliJ and open the latex project again. IntellJ reopens all open files from the last session.

#### Expected behavior
Soft-wrap should be activated on all reopened files.

#### Actual behavior
The latex files are opened again but soft-wrapping is disabled on these files. When closing these files and reopening them, soft-wrap is activated again.


Changed files:
src/nl/hannahsten/texifyidea/editor/LatexSoftWrapEditorListener.kt, src/nl/hannahsten/texifyidea/settings/TexifyConfigurable.kt, src/nl/hannahsten/texifyidea/settings/TexifySettingsState.kt, src/nl/hannahsten/texifyidea/startup/TexifyStartupActivity.kt, src/nl/hannahsten/texifyidea/settings/TexifySettings.kt

diff --git a/src/nl/hannahsten/texifyidea/editor/LatexSoftWrapEditorListener.kt b/src/nl/hannahsten/texifyidea/editor/LatexSoftWrapEditorListener.kt
deleted file mode 100644
index abc5008df..000000000
--- a/src/nl/hannahsten/texifyidea/editor/LatexSoftWrapEditorListener.kt
+++ /dev/null
@@ -1,35 +0,0 @@
-package nl.hannahsten.texifyidea.editor
-
-import com.intellij.openapi.editor.event.EditorFactoryEvent
-import com.intellij.openapi.editor.event.EditorFactoryListener
-import nl.hannahsten.texifyidea.settings.TexifySettings
-import nl.hannahsten.texifyidea.util.files.isLatexFile
-import nl.hannahsten.texifyidea.util.files.psiFile
-
-/**
- * Enables automatic soft wrap when a LaTeX file is opened.
- *
- * @author Sten Wessel
- */
-class LatexSoftWrapEditorListener : EditorFactoryListener {
-
-    override fun editorCreated(event: EditorFactoryEvent) {
-        if (!TexifySettings.getInstance().automaticSoftWraps) {
-            return
-        }
-
-        val editor = event.editor
-
-        if (editor.document.psiFile(editor.project ?: return)?.isLatexFile() != true) {
-            return
-        }
-
-        editor.settings.apply {
-            isUseSoftWraps = true
-            isUseCustomSoftWrapIndent = true
-        }
-    }
-
-    override fun editorReleased(event: EditorFactoryEvent) {
-    }
-}
diff --git a/src/nl/hannahsten/texifyidea/settings/TexifyConfigurable.kt b/src/nl/hannahsten/texifyidea/settings/TexifyConfigurable.kt
index 641790a2f..4e355422c 100644
--- a/src/nl/hannahsten/texifyidea/settings/TexifyConfigurable.kt
+++ b/src/nl/hannahsten/texifyidea/settings/TexifyConfigurable.kt
@@ -4,8 +4,8 @@ import com.intellij.openapi.options.SearchableConfigurable
 import com.intellij.openapi.ui.ComboBox
 import com.intellij.ui.components.JBCheckBox
 import com.intellij.ui.components.JBLabel
-import nl.hannahsten.texifyidea.settings.labeldefiningcommands.TexifyConfigurableLabelCommands
 import nl.hannahsten.texifyidea.run.linuxpdfviewer.PdfViewer
+import nl.hannahsten.texifyidea.settings.labeldefiningcommands.TexifyConfigurableLabelCommands
 import java.awt.FlowLayout
 import javax.swing.BoxLayout
 import javax.swing.JComponent
@@ -16,7 +16,6 @@ import javax.swing.JPanel
  */
 class TexifyConfigurable(private val settings: TexifySettings) : SearchableConfigurable {
 
-    private lateinit var automaticSoftWraps: JBCheckBox
     private lateinit var automaticSecondInlineMathSymbol: JBCheckBox
     private lateinit var automaticUpDownBracket: JBCheckBox
     private lateinit var automaticItemInItemize: JBCheckBox
@@ -36,7 +35,6 @@ class TexifyConfigurable(private val settings: TexifySettings) : SearchableConfi
             add(JPanel().apply {
                 layout = BoxLayout(this, BoxLayout.Y_AXIS)
 
-                automaticSoftWraps = addCheckbox("Enable soft wraps when opening LaTeX files")
                 automaticSecondInlineMathSymbol = addCheckbox("Automatically insert second '$'")
                 automaticUpDownBracket = addCheckbox("Automatically insert braces around text in subscript and superscript")
                 automaticItemInItemize = addCheckbox("Automatically insert '\\\\item' in itemize-like environments on pressing enter")
@@ -79,8 +77,7 @@ class TexifyConfigurable(private val settings: TexifySettings) : SearchableConfi
     }
 
     override fun isModified(): Boolean {
-        return automaticSoftWraps.isSelected != settings.automaticSoftWraps
-                || automaticSecondInlineMathSymbol.isSelected != settings.automaticSecondInlineMathSymbol
+        return automaticSecondInlineMathSymbol.isSelected != settings.automaticSecondInlineMathSymbol
                 || automaticUpDownBracket.isSelected != settings.automaticUpDownBracket
                 || automaticItemInItemize.isSelected != settings.automaticItemInItemize
                 || continuousPreview.isSelected != settings.continuousPreview
@@ -90,7 +87,6 @@ class TexifyConfigurable(private val settings: TexifySettings) : SearchableConfi
     }
 
     override fun apply() {
-        settings.automaticSoftWraps = automaticSoftWraps.isSelected
         settings.automaticSecondInlineMathSymbol = automaticSecondInlineMathSymbol.isSelected
         settings.automaticUpDownBracket = automaticUpDownBracket.isSelected
         settings.automaticItemInItemize = automaticItemInItemize.isSelected
@@ -101,7 +97,6 @@ class TexifyConfigurable(private val settings: TexifySettings) : SearchableConfi
     }
 
     override fun reset() {
-        automaticSoftWraps.isSelected = settings.automaticSoftWraps
         automaticSecondInlineMathSymbol.isSelected = settings.automaticSecondInlineMathSymbol
         automaticUpDownBracket.isSelected = settings.automaticUpDownBracket
         automaticItemInItemize.isSelected = settings.automaticItemInItemize
diff --git a/src/nl/hannahsten/texifyidea/settings/TexifySettings.kt b/src/nl/hannahsten/texifyidea/settings/TexifySettings.kt
index a5c9781fc..e3a540ba8 100644
--- a/src/nl/hannahsten/texifyidea/settings/TexifySettings.kt
+++ b/src/nl/hannahsten/texifyidea/settings/TexifySettings.kt
@@ -4,8 +4,6 @@ import com.intellij.openapi.components.PersistentStateComponent
 import com.intellij.openapi.components.ServiceManager
 import com.intellij.openapi.components.State
 import com.intellij.openapi.components.Storage
-import com.intellij.openapi.util.SystemInfo
-import com.intellij.util.xmlb.XmlSerializerUtil
 import nl.hannahsten.texifyidea.run.linuxpdfviewer.PdfViewer
 
 /**
@@ -27,7 +25,6 @@ class TexifySettings : PersistentStateComponent<TexifySettingsState> {
         CSQUOTES // Context Sensitive quotes from the csquotes package
     }
 
-    var automaticSoftWraps = false
     var automaticSecondInlineMathSymbol = true
     var automaticUpDownBracket = true
     var automaticItemInItemize = true
@@ -43,7 +40,6 @@ class TexifySettings : PersistentStateComponent<TexifySettingsState> {
 
     override fun getState(): TexifySettingsState? {
         return TexifySettingsState(
-                automaticSoftWraps = automaticSoftWraps,
                 automaticSecondInlineMathSymbol = automaticSecondInlineMathSymbol,
                 automaticUpDownBracket = automaticUpDownBracket,
                 automaticItemInItemize = automaticItemInItemize,
@@ -55,7 +51,6 @@ class TexifySettings : PersistentStateComponent<TexifySettingsState> {
     }
 
     override fun loadState(state: TexifySettingsState) {
-        automaticSoftWraps = state.automaticSoftWraps
         automaticSecondInlineMathSymbol = state.automaticSecondInlineMathSymbol
         automaticUpDownBracket = state.automaticUpDownBracket
         automaticItemInItemize = state.automaticItemInItemize
diff --git a/src/nl/hannahsten/texifyidea/settings/TexifySettingsState.kt b/src/nl/hannahsten/texifyidea/settings/TexifySettingsState.kt
index 28f8cdfa4..706dfc4e7 100644
--- a/src/nl/hannahsten/texifyidea/settings/TexifySettingsState.kt
+++ b/src/nl/hannahsten/texifyidea/settings/TexifySettingsState.kt
@@ -3,7 +3,6 @@ package nl.hannahsten.texifyidea.settings
 import nl.hannahsten.texifyidea.run.linuxpdfviewer.PdfViewer
 
 data class TexifySettingsState (
-        var automaticSoftWraps : Boolean = false,
         var automaticSecondInlineMathSymbol : Boolean = true,
         var automaticUpDownBracket : Boolean = true,
         var automaticItemInItemize: Boolean = true,
diff --git a/src/nl/hannahsten/texifyidea/startup/TexifyStartupActivity.kt b/src/nl/hannahsten/texifyidea/startup/TexifyStartupActivity.kt
index c2ed1648d..4d7ce7528 100644
--- a/src/nl/hannahsten/texifyidea/startup/TexifyStartupActivity.kt
+++ b/src/nl/hannahsten/texifyidea/startup/TexifyStartupActivity.kt
@@ -1,10 +1,8 @@
 package nl.hannahsten.texifyidea.startup
 
-import com.intellij.openapi.editor.EditorFactory
 import com.intellij.openapi.project.Project
 import com.intellij.openapi.startup.StartupActivity
 import com.intellij.openapi.util.SystemInfo
-import nl.hannahsten.texifyidea.editor.LatexSoftWrapEditorListener
 import nl.hannahsten.texifyidea.run.linuxpdfviewer.PdfViewer
 import nl.hannahsten.texifyidea.run.linuxpdfviewer.evince.EvinceInverseSearchListener
 import nl.hannahsten.texifyidea.settings.TexifySettings
@@ -15,11 +13,6 @@ import nl.hannahsten.texifyidea.settings.TexifySettings
 class TexifyStartupActivity : StartupActivity {
 
     override fun runActivity(project: Project) {
-        EditorFactory.getInstance().addEditorFactoryListener(
-                LatexSoftWrapEditorListener(),
-                project
-        )
-
         if (SystemInfo.isLinux && TexifySettings.getInstance().pdfViewer == PdfViewer.EVINCE) {
             EvinceInverseSearchListener().start()
         }