@@ -55,28 +55,28 @@ internal class DefaultTokensFileExportPanel(private val project: Project) :
5555 }
5656
5757 private fun writeFile (fileWrapper : VirtualFileWrapper ) {
58- val virtualFile = fileWrapper.getVirtualFile(/* createIfNotExist = */ true )
58+ val file = fileWrapper.getVirtualFile(/* createIfNotExist = */ true )
5959
60- if (virtualFile == null || ! virtualFile .isWritable) {
60+ if (file == null || ! file .isWritable) {
6161 exportInfo.foreground = JBColor .RED
6262 exportInfo.text = CCBundle [" cc.config.defaults.exportToPath.error" ]
6363 return
6464 }
6565
6666 // When exporting to a file, we also need to add the JSON schema reference.
6767 // Better normalize line endings to \n.
68- val jsonStr = StringUtil .convertLineSeparators(
68+ val content = StringUtil .convertLineSeparators(
6969 getResourceAsStream(" /defaults/${CC .File .Defaults } " ).bufferedReader().use(Reader ::readText)
7070 )
7171
7272 val pluginVersion = getPluginVersion()
7373 val schemaPath = " src/main/resources/defaults/conventionalcommit.schema.json"
7474 val schemaUrl = " https://github.com/lppedd/idea-conventional-commit/raw/$pluginVersion /$schemaPath "
75- val sb = StringBuilder (jsonStr )
76- sb.insert( 4 , $$ " \" $schema \" : \" $ $schemaUrl \" , \n " )
75+ val bytes = (content.substring( 0 , 4 ) + $$ " \" $schema \" : \" $ $schemaUrl \" , \n " + content.substring( 2 ) )
76+ .toByteArray(file.charset )
7777
7878 WriteAction .runAndWait<Throwable > {
79- virtualFile .setBinaryContent(" $sb " .toByteArray() )
79+ file .setBinaryContent(bytes )
8080 }
8181
8282 exportInfo.foreground = UIUtil .getLabelDisabledForeground()
0 commit comments