From 9148b1ae92024ea4974299e87788a58d67635664 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 5 Aug 2013 10:23:13 +0200 Subject: [PATCH] Add line completion --- src/input_handler.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/input_handler.cc b/src/input_handler.cc index a2ed3cae..2c23af80 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -723,6 +723,23 @@ public: return {}; } + BufferCompletion complete_line(const Buffer& buffer, BufferCoord cursor_pos) + { + String prefix = buffer[cursor_pos.line].substr(0_byte, cursor_pos.column); + StringList res; + for (LineCount l = 0_line; l < buffer.line_count(); ++l) + { + if (l == cursor_pos.line) + continue; + ByteCount len = buffer[l].length(); + if (len > cursor_pos.column and std::equal(prefix.begin(), prefix.end(), buffer[l].begin())) + res.push_back(buffer[l].substr(0_byte, len-1)); + } + if (res.empty()) + return {}; + return { cursor_pos.line, cursor_pos, std::move(res), buffer.timestamp() }; + } + private: void on_option_changed(const Option& opt) override { @@ -807,6 +824,8 @@ public: m_completer.try_complete<&BufferCompleter::complete_word>(); if (key.key == 'o') m_completer.try_complete<&BufferCompleter::complete_option>(); + if (key.key == 'l') + m_completer.try_complete<&BufferCompleter::complete_line>(); m_mode = Mode::Default; return; }