@@ -7,7 +7,6 @@ import com.intellij.ide.projectView.ProjectView
77import com.intellij.openapi.application.runReadAction
88import com.intellij.openapi.application.runWriteAction
99import com.intellij.openapi.components.service
10- import com.intellij.openapi.editor.Editor
1110import com.intellij.openapi.editor.EditorFactory
1211import com.intellij.openapi.editor.EditorSettings
1312import com.intellij.openapi.editor.colors.EditorColorsManager
@@ -24,6 +23,7 @@ import com.intellij.openapi.ui.DialogPanel
2423import com.intellij.openapi.ui.TextFieldWithBrowseButton
2524import com.intellij.openapi.ui.ValidationInfo
2625import com.intellij.openapi.util.Disposer
26+ import com.intellij.ui.EditorTextField
2727import com.intellij.ui.EnumComboBoxModel
2828import com.intellij.ui.components.ActionLink
2929import 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