fix rename error if using 'LF' eol in windows#748
fix rename error if using 'LF' eol in windows#748DonJayamanne merged 2 commits intoDonJayamanne:masterfrom
Conversation
|
Very useful - is this related to #579? |
|
@gandhis1 I'm not sure. If you are using Windows and editing python file with |
| return offset - position.line; | ||
|
|
||
| const winEols = getWindowsLineEndingCount(document.getText(), offset); | ||
| return offset - winEols; |
There was a problem hiding this comment.
@drzunny
You are loading the entire document as a string (document.getText()), contrary to your comments.
// In order to prevent the one-time loading of large files from taking up too much memory
You might want to use the VS Code api to read text from the document.
There was a problem hiding this comment.
OK, i will update my PR later, thanks for your suggestion
| return offset - position.line; | ||
|
|
||
| const winEols = getWindowsLineEndingCount(document.getText(), offset); | ||
| return offset - winEols; |
There was a problem hiding this comment.
Also, if this is specific to windows, shouldn't we check the value of IS_WINDOWS and then invoke the functino getWindowsLineEncodingCount?
There was a problem hiding this comment.
Yes, it specific to Windows, but in this method (getOffsetAt), IS_WINDOWS has already checked before invoke the function getWindowsLineEndingCount.
|
@drzunny please could you point me to the rope code that uses LF instead of CRLF |
|
i check the source code and find the reason in fscommands.py def file_data_to_unicode(data, encoding=None):
result = _decode_data(data, encoding)
if '\r' in result: # <-------------------- here
result = result.replace('\r\n', '\n').replace('\r', '\n')
return resultThe filepath will be read as a def read(self):
data = self.read_bytes()
try:
return fscommands.file_data_to_unicode(data)
except UnicodeDecodeError as e:
raise exceptions.ModuleDecodeError(self.path, e.reason)it read binary data, and convert to unicode AND REPLACE THE |
Hello, DonJayamanne
I found the

renamefeature goes wrong when i edit a py file withLFeol on Windows(7/8/10).but if I convert the file EOL to
CRLF, everything is ok.Some editor / IDE will keep both
LFandCRLFin one file. So the numbers of character (CR) are not necessarily equal to the line numbersHere is the effect of this patch:
