mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
Support arbitrary newlines for search result excerpts
Previously we expected only LF to mark a newline but in theory we can receive CRLF or CR separated text (from files on disk) which would cause incorrect excerpt for matches crossing line boundaries.
This commit is contained in:
@@ -53,7 +53,7 @@ static void append (ns::attr_string_t& dst, std::string const& src, size_t from,
|
||||
dst.add(src.substr(begin, to-begin));
|
||||
}
|
||||
|
||||
static NSAttributedString* AttributedStringForMatch (std::string const& text, size_t from, size_t to, size_t n)
|
||||
static NSAttributedString* AttributedStringForMatch (std::string const& text, size_t from, size_t to, size_t n, std::string const& newlines)
|
||||
{
|
||||
ns::attr_string_t str;
|
||||
str.add(ns::style::line_break(NSLineBreakByTruncatingTail));
|
||||
@@ -66,7 +66,8 @@ static NSAttributedString* AttributedStringForMatch (std::string const& text, si
|
||||
size_t last = text.size();
|
||||
for(size_t it = 0; it != last; )
|
||||
{
|
||||
size_t eol = std::find(text.begin() + it, text.end(), '\n') - text.begin();
|
||||
size_t eol = text.find(newlines, it);
|
||||
eol = eol != std::string::npos ? eol : last;
|
||||
|
||||
if(oak::cap(it, from, eol) == from)
|
||||
{
|
||||
@@ -103,7 +104,7 @@ static NSAttributedString* AttributedStringForMatch (std::string const& text, si
|
||||
str.add(ns::style::unbold);
|
||||
}
|
||||
|
||||
if(++eol == to)
|
||||
if((eol += newlines.size()) == to)
|
||||
inMatch = false;
|
||||
|
||||
if(eol != last)
|
||||
@@ -270,7 +271,7 @@ static NSAttributedString* AttributedStringForMatch (std::string const& text, si
|
||||
<< text::format("%zu-%zu: Range is not valid UTF-8, please contact: http://macromates.com/support", m.first, m.last);
|
||||
}
|
||||
|
||||
_excerpt = AttributedStringForMatch(prefix + middle + suffix, prefix.size(), prefix.size() + middle.size(), m.line_number);
|
||||
_excerpt = AttributedStringForMatch(prefix + middle + suffix, prefix.size(), prefix.size() + middle.size(), m.line_number, m.newlines);
|
||||
_excerptReplaceString = replacementString;
|
||||
return _excerpt;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace find
|
||||
std::string excerpt;
|
||||
size_t excerpt_offset = 0;
|
||||
size_t line_number = 0;
|
||||
std::string newlines = "\n";
|
||||
};
|
||||
|
||||
struct scan_path_t
|
||||
|
||||
Reference in New Issue
Block a user