Support changing buffer when an edition is in progress
This commit is contained in:
parent
ab930ccfa8
commit
729e55573f
|
@ -170,8 +170,14 @@ void Context::forget_jumps_to_buffer(Buffer& buffer)
|
||||||
|
|
||||||
void Context::change_buffer(Buffer& buffer)
|
void Context::change_buffer(Buffer& buffer)
|
||||||
{
|
{
|
||||||
|
if (&buffer == &this->buffer())
|
||||||
|
return;
|
||||||
|
|
||||||
if (m_edition_level > 0)
|
if (m_edition_level > 0)
|
||||||
throw runtime_error("the current buffer is still being edited");
|
{
|
||||||
|
this->buffer().commit_undo_group();
|
||||||
|
m_edition_level = 0;
|
||||||
|
}
|
||||||
m_window.reset();
|
m_window.reset();
|
||||||
if (has_client())
|
if (has_client())
|
||||||
client().change_buffer(buffer);
|
client().change_buffer(buffer);
|
||||||
|
|
|
@ -113,15 +113,21 @@ private:
|
||||||
struct ScopedEdition
|
struct ScopedEdition
|
||||||
{
|
{
|
||||||
ScopedEdition(Context& context)
|
ScopedEdition(Context& context)
|
||||||
: m_context(context)
|
: m_context(context), m_buffer(&context.buffer())
|
||||||
{ m_context.begin_edition(); }
|
{ m_context.begin_edition(); }
|
||||||
|
|
||||||
~ScopedEdition()
|
~ScopedEdition()
|
||||||
{ m_context.end_edition(); }
|
{
|
||||||
|
// If buffer changed, the edition count
|
||||||
|
// was reset.
|
||||||
|
if (m_buffer == &m_context.buffer())
|
||||||
|
m_context.end_edition();
|
||||||
|
}
|
||||||
|
|
||||||
Context& context() const { return m_context; }
|
Context& context() const { return m_context; }
|
||||||
private:
|
private:
|
||||||
Context& m_context;
|
Context& m_context;
|
||||||
|
safe_ptr<Buffer> m_buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user