parent
fa9169fe97
commit
88a9607552
|
@ -1469,6 +1469,9 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func)
|
||||||
if (parser.get_switch("itersel"))
|
if (parser.get_switch("itersel"))
|
||||||
{
|
{
|
||||||
SelectionList sels{base_context->selections()};
|
SelectionList sels{base_context->selections()};
|
||||||
|
Vector<Selection> new_sels;
|
||||||
|
size_t main = 0;
|
||||||
|
size_t timestamp = c.buffer().timestamp();
|
||||||
ScopedEdition edition{c};
|
ScopedEdition edition{c};
|
||||||
for (auto& sel : sels)
|
for (auto& sel : sels)
|
||||||
{
|
{
|
||||||
|
@ -1479,12 +1482,20 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func)
|
||||||
|
|
||||||
if (&sels.buffer() != &c.buffer())
|
if (&sels.buffer() != &c.buffer())
|
||||||
throw runtime_error("the buffer has changed while iterating on selections");
|
throw runtime_error("the buffer has changed while iterating on selections");
|
||||||
|
|
||||||
|
if (not draft)
|
||||||
|
{
|
||||||
|
update_selections(new_sels, main, c.buffer(), timestamp);
|
||||||
|
timestamp = c.buffer().timestamp();
|
||||||
|
for (auto& sel : c.selections())
|
||||||
|
new_sels.push_back(sel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (not draft)
|
if (not draft)
|
||||||
{
|
{
|
||||||
sels.update();
|
c.selections_write_only() = SelectionList(c.buffer(), new_sels);
|
||||||
c.selections_write_only() = std::move(sels);
|
c.selections().sort_and_merge_overlapping();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -337,12 +337,12 @@ Vector<Selection> compute_modified_ranges(Buffer& buffer, size_t timestamp)
|
||||||
return ranges;
|
return ranges;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectionList::update()
|
void update_selections(Vector<Selection>& selections, size_t& main, Buffer& buffer, size_t timestamp)
|
||||||
{
|
{
|
||||||
if (m_timestamp == m_buffer->timestamp())
|
if (timestamp == buffer.timestamp())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto changes = m_buffer->changes_since(m_timestamp);
|
auto changes = buffer.changes_since(timestamp);
|
||||||
auto change_it = changes.begin();
|
auto change_it = changes.begin();
|
||||||
while (change_it != changes.end())
|
while (change_it != changes.end())
|
||||||
{
|
{
|
||||||
|
@ -351,28 +351,33 @@ void SelectionList::update()
|
||||||
|
|
||||||
if (forward_end >= backward_end)
|
if (forward_end >= backward_end)
|
||||||
{
|
{
|
||||||
update_forward({ change_it, forward_end }, m_selections);
|
update_forward({ change_it, forward_end }, selections);
|
||||||
change_it = forward_end;
|
change_it = forward_end;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
update_backward({ change_it, backward_end }, m_selections);
|
update_backward({ change_it, backward_end }, selections);
|
||||||
change_it = backward_end;
|
change_it = backward_end;
|
||||||
}
|
}
|
||||||
m_selections.erase(
|
selections.erase(
|
||||||
merge_overlapping(m_selections.begin(), m_selections.end(),
|
merge_overlapping(selections.begin(), selections.end(),
|
||||||
m_main, overlaps), m_selections.end());
|
main, overlaps), selections.end());
|
||||||
kak_assert(std::is_sorted(m_selections.begin(), m_selections.end(),
|
kak_assert(std::is_sorted(selections.begin(), selections.end(),
|
||||||
compare_selections));
|
compare_selections));
|
||||||
}
|
}
|
||||||
for (auto& sel : m_selections)
|
for (auto& sel : selections)
|
||||||
{
|
{
|
||||||
sel.anchor() = m_buffer->clamp(sel.anchor());
|
sel.anchor() = buffer.clamp(sel.anchor());
|
||||||
sel.cursor() = m_buffer->clamp(sel.cursor());
|
sel.cursor() = buffer.clamp(sel.cursor());
|
||||||
|
}
|
||||||
|
selections.erase(merge_overlapping(selections.begin(), selections.end(),
|
||||||
|
main, overlaps), selections.end());
|
||||||
}
|
}
|
||||||
m_selections.erase(merge_overlapping(begin(), end(), m_main, overlaps), end());
|
|
||||||
check_invariant();
|
|
||||||
|
|
||||||
|
void SelectionList::update()
|
||||||
|
{
|
||||||
|
update_selections(m_selections, m_main, *m_buffer, m_timestamp);
|
||||||
|
check_invariant();
|
||||||
m_timestamp = m_buffer->timestamp();
|
m_timestamp = m_buffer->timestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,9 @@ inline bool overlaps(const Selection& lhs, const Selection& rhs)
|
||||||
: lhs.min() <= rhs.max();
|
: lhs.min() <= rhs.max();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void update_selections(Vector<Selection>& selections, size_t& main,
|
||||||
|
Buffer& buffer, size_t timestamp);
|
||||||
|
|
||||||
enum class InsertMode : unsigned
|
enum class InsertMode : unsigned
|
||||||
{
|
{
|
||||||
Insert,
|
Insert,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user