Skip to content

Commit df33ef0

Browse files
Normalize line separators for windows support
1 parent d066db3 commit df33ef0

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/main/kotlin/com/github/ramonvermeulen/dbtToolkit/ui/panels/CompiledSqlPanel.kt

+8-5
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@ class CompiledSqlPanel(project: Project) : IdeaPanel, Disposable, ActiveFileList
2828
private val dbtCommandExecutorService = project.service<DbtCommandExecutorService>()
2929
private val mainPanel = JPanel(BorderLayout())
3030
private val recompileButton = JButton("Re-compile model")
31-
private var document: Document? = null
31+
private var document = EditorFactory.getInstance().createDocument("")
3232
private var activeFile: VirtualFile? = null
3333

3434
init {
3535
project.messageBus.connect().subscribe(ActiveFileService.TOPIC, this)
3636
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)
3938
val editorTextField = editor.component
4039
// to set the initial file, since the subscription is only set-up after
4140
// opening the panel (lazy) for the first time
@@ -100,13 +99,17 @@ class CompiledSqlPanel(project: Project) : IdeaPanel, Disposable, ActiveFileList
10099
file.refresh(false, false)
101100
SwingUtilities.invokeLater {
102101
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)
104107
}
105108
}
106109
} else {
107110
SwingUtilities.invokeLater {
108111
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.")
110113
}
111114
}
112115
}

0 commit comments

Comments
 (0)