diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2012-10-29 18:59:41 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2012-10-29 18:59:41 +0100 |
| commit | cc876f7107f33a860e7379992aefd3f8659b948f (patch) | |
| tree | fcec2d615d5e8c218f6f03a0773ca96a8ae66dd3 /src/input_handler.cc | |
| parent | 6b664052b8062dae71df65ddc759d908cc08458d (diff) | |
validate key in InputHandler before sending to mode, and minor refactor
Diffstat (limited to 'src/input_handler.cc')
| -rw-r--r-- | src/input_handler.cc | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc index 56879e98..c6c782af 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -62,6 +62,14 @@ private: int m_count = 0; }; +String codepoint_to_str(Codepoint cp) +{ + std::string str; + auto it = back_inserter(str); + utf8::dump(it, cp); + return String(str); +} + class LineEditor { public: @@ -91,10 +99,7 @@ public: } else { - std::string keystr; - auto inserter = back_inserter(keystr); - utf8::dump(inserter, key.key); - m_line = m_line.substr(0, m_cursor_pos) + keystr + m_line = m_line.substr(0, m_cursor_pos) + codepoint_to_str(key.key) + m_line.substr(m_cursor_pos); ++m_cursor_pos; } @@ -467,14 +472,6 @@ private: int m_current_completion = -1; }; -String codepoint_to_str(Codepoint cp) -{ - std::string str; - auto it = back_inserter(str); - utf8::dump(it, cp); - return String(str); -} - class Insert : public InputMode { public: @@ -625,12 +622,17 @@ void InputHandler::on_next_key(KeyCallback callback) m_mode.reset(new InputModes::NextKey(*this, callback)); } +bool is_valid(const Key& key) +{ + return key != Key::Invalid and key.key <= 0x10FFFF; +} + void InputHandler::handle_available_inputs(Context& context) { while (context.ui().is_key_available()) { Key key = context.ui().get_key(); - if (key != Key::Invalid) + if (is_valid(key)) m_mode->on_key(key, context); } context.draw_ifn(); |
