diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2014-01-04 18:18:59 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2014-01-04 18:18:59 +0000 |
| commit | feaf197caefdb08b6cd8b3e187defd5d22e23c6f (patch) | |
| tree | 7806e7e1d24d180a1887e53d11d9c7c6ab3af18d /src/input_handler.cc | |
| parent | 39bc83c8c1408f54c443a19692946bb207f7d88a (diff) | |
Add support for the erase key in prompt and insert mode
Fixes #18
Diffstat (limited to 'src/input_handler.cc')
| -rw-r--r-- | src/input_handler.cc | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc index 8ed938ec..30c31413 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -128,6 +128,12 @@ public: --m_cursor_pos; } } + else if (key == Key::Erase) + { + if (m_cursor_pos != m_line.char_length()) + m_line = m_line.substr(0, m_cursor_pos) + + m_line.substr(m_cursor_pos+1); + } else { m_line = m_line.substr(0, m_cursor_pos) + codepoint_to_str(key.key) @@ -904,6 +910,7 @@ public: void on_key(Key key) override { + auto& buffer = context().buffer(); last_insert().second.push_back(key); if (m_mode == Mode::InsertReg) { @@ -935,7 +942,23 @@ public: reset_normal_mode(); } else if (key == Key::Backspace) - erase(); + { + for (auto& sel : context().selections()) + { + if (sel.last() == BufferCoord{0,0}) + continue; + auto pos = buffer.iterator_at(sel.last()); + buffer.erase(utf8::previous(pos), pos); + } + } + else if (key == Key::Erase) + { + for (auto& sel : context().selections()) + { + auto pos = buffer.iterator_at(sel.last()); + buffer.erase(pos, utf8::next(pos)); + } + } else if (key == Key::Left) { move(-1_char); @@ -995,18 +1018,6 @@ public: KeymapMode keymap_mode() const override { return KeymapMode::Insert; } private: - void erase() const - { - auto& buffer = context().buffer(); - for (auto& sel : context().selections()) - { - if (sel.last() == BufferCoord{0,0}) - continue; - auto pos = buffer.iterator_at(sel.last()); - buffer.erase(utf8::previous(pos), pos); - } - } - template<typename Type> void move(Type offset) { |
