@@ -28,14 +28,13 @@ class CompiledSqlPanel(project: Project) : IdeaPanel, Disposable, ActiveFileList
28
28
private val dbtCommandExecutorService = project.service<DbtCommandExecutorService >()
29
29
private val mainPanel = JPanel (BorderLayout ())
30
30
private val recompileButton = JButton (" Re-compile model" )
31
- private var document: Document ? = null
31
+ private var document = EditorFactory .getInstance().createDocument( " " )
32
32
private var activeFile: VirtualFile ? = null
33
33
34
34
init {
35
35
project.messageBus.connect().subscribe(ActiveFileService .TOPIC , this )
36
36
val fileType = FileTypeManager .getInstance().getFileTypeByExtension(" sql" )
37
- document = EditorFactory .getInstance().createDocument(" " )
38
- val editor = EditorFactory .getInstance().createEditor(document!! , project, fileType, true )
37
+ val editor = EditorFactory .getInstance().createEditor(document, project, fileType, true )
39
38
val editorTextField = editor.component
40
39
// to set the initial file, since the subscription is only set-up after
41
40
// opening the panel (lazy) for the first time
@@ -100,13 +99,17 @@ class CompiledSqlPanel(project: Project) : IdeaPanel, Disposable, ActiveFileList
100
99
file.refresh(false , false )
101
100
SwingUtilities .invokeLater {
102
101
ApplicationManager .getApplication().runWriteAction {
103
- document?.setText(file.contentsToByteArray().toString(Charsets .UTF_8 ))
102
+ val fileContent = file.contentsToByteArray().toString(Charsets .UTF_8 )
103
+ // On windows line separators are typically \r\n instead of \n
104
+ // This can cause issues with the editor, so we normalize the line separators
105
+ val normalizedContent = fileContent.replace(" \r\n " , " \n " )
106
+ document.setText(normalizedContent)
104
107
}
105
108
}
106
109
} else {
107
110
SwingUtilities .invokeLater {
108
111
ApplicationManager .getApplication().runWriteAction {
109
- document? .setText(" No compiled file found. Please compile the model first by clicking the 'Re-compile model' button." )
112
+ document.setText(" No compiled file found. Please compile the model first by clicking the 'Re-compile model' button." )
110
113
}
111
114
}
112
115
}
0 commit comments