Skip to content

Commit

Permalink
[WIP] Create first custom autocomplete for GH
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
leha-bot committed Apr 16, 2018
1 parent fdf942e commit c140c0e
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit c140c0e

Please sign in to comment.