1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-24 03:56:32 +03:00

IncrementalInserter: Append, Insert or Change mode specified at construction

This commit is contained in:
Maxime Coste 2011-09-28 19:14:39 +00:00
parent 43fb64a913
commit e619a81375
3 changed files with 20 additions and 10 deletions

View File

@ -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 --");
Kakoune::IncrementalInserter inserter(window, append);
Kakoune::IncrementalInserter inserter(window, mode);
draw_window(window);
while(true)
{
@ -399,8 +399,7 @@ void do_erase(Window& window, int count)
void do_change(Window& window, int count)
{
do_yank(window, 0);
window.erase();
do_insert(window);
do_insert(window, IncrementalInserter::Mode::Change);
}
template<bool append>
@ -424,8 +423,8 @@ std::unordered_map<char, std::function<void (Window& window, int count)>> keymap
{ 'd', do_erase },
{ 'c', do_change },
{ 'i', [](Window& window, int count) { do_insert(window); } },
{ 'a', [](Window& window, int count) { do_insert(window, true); } },
{ 'i', [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::Insert); } },
{ 'a', [](Window& window, int count) { do_insert(window, IncrementalInserter::Mode::Append); } },
{ 'g', do_go },

View File

@ -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)
{
assert(not m_window.m_current_inserter);
m_window.m_current_inserter = this;
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)
{
const BufferIterator& pos = append ? sel.end() : sel.begin();
const BufferIterator& pos = mode == Mode::Append ? sel.end() : sel.begin();
sel = Selection(pos, pos);
}
m_window.m_buffer.begin_undo_group();
}
IncrementalInserter::~IncrementalInserter()

View File

@ -113,7 +113,14 @@ private:
class IncrementalInserter
{
public:
IncrementalInserter(Window& window, bool append = false);
enum class Mode
{
Insert,
Append,
Change
};
IncrementalInserter(Window& window, Mode mode = Mode::Insert);
~IncrementalInserter();
void insert(const Window::String& string);