[Fix] Snippet will not be displayed correctly when file content is too short.

This commit is contained in:
iaom 2021-04-01 20:41:22 +08:00
parent ac5f47e374
commit d050d4ea28
1 changed files with 4 additions and 1 deletions

View File

@ -396,7 +396,10 @@ int FileContentSearch::getResult(Xapian::MSet &result, std::string &keyWord)
{
std::string s = data.substr((*pos < 60)? 0: (*pos - 60) , size + 120);
QString snippet = QString::fromStdString(s);
if(snippet.size() > 6 + QString::fromStdString(keyWord).size())
snippet.replace(0,3,"...").replace(snippet.size()-3,3,"...");
else
snippet.append("...").prepend("...");
snippets.append(snippet);
QString().swap(snippet);
std::string().swap(s);