mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
revert(chatlog): "feat: save selected search text after scrolling up"
This reverts commit dbf880078e
.
This commit is contained in:
parent
83d5863bbe
commit
c1d0624b5d
|
@ -688,7 +688,7 @@ void ChatLog::scrollToLine(ChatLine::Ptr line)
|
|||
workerStb = false;
|
||||
} else {
|
||||
updateSceneRect();
|
||||
verticalScrollBar()->setValue(line->sceneBoundingRect().top());
|
||||
verticalScrollBar()->setValue(line->sceneBoundingRect().top()); // NOTE: start here
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ struct SearchPos
|
|||
|
||||
struct SearchResult
|
||||
{
|
||||
bool found{false};
|
||||
bool found;
|
||||
SearchPos pos;
|
||||
size_t start;
|
||||
size_t len;
|
||||
|
|
|
@ -680,11 +680,7 @@ void GenericChatForm::loadHistoryTo(const QDateTime &time)
|
|||
}
|
||||
|
||||
if (begin != end) {
|
||||
if (searchResult.found == true) {
|
||||
renderMessages(begin, searchResult.pos.logIdx, [this]{enableSearchText();});
|
||||
} else {
|
||||
renderMessages(begin, end);
|
||||
}
|
||||
} else {
|
||||
chatWidget->setScroll(true);
|
||||
}
|
||||
|
@ -729,23 +725,13 @@ void GenericChatForm::removeLastsMessages(const int num)
|
|||
|
||||
void GenericChatForm::disableSearchText()
|
||||
{
|
||||
auto msgIt = messages.find(searchResult.pos.logIdx);
|
||||
auto msgIt = messages.find(searchPos.logIdx);
|
||||
if (msgIt != messages.end()) {
|
||||
auto text = qobject_cast<Text*>(msgIt->second->getContent(1));
|
||||
text->deselectText();
|
||||
}
|
||||
}
|
||||
|
||||
void GenericChatForm::enableSearchText()
|
||||
{
|
||||
auto msg = messages.at(searchResult.pos.logIdx);
|
||||
chatWidget->scrollToLine(msg);
|
||||
|
||||
auto text = qobject_cast<Text*>(msg->getContent(1));
|
||||
text->visibilityChanged(true);
|
||||
text->selectText(searchResult.exp, std::make_pair(searchResult.start, searchResult.len));
|
||||
}
|
||||
|
||||
void GenericChatForm::clearChatArea()
|
||||
{
|
||||
clearChatArea(/* confirm = */ true, /* inform = */ true);
|
||||
|
@ -941,7 +927,6 @@ void GenericChatForm::onExportChat()
|
|||
void GenericChatForm::onSearchTriggered()
|
||||
{
|
||||
if (searchForm->isHidden()) {
|
||||
searchResult.found = false;
|
||||
searchForm->removeSearchPhrase();
|
||||
}
|
||||
disableSearchText();
|
||||
|
@ -971,27 +956,27 @@ void GenericChatForm::searchInBegin(const QString& phrase, const ParameterSearch
|
|||
switch (parameter.period) {
|
||||
case PeriodSearch::WithTheFirst: {
|
||||
bForwardSearch = true;
|
||||
searchResult.pos.logIdx = chatLog.getFirstIdx();
|
||||
searchResult.pos.numMatches = 0;
|
||||
searchPos.logIdx = chatLog.getFirstIdx();
|
||||
searchPos.numMatches = 0;
|
||||
break;
|
||||
}
|
||||
case PeriodSearch::WithTheEnd:
|
||||
case PeriodSearch::None: {
|
||||
bForwardSearch = false;
|
||||
searchResult.pos.logIdx = chatLog.getNextIdx();
|
||||
searchResult.pos.numMatches = 0;
|
||||
searchPos.logIdx = chatLog.getNextIdx();
|
||||
searchPos.numMatches = 0;
|
||||
break;
|
||||
}
|
||||
case PeriodSearch::AfterDate: {
|
||||
bForwardSearch = true;
|
||||
searchResult.pos.logIdx = firstItemAfterDate(parameter.time.date(), chatLog);
|
||||
searchResult.pos.numMatches = 0;
|
||||
searchPos.logIdx = firstItemAfterDate(parameter.time.date(), chatLog);
|
||||
searchPos.numMatches = 0;
|
||||
break;
|
||||
}
|
||||
case PeriodSearch::BeforeDate: {
|
||||
bForwardSearch = false;
|
||||
searchResult.pos.logIdx = firstItemAfterDate(parameter.time.date(), chatLog);
|
||||
searchResult.pos.numMatches = 0;
|
||||
searchPos.logIdx = firstItemAfterDate(parameter.time.date(), chatLog);
|
||||
searchPos.numMatches = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1005,13 +990,13 @@ void GenericChatForm::searchInBegin(const QString& phrase, const ParameterSearch
|
|||
|
||||
void GenericChatForm::onSearchUp(const QString& phrase, const ParameterSearch& parameter)
|
||||
{
|
||||
auto result = chatLog.searchBackward(searchResult.pos, phrase, parameter);
|
||||
auto result = chatLog.searchBackward(searchPos, phrase, parameter);
|
||||
handleSearchResult(result, SearchDirection::Up);
|
||||
}
|
||||
|
||||
void GenericChatForm::onSearchDown(const QString& phrase, const ParameterSearch& parameter)
|
||||
{
|
||||
auto result = chatLog.searchForward(searchResult.pos, phrase, parameter);
|
||||
auto result = chatLog.searchForward(searchPos, phrase, parameter);
|
||||
|
||||
if (result.found && result.pos.logIdx.get() > messages.end()->first.get()) {
|
||||
const auto dt = chatLog.at(result.pos.logIdx).getTimestamp();
|
||||
|
@ -1030,11 +1015,18 @@ void GenericChatForm::handleSearchResult(SearchResult result, SearchDirection di
|
|||
|
||||
disableSearchText();
|
||||
|
||||
searchResult = result;
|
||||
searchPos = result.pos;
|
||||
|
||||
auto const firstRenderedIdx = (messages.empty()) ? chatLog.getNextIdx() : messages.begin()->first;
|
||||
|
||||
renderMessages(searchResult.pos.logIdx, firstRenderedIdx, [this]{enableSearchText();});
|
||||
renderMessages(searchPos.logIdx, firstRenderedIdx, [this, result] {
|
||||
auto msg = messages.at(searchPos.logIdx);
|
||||
chatWidget->scrollToLine(msg);
|
||||
|
||||
auto text = qobject_cast<Text*>(msg->getContent(1));
|
||||
text->visibilityChanged(true);
|
||||
text->selectText(result.exp, std::make_pair(result.start, result.len));
|
||||
});
|
||||
}
|
||||
|
||||
void GenericChatForm::renderMessage(ChatLogIdx idx)
|
||||
|
|
|
@ -156,7 +156,6 @@ protected:
|
|||
virtual void resizeEvent(QResizeEvent* event) final override;
|
||||
virtual bool eventFilter(QObject* object, QEvent* event) final override;
|
||||
void disableSearchText();
|
||||
void enableSearchText();
|
||||
bool searchInText(const QString& phrase, const ParameterSearch& parameter, SearchDirection direction);
|
||||
std::pair<int, int> indexForSearchInLine(const QString& txt, const QString& phrase, const ParameterSearch& parameter, SearchDirection direction);
|
||||
|
||||
|
@ -197,7 +196,7 @@ protected:
|
|||
|
||||
IChatLog& chatLog;
|
||||
IMessageDispatcher& messageDispatcher;
|
||||
SearchResult searchResult;
|
||||
SearchPos searchPos;
|
||||
std::map<ChatLogIdx, ChatMessage::Ptr> messages;
|
||||
bool colorizeNames = false;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user