BigBahss / vscode-cmantic

C/C++ code generation for VS Code: Generate Definitions, Getters, Setters, and much more.
https://bigbahss.github.io/vscode-cmantic/
MIT License
82 stars 9 forks source link

Fix double lines in CRLF EOL endings #45

Open sewbacca opened 2 years ago

sewbacca commented 2 years ago

I noticed a strange bug when using CRLF line endings. Whenever i wanted to add a definition, somehow an excess of newlines would appear, e.g.:

    void Instance::function()

    {

    }

Which seemed strange, at first and after a little digging, I found the issue:

Whenever you add tabspaces to a block, you appear to use insertText.replace(/^/gm, util.indentation()) to prepend any indentation. Unfortunatly it does work only with LF line endings. When using CRLF line endings, it assumes the \r and \n are both line seperators (instead of completly\r\n), which led to inserting tabspaces between and after them, resulting in \r\t\n\t. Then, vscode would translate these into \r\n\t\r\n\t (or at least in an equivalent visual representation). To fix the issue, I have created a function in utilities, called insertBeforeEachLine, which solves the issue and I have replaced each occurence $1.replace(/^/gm, $2) with util.insertBeforeEachLine($1, $2).

LeandroSQ commented 5 months ago

I have another change ready to go:

But it seems this repo is not maintained anymore, I'm considering forking it and maintaining myself. Would you be willing to move your PR there if that would be the case?

sewbacca commented 5 months ago

Sure, I'd be happy to move it over. Just ping me the deeds, if you decided to fork the repository.