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;
|
workerStb = false;
|
||||||
} else {
|
} else {
|
||||||
updateSceneRect();
|
updateSceneRect();
|
||||||
verticalScrollBar()->setValue(line->sceneBoundingRect().top());
|
verticalScrollBar()->setValue(line->sceneBoundingRect().top()); // NOTE: start here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ struct SearchPos
|
||||||
|
|
||||||
struct SearchResult
|
struct SearchResult
|
||||||
{
|
{
|
||||||
bool found{false};
|
bool found;
|
||||||
SearchPos pos;
|
SearchPos pos;
|
||||||
size_t start;
|
size_t start;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
|
@ -680,11 +680,7 @@ void GenericChatForm::loadHistoryTo(const QDateTime &time)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (begin != end) {
|
if (begin != end) {
|
||||||
if (searchResult.found == true) {
|
renderMessages(begin, end);
|
||||||
renderMessages(begin, searchResult.pos.logIdx, [this]{enableSearchText();});
|
|
||||||
} else {
|
|
||||||
renderMessages(begin, end);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
chatWidget->setScroll(true);
|
chatWidget->setScroll(true);
|
||||||
}
|
}
|
||||||
|
@ -729,23 +725,13 @@ void GenericChatForm::removeLastsMessages(const int num)
|
||||||
|
|
||||||
void GenericChatForm::disableSearchText()
|
void GenericChatForm::disableSearchText()
|
||||||
{
|
{
|
||||||
auto msgIt = messages.find(searchResult.pos.logIdx);
|
auto msgIt = messages.find(searchPos.logIdx);
|
||||||
if (msgIt != messages.end()) {
|
if (msgIt != messages.end()) {
|
||||||
auto text = qobject_cast<Text*>(msgIt->second->getContent(1));
|
auto text = qobject_cast<Text*>(msgIt->second->getContent(1));
|
||||||
text->deselectText();
|
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()
|
void GenericChatForm::clearChatArea()
|
||||||
{
|
{
|
||||||
clearChatArea(/* confirm = */ true, /* inform = */ true);
|
clearChatArea(/* confirm = */ true, /* inform = */ true);
|
||||||
|
@ -941,7 +927,6 @@ void GenericChatForm::onExportChat()
|
||||||
void GenericChatForm::onSearchTriggered()
|
void GenericChatForm::onSearchTriggered()
|
||||||
{
|
{
|
||||||
if (searchForm->isHidden()) {
|
if (searchForm->isHidden()) {
|
||||||
searchResult.found = false;
|
|
||||||
searchForm->removeSearchPhrase();
|
searchForm->removeSearchPhrase();
|
||||||
}
|
}
|
||||||
disableSearchText();
|
disableSearchText();
|
||||||
|
@ -971,27 +956,27 @@ void GenericChatForm::searchInBegin(const QString& phrase, const ParameterSearch
|
||||||
switch (parameter.period) {
|
switch (parameter.period) {
|
||||||
case PeriodSearch::WithTheFirst: {
|
case PeriodSearch::WithTheFirst: {
|
||||||
bForwardSearch = true;
|
bForwardSearch = true;
|
||||||
searchResult.pos.logIdx = chatLog.getFirstIdx();
|
searchPos.logIdx = chatLog.getFirstIdx();
|
||||||
searchResult.pos.numMatches = 0;
|
searchPos.numMatches = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PeriodSearch::WithTheEnd:
|
case PeriodSearch::WithTheEnd:
|
||||||
case PeriodSearch::None: {
|
case PeriodSearch::None: {
|
||||||
bForwardSearch = false;
|
bForwardSearch = false;
|
||||||
searchResult.pos.logIdx = chatLog.getNextIdx();
|
searchPos.logIdx = chatLog.getNextIdx();
|
||||||
searchResult.pos.numMatches = 0;
|
searchPos.numMatches = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PeriodSearch::AfterDate: {
|
case PeriodSearch::AfterDate: {
|
||||||
bForwardSearch = true;
|
bForwardSearch = true;
|
||||||
searchResult.pos.logIdx = firstItemAfterDate(parameter.time.date(), chatLog);
|
searchPos.logIdx = firstItemAfterDate(parameter.time.date(), chatLog);
|
||||||
searchResult.pos.numMatches = 0;
|
searchPos.numMatches = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PeriodSearch::BeforeDate: {
|
case PeriodSearch::BeforeDate: {
|
||||||
bForwardSearch = false;
|
bForwardSearch = false;
|
||||||
searchResult.pos.logIdx = firstItemAfterDate(parameter.time.date(), chatLog);
|
searchPos.logIdx = firstItemAfterDate(parameter.time.date(), chatLog);
|
||||||
searchResult.pos.numMatches = 0;
|
searchPos.numMatches = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1005,13 +990,13 @@ void GenericChatForm::searchInBegin(const QString& phrase, const ParameterSearch
|
||||||
|
|
||||||
void GenericChatForm::onSearchUp(const QString& phrase, const ParameterSearch& parameter)
|
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);
|
handleSearchResult(result, SearchDirection::Up);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericChatForm::onSearchDown(const QString& phrase, const ParameterSearch& parameter)
|
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()) {
|
if (result.found && result.pos.logIdx.get() > messages.end()->first.get()) {
|
||||||
const auto dt = chatLog.at(result.pos.logIdx).getTimestamp();
|
const auto dt = chatLog.at(result.pos.logIdx).getTimestamp();
|
||||||
|
@ -1030,11 +1015,18 @@ void GenericChatForm::handleSearchResult(SearchResult result, SearchDirection di
|
||||||
|
|
||||||
disableSearchText();
|
disableSearchText();
|
||||||
|
|
||||||
searchResult = result;
|
searchPos = result.pos;
|
||||||
|
|
||||||
auto const firstRenderedIdx = (messages.empty()) ? chatLog.getNextIdx() : messages.begin()->first;
|
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)
|
void GenericChatForm::renderMessage(ChatLogIdx idx)
|
||||||
|
|
|
@ -156,7 +156,6 @@ protected:
|
||||||
virtual void resizeEvent(QResizeEvent* event) final override;
|
virtual void resizeEvent(QResizeEvent* event) final override;
|
||||||
virtual bool eventFilter(QObject* object, QEvent* event) final override;
|
virtual bool eventFilter(QObject* object, QEvent* event) final override;
|
||||||
void disableSearchText();
|
void disableSearchText();
|
||||||
void enableSearchText();
|
|
||||||
bool searchInText(const QString& phrase, const ParameterSearch& parameter, SearchDirection direction);
|
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);
|
std::pair<int, int> indexForSearchInLine(const QString& txt, const QString& phrase, const ParameterSearch& parameter, SearchDirection direction);
|
||||||
|
|
||||||
|
@ -197,7 +196,7 @@ protected:
|
||||||
|
|
||||||
IChatLog& chatLog;
|
IChatLog& chatLog;
|
||||||
IMessageDispatcher& messageDispatcher;
|
IMessageDispatcher& messageDispatcher;
|
||||||
SearchResult searchResult;
|
SearchPos searchPos;
|
||||||
std::map<ChatLogIdx, ChatMessage::Ptr> messages;
|
std::map<ChatLogIdx, ChatMessage::Ptr> messages;
|
||||||
bool colorizeNames = false;
|
bool colorizeNames = false;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user