Opening document with no newlines no longer default to LF

Since creating new untitled documents go through the same “open” code they would have their newlines set to LF, this is no longer the case, so the global (or targeted) lineEndings setting now decide what to use (when saving the document).

Currently creating an untitled document from a buffer (e.g. `echo foo|mate`) will do newline detection and thus will ignore user settings during save, if the buffer had any newlines during initialization.

This may or may not be desired. Probably it should do newline detection when the data is provided by the user, but not when it is based on “internal” data, for example a command with “New Document” as output location.
This commit is contained in:
Allan Odgaard
2016-11-01 19:57:37 +07:00
parent 9a525a7c24
commit e08ea3d291
2 changed files with 5 additions and 3 deletions

View File

@@ -395,7 +395,7 @@ namespace
_state = kStateIdle;
_next_state = kStateHarmonizeLineFeeds;
_encoding.set_newlines(text::estimate_line_endings(_content->begin(), _content->end()));
_encoding.set_newlines(text::estimate_line_endings(_content->begin(), _content->end(), NULL_STR));
proceed();
}
break;

View File

@@ -14,7 +14,7 @@ namespace text
// =====================
template <typename _InputIter>
std::string estimate_line_endings (_InputIter const& first, _InputIter const& last)
std::string estimate_line_endings (_InputIter const& first, _InputIter const& last, std::string const& fallback = kLF)
{
size_t const kEnoughSamples = 50;
@@ -49,7 +49,9 @@ namespace text
return kCRLF;
else if(lf_count == 0 && crlf_count == 0 && cr_count > 0)
return kCR;
return kLF;
else if(lf_count != 0)
return kLF;
return fallback;
}
template <typename _InputIter>