From c140c0eb59c560919c5d3f2c6fe9b923d42f8bed Mon Sep 17 00:00:00 2001 From: leha-bot Date: Tue, 17 Apr 2018 02:06:43 +0300 Subject: [PATCH] [WIP] Create first custom autocomplete for GH This commit adds the simple logic for numeric hashtags (like #30) and suggests the URL to Kepka's issue. Right now the link generation is stupid and does not respects the actual existence of issue. Related to #137. --- .../chat_helpers/field_autocomplete.cpp | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index b7d156b2b..c80d2473d 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -234,13 +234,24 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) { } } else if (_type == Type::Hashtags) { bool listAllSuggestions = _filter.isEmpty(); + bool isInteger = false; + int ghTextIssueId = _filter.toInt(&isInteger); + int size = 0; + if (isInteger) { + size++; + } auto &recent(cRecentWriteHashtags()); - hrows.reserve(recent.size()); - for (auto i = recent.cbegin(), e = recent.cend(); i != e; ++i) { - if (!listAllSuggestions && (!i->first.startsWith(_filter, Qt::CaseInsensitive) || i->first.size() == _filter.size())) { - continue; + hrows.reserve(recent.size() + size); + if (isInteger) { + hrows.push_back("github.com/procxx/kepka/issues/" + QString(_filter)); + } + if (listAllSuggestions) { + for_const (auto &i, recent) { + if (!i.first.startsWith(_filter, Qt::CaseInsensitive) || i.first.size() == _filter.size()) { + continue; + } + hrows.push_back("#" + i.first); } - hrows.push_back(i->first); } } else if (_type == Type::BotCommands) { bool listAllSuggestions = _filter.isEmpty(); @@ -629,8 +640,8 @@ void FieldAutocompleteInner::paintEvent(QPaintEvent *e) { } } else if (!_hrows->isEmpty()) { QString hrow = _hrows->at(i); - QString first = filterIsEmpty ? QString() : ('#' + hrow.mid(0, filterSize)); - QString second = filterIsEmpty ? ('#' + hrow) : hrow.mid(filterSize); + QString first = filterIsEmpty ? QString() : (/*'#' + */hrow.mid(0, filterSize)); + QString second = filterIsEmpty ? (/*'#' + */hrow) : hrow.mid(filterSize); qint32 firstwidth = st::mentionFont->width(first), secondwidth = st::mentionFont->width(second); if (htagwidth < firstwidth + secondwidth) { if (htagwidth < firstwidth + st::mentionFont->elidew) { @@ -742,7 +753,7 @@ bool FieldAutocompleteInner::chooseSelected(FieldAutocomplete::ChooseMethod meth } } else if (!_hrows->isEmpty()) { if (_sel >= 0 && _sel < _hrows->size()) { - emit hashtagChosen('#' + _hrows->at(_sel), method); + emit hashtagChosen(/*'#' + */_hrows->at(_sel), method); return true; } } else if (!_brows->isEmpty()) {