Skip to content

Commit db6dc2f

Browse files
p3rmiashkinintellij-monorepo-bot
authored andcommitted
[markdown] IJPL-254186 Settings page fails to open with custom CSS editor
GitOrigin-RevId: 588533784f0d1fce661cdb97de6e5d8aac473d06
1 parent bd0cb73 commit db6dc2f

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

plugins/markdown/core/src/org/intellij/plugins/markdown/settings/MarkdownSettingsConfigurable.kt

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import com.intellij.ide.projectView.ProjectView
77
import com.intellij.openapi.application.runReadAction
88
import com.intellij.openapi.application.runWriteAction
99
import com.intellij.openapi.components.service
10-
import com.intellij.openapi.editor.Editor
1110
import com.intellij.openapi.editor.EditorFactory
1211
import com.intellij.openapi.editor.EditorSettings
1312
import com.intellij.openapi.editor.colors.EditorColorsManager
@@ -24,6 +23,7 @@ import com.intellij.openapi.ui.DialogPanel
2423
import com.intellij.openapi.ui.TextFieldWithBrowseButton
2524
import com.intellij.openapi.ui.ValidationInfo
2625
import com.intellij.openapi.util.Disposer
26+
import com.intellij.ui.EditorTextField
2727
import com.intellij.ui.EnumComboBoxModel
2828
import com.intellij.ui.components.ActionLink
2929
import com.intellij.ui.components.JBCheckBox
@@ -69,7 +69,7 @@ internal class MarkdownSettingsConfigurable(private val project: Project) : Boun
6969
private val settings
7070
get() = MarkdownSettings.getInstance(project)
7171

72-
private var customStylesheetEditor: Editor? = null
72+
private var customStylesheetEditor: EditorTextField? = null
7373

7474
private fun isPreviewAvailable(): Boolean {
7575
return MarkdownHtmlPanelProvider.hasAvailableProviders()
@@ -287,7 +287,7 @@ internal class MarkdownSettingsConfigurable(private val project: Project) : Boun
287287
private fun setEditorReadonlyState(isReadonly: Boolean) {
288288
customStylesheetEditor?.let {
289289
it.document.setReadOnly(isReadonly)
290-
it.contentComponent.isEnabled = !isReadonly
290+
it.isEnabled = !isReadonly
291291
}
292292
}
293293

@@ -315,7 +315,6 @@ internal class MarkdownSettingsConfigurable(private val project: Project) : Boun
315315
}
316316

317317
override fun disposeUIResources() {
318-
customStylesheetEditor?.let(EditorFactory.getInstance()::releaseEditor)
319318
customStylesheetEditor = null
320319
super.disposeUIResources()
321320
}
@@ -360,13 +359,18 @@ internal class MarkdownSettingsConfigurable(private val project: Project) : Boun
360359
}
361360
}
362361

363-
private fun createCustomStylesheetEditor(): EditorEx {
362+
private fun createCustomStylesheetEditor(): EditorTextField {
364363
val editorFactory = EditorFactory.getInstance()
365364
val editorDocument = editorFactory.createDocument(settings.customStylesheetText ?: "")
366-
val editor = editorFactory.createEditor(editorDocument) as EditorEx
367-
fillEditorSettings(editor.settings)
368-
setEditorHighlighting(editor)
369-
return editor
365+
val cssFileType = FileTypeManager.getInstance().getFileTypeByExtension("css")
366+
return object : EditorTextField(editorDocument, null, cssFileType, false, false) {
367+
override fun createEditor(): EditorEx {
368+
return super.createEditor().also {
369+
fillEditorSettings(it.settings)
370+
setEditorHighlighting(it)
371+
}
372+
}
373+
}
370374
}
371375

372376
private fun setEditorHighlighting(editor: EditorEx) {
@@ -384,13 +388,11 @@ internal class MarkdownSettingsConfigurable(private val project: Project) : Boun
384388

385389
private fun resetEditorText(cssText: String) {
386390
customStylesheetEditor?.let { editor ->
387-
if (!editor.isDisposed) {
388-
runWriteAction {
389-
val writable = editor.document.isWritable
390-
editor.document.setReadOnly(false)
391-
editor.document.setText(cssText)
392-
editor.document.setReadOnly(!writable)
393-
}
391+
runWriteAction {
392+
val writable = editor.document.isWritable
393+
editor.document.setReadOnly(false)
394+
editor.document.setText(cssText)
395+
editor.document.setReadOnly(!writable)
394396
}
395397
}
396398
}

0 commit comments

Comments
 (0)