Empty result ([]) on Windows with default line endings: selection.find(newline) never matches
Claude reports: on Windows, a new buffer with the default line endings gives an empty result from the converter. Same symptom as #30 (CSV to JSON gives []) and related to #26 (Unix newlines). Switching the buffer to Unix line endings makes it work, and the code explains why.
Steps, Sublime Text 4 build 4215, Windows, DataConverter 2023.05.20:
-
New file with the default line endings, insert:
name,age,city ann,30,NYC bob,25,LA cat,41,SF -
Select all, run
DataConverter: to JSON.
Result: the buffer becomes []. The console only shows CSV Sniffer found headers.
Then View > Line Endings > Unix, select all and run the same command again: the buffer becomes the expected JSON list of three objects. So only the line ending of the buffer decides it.
Cause (DataConverter.py):
- line 296:
settings["newline"] = LINEENDINGS.get(self.view.line_endings(), os.linesep)gives"\r\n"for a buffer with Windows line endings (andos.linesepis"\r\n"on Windows). - line 245: the text is read with
self.view.substr(sel), which always returns"\n"line breaks, whatever the buffer's line ending. - lines 386 and 403:
selection = selection[selection.find(self.settings["newline"]):]looks for"\r\n"in text that only contains"\n".findreturns -1, soselection[-1:]keeps only the last character and there are no rows left to convert.
The text read from the view should be split on "\n"; settings["newline"] is only needed for the output. Replacing selection.find(self.settings["newline"]) with selection.find("\n") at both places (lines 386 and 403) should fix it.
Checked: installed through the Package Control picker, removed again afterwards.