IncrementalInserter: Append, Insert or Change mode specified at construction
This commit is contained in:
parent
43fb64a913
commit
e619a81375
11
src/main.cc
11
src/main.cc
|
@ -221,10 +221,10 @@ struct scoped_status
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void do_insert(Window& window, bool append = false)
|
void do_insert(Window& window, IncrementalInserter::Mode mode)
|
||||||
{
|
{
|
||||||
scoped_status("-- INSERT --");
|
scoped_status("-- INSERT --");
|
||||||
Kakoune::IncrementalInserter inserter(window, append);
|
Kakoune::IncrementalInserter inserter(window, mode);
|
||||||
draw_window(window);
|
draw_window(window);
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
|
@ -399,8 +399,7 @@ void do_erase(Window& window, int count)
|
||||||
void do_change(Window& window, int count)
|
void do_change(Window& window, int count)
|
||||||
{
|
{
|
||||||
do_yank(window, 0);
|
do_yank(window, 0);
|
||||||
window.erase();
|
do_insert(window, IncrementalInserter::Mode::Change);
|
||||||
do_insert(window);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool append>
|
template<bool append>
|
||||||
|
@ -424,8 +423,8 @@ std::unordered_map<char, std::function<void (Window& window, int count)>> keymap
|
||||||
|
|
||||||
{ 'd', do_erase },
|
{ 'd', do_erase },
|
||||||
{ 'c', do_change },
|
{ 'c', do_change },
|
||||||
{ 'i', [](Window& window, int count) { do_insert(window); } },
|
{ 'i', [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::Insert); } },
|
||||||
{ 'a', [](Window& window, int count) { do_insert(window, true); } },
|
{ 'a', [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::Append); } },
|
||||||
|
|
||||||
{ 'g', do_go },
|
{ 'g', do_go },
|
||||||
|
|
||||||
|
|
|
@ -270,19 +270,23 @@ void Window::scroll_to_keep_cursor_visible_ifn()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IncrementalInserter::IncrementalInserter(Window& window, bool append)
|
IncrementalInserter::IncrementalInserter(Window& window, Mode mode)
|
||||||
: m_window(window)
|
: m_window(window)
|
||||||
{
|
{
|
||||||
assert(not m_window.m_current_inserter);
|
assert(not m_window.m_current_inserter);
|
||||||
m_window.m_current_inserter = this;
|
m_window.m_current_inserter = this;
|
||||||
m_window.check_invariant();
|
m_window.check_invariant();
|
||||||
|
|
||||||
|
m_window.m_buffer.begin_undo_group();
|
||||||
|
|
||||||
|
if (mode == Mode::Change)
|
||||||
|
window.erase_noundo();
|
||||||
|
|
||||||
for (auto& sel : m_window.m_selections)
|
for (auto& sel : m_window.m_selections)
|
||||||
{
|
{
|
||||||
const BufferIterator& pos = append ? sel.end() : sel.begin();
|
const BufferIterator& pos = mode == Mode::Append ? sel.end() : sel.begin();
|
||||||
sel = Selection(pos, pos);
|
sel = Selection(pos, pos);
|
||||||
}
|
}
|
||||||
m_window.m_buffer.begin_undo_group();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IncrementalInserter::~IncrementalInserter()
|
IncrementalInserter::~IncrementalInserter()
|
||||||
|
|
|
@ -113,7 +113,14 @@ private:
|
||||||
class IncrementalInserter
|
class IncrementalInserter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IncrementalInserter(Window& window, bool append = false);
|
enum class Mode
|
||||||
|
{
|
||||||
|
Insert,
|
||||||
|
Append,
|
||||||
|
Change
|
||||||
|
};
|
||||||
|
|
||||||
|
IncrementalInserter(Window& window, Mode mode = Mode::Insert);
|
||||||
~IncrementalInserter();
|
~IncrementalInserter();
|
||||||
|
|
||||||
void insert(const Window::String& string);
|
void insert(const Window::String& string);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user