summaryrefslogtreecommitdiff
path: root/src/insert_completer.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2019-12-01 21:03:50 +1100
committerMaxime Coste <mawww@kakoune.org>2019-12-01 21:05:02 +1100
commit2623366514d64b23c3fb6f6237396eec49a310b6 (patch)
tree1dc44f939cb717a592f1bfedb02f52bff8c7d4e4 /src/insert_completer.cc
parent4fdbf21ff8b042d48c9fb8a506bdc63018631453 (diff)
Pass inserted text ranges in InsertCompletionHide hook parameter
Fixes #2898
Diffstat (limited to 'src/insert_completer.cc')
-rw-r--r--src/insert_completer.cc23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/insert_completer.cc b/src/insert_completer.cc
index 0bb6186d..57a12478 100644
--- a/src/insert_completer.cc
+++ b/src/insert_completer.cc
@@ -468,9 +468,24 @@ void InsertCompleter::reset()
{
if (m_explicit_completer or m_completions.is_valid())
{
- String selected_item;
- if (m_current_candidate >= 0 and m_current_candidate < m_completions.candidates.size())
- selected_item = std::move(m_completions.candidates[m_current_candidate].completion);
+ String hook_param;
+ if (m_context.has_client() and m_current_candidate >= 0 and m_current_candidate < m_completions.candidates.size() - 1)
+ {
+ auto& buffer = m_context.buffer();
+ auto ref = buffer.string(m_completions.begin, m_completions.end);
+ const auto& cursor_pos = m_context.selections().main().cursor();
+ const auto prefix_len = buffer.distance(m_completions.begin, cursor_pos);
+ const auto suffix_len = std::max(0_byte, buffer.distance(cursor_pos, m_completions.end));
+ hook_param = join(m_context.selections() |
+ transform([&](const auto& sel) { return buffer.iterator_at(sel.cursor()); }) |
+ filter([&](const auto& pos) {
+ return pos.coord().column >= prefix_len and (pos + suffix_len) != buffer.end() and
+ std::equal(ref.begin(), ref.end(), pos - prefix_len);
+ }) |
+ transform([&](const auto& pos) {
+ return selection_to_string(ColumnType::Byte, buffer, {(pos - prefix_len).coord(), buffer.char_prev((pos + suffix_len).coord())});
+ }), ' ');
+ }
m_explicit_completer = nullptr;
m_completions = InsertCompletion{};
@@ -478,7 +493,7 @@ void InsertCompleter::reset()
{
m_context.client().menu_hide();
m_context.client().info_hide();
- m_context.hooks().run_hook(Hook::InsertCompletionHide, selected_item, m_context);
+ m_context.hooks().run_hook(Hook::InsertCompletionHide, hook_param, m_context);
}
}
}