use_selection_as_search_pattern: use iterators instead of coords
This commit is contained in:
parent
43ff1909fb
commit
58ff97d51d
|
@ -15,6 +15,7 @@
|
||||||
#include "string.hh"
|
#include "string.hh"
|
||||||
#include "window.hh"
|
#include "window.hh"
|
||||||
#include "user_interface.hh"
|
#include "user_interface.hh"
|
||||||
|
#include "utf8_iterator.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
@ -335,18 +336,14 @@ void use_selection_as_search_pattern(Context& context)
|
||||||
const auto& buffer = context.buffer();
|
const auto& buffer = context.buffer();
|
||||||
for (auto& sel : sels)
|
for (auto& sel : sels)
|
||||||
{
|
{
|
||||||
auto begin = sel.min();
|
auto begin = utf8::make_iterator(buffer.iterator_at(sel.min()));
|
||||||
auto end = buffer.char_next(sel.max());
|
auto end = utf8::make_iterator(buffer.iterator_at(sel.max()))+1;
|
||||||
auto content = "\\Q" + context.buffer().string(begin, end) + "\\E";
|
auto content = "\\Q" + String{begin.base(), end.base()} + "\\E";
|
||||||
if (smart)
|
if (smart)
|
||||||
{
|
{
|
||||||
if (begin == BufferCoord{0,0} or
|
if (begin == buffer.begin() or (is_word(*begin) and not is_word(*begin-1)))
|
||||||
(is_word(buffer.char_at(begin)) and not
|
|
||||||
is_word(buffer.char_at(buffer.char_prev(begin)))))
|
|
||||||
content = "\\b" + content;
|
content = "\\b" + content;
|
||||||
if (buffer.is_end(end) or
|
if (end == buffer.end() or (is_word(*(end-1)) and not is_word(*end)))
|
||||||
(is_word(buffer.char_at(buffer.char_prev(end))) and not
|
|
||||||
is_word(buffer.char_at(end))))
|
|
||||||
content = content + "\\b";
|
content = content + "\\b";
|
||||||
}
|
}
|
||||||
patterns.push_back(std::move(content));
|
patterns.push_back(std::move(content));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user