smartlist: select top item when return is pressed during a search

- fixes index change on re-filtering

Change-Id: I08c32857600c5f3930967a98756a3c4b8b63fe64
This commit is contained in:
Andreas Traczyk
2020-10-08 19:18:53 -04:00
committed by Ming Rui Zhang
parent da026ab226
commit 28e40f88da
6 changed files with 60 additions and 28 deletions

View File

@@ -61,9 +61,8 @@ ConversationsAdapter::safeInit()
connectConversationModel(); connectConversationModel();
setProperty("currentTypeFilter", QVariant::fromValue( setProperty("currentTypeFilter",
LRCInstance::getCurrentAccountInfo().profileInfo.type)); QVariant::fromValue(LRCInstance::getCurrentAccountInfo().profileInfo.type));
} }
void void
@@ -129,8 +128,8 @@ ConversationsAdapter::onCurrentAccountIdChanged()
disconnectConversationModel(); disconnectConversationModel();
connectConversationModel(); connectConversationModel();
setProperty("currentTypeFilter", QVariant::fromValue( setProperty("currentTypeFilter",
LRCInstance::getCurrentAccountInfo().profileInfo.type)); QVariant::fromValue(LRCInstance::getCurrentAccountInfo().profileInfo.type));
} }
void void
@@ -146,10 +145,7 @@ ConversationsAdapter::onNewUnreadInteraction(const QString& accountId,
auto& accInfo = LRCInstance::getAccountInfo(accountId); auto& accInfo = LRCInstance::getAccountInfo(accountId);
auto& contact = accInfo.contactModel->getContact(interaction.authorUri); auto& contact = accInfo.contactModel->getContact(interaction.authorUri);
auto from = Utils::bestNameForContact(contact); auto from = Utils::bestNameForContact(contact);
auto onClicked = [this, auto onClicked = [this, accountId, convUid, uri = interaction.authorUri] {
accountId,
convUid,
uri = interaction.authorUri] {
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
emit LRCInstance::instance().notificationClicked(); emit LRCInstance::instance().notificationClicked();
#else #else
@@ -159,7 +155,7 @@ ConversationsAdapter::onNewUnreadInteraction(const QString& accountId,
if (!convInfo.uid.isEmpty()) { if (!convInfo.uid.isEmpty()) {
selectConversation(accountId, convInfo.uid); selectConversation(accountId, convInfo.uid);
emit LRCInstance::instance().updateSmartList(); emit LRCInstance::instance().updateSmartList();
emit modelSorted(uri); emit modelSorted(convInfo.uid);
} }
}; };
@@ -210,7 +206,7 @@ ConversationsAdapter::connectConversationModel(bool updateFilter)
== lrc::api::profile::Type::TEMPORARY) { == lrc::api::profile::Type::TEMPORARY) {
return; return;
} }
emit modelSorted(QVariant::fromValue(contactURI)); emit modelSorted(QVariant::fromValue(conversation.uid));
}); });
modelUpdatedConnection_ = QObject::connect(currentConversationModel, modelUpdatedConnection_ = QObject::connect(currentConversationModel,
@@ -228,6 +224,7 @@ ConversationsAdapter::connectConversationModel(bool updateFilter)
conversationSmartListModel_ conversationSmartListModel_
->fillConversationsList(); ->fillConversationsList();
updateConversationsFilterWidget(); updateConversationsFilterWidget();
emit indexRepositionRequested();
emit updateListViewRequested(); emit updateListViewRequested();
}); });
@@ -264,6 +261,11 @@ ConversationsAdapter::connectConversationModel(bool updateFilter)
&lrc::api::ConversationModel::searchStatusChanged, &lrc::api::ConversationModel::searchStatusChanged,
[this](const QString& status) { emit showSearchStatus(status); }); [this](const QString& status) { emit showSearchStatus(status); });
// This connection is ideal when separated search results list.
// This signal is guaranteed to fire just after filterChanged during a search if results are
// changed, and once before filterChanged when calling setFilter.
// NOTE: Currently, when searching, the entire conversation list will be copied 2-3 times each
// keystroke :/.
searchResultUpdatedConnection_ searchResultUpdatedConnection_
= QObject::connect(currentConversationModel, = QObject::connect(currentConversationModel,
&lrc::api::ConversationModel::searchResultUpdated, &lrc::api::ConversationModel::searchResultUpdated,

View File

@@ -52,10 +52,11 @@ signals:
void showSearchStatus(const QString& status); void showSearchStatus(const QString& status);
void modelChanged(const QVariant& model); void modelChanged(const QVariant& model);
void modelSorted(const QVariant& uri); void modelSorted(const QVariant& uid);
void updateListViewRequested(); void updateListViewRequested();
void navigateToWelcomePageRequested(); void navigateToWelcomePageRequested();
void currentTypeFilterChanged(); void currentTypeFilterChanged();
void indexRepositionRequested();
private slots: private slots:
void onCurrentAccountIdChanged(); void onCurrentAccountIdChanged();

View File

@@ -26,6 +26,7 @@ Rectangle {
id: contactSearchBarRect id: contactSearchBarRect
signal contactSearchBarTextChanged(string text) signal contactSearchBarTextChanged(string text)
signal returnPressedWhileSearching
function clearText() { function clearText() {
contactSearchBar.clear() contactSearchBar.clear()
@@ -93,4 +94,14 @@ Rectangle {
context: Qt.ApplicationShortcut context: Qt.ApplicationShortcut
onActivated: contactSearchBar.forceActiveFocus() onActivated: contactSearchBar.forceActiveFocus()
} }
Shortcut {
sequence: "Return"
context: Qt.ApplicationShortcut
onActivated: {
if (contactSearchBar.text !== "") {
returnPressedWhileSearching()
}
}
}
} }

View File

@@ -40,6 +40,20 @@ ListView {
root.forceUpdatePotentialInvalidItem() root.forceUpdatePotentialInvalidItem()
} }
function repositionIndex(uid = "") {
if (uid === "")
uid = mainViewWindow.currentConvUID
root.currentIndex = -1
updateListView()
for (var i = 0; i < count; i++) {
if (root.model.data(
root.model.index(i, 0), SmartListModel.UID) === uid) {
root.currentIndex = i
break
}
}
}
ConversationSmartListContextMenu { ConversationSmartListContextMenu {
id: smartListContextMenu id: smartListContextMenu
} }
@@ -53,21 +67,17 @@ ListView {
// When the model has been sorted, we need to adjust the focus (currentIndex) // When the model has been sorted, we need to adjust the focus (currentIndex)
// to the previously focused conversation item. // to the previously focused conversation item.
function onModelSorted(uri) { function onModelSorted(uid) {
root.currentIndex = -1 repositionIndex(uid)
updateListView()
for (var i = 0; i < count; i++) {
if (root.model.data(
root.model.index(i, 0), SmartListModel.URI) === uri) {
root.currentIndex = i
break
}
}
} }
function onUpdateListViewRequested() { function onUpdateListViewRequested() {
updateListView() updateListView()
} }
function onIndexRepositionRequested() {
repositionIndex()
}
} }
Connections { Connections {

View File

@@ -29,6 +29,11 @@ ItemDelegate {
height: 72 height: 72
property int lastInteractionPreferredWidth: 80 property int lastInteractionPreferredWidth: 80
function convUid() {
return UID
}
Connections { Connections {
target: conversationSmartListView target: conversationSmartListView

View File

@@ -59,13 +59,9 @@ Rectangle {
contactSearchBar.clearText() contactSearchBar.clearText()
} }
function accountChangedUIReset() {
contactSearchBar.clearText()
}
function refreshAccountComboBox(index) { function refreshAccountComboBox(index) {
accountComboBox.update() accountComboBox.update()
accountChangedUIReset() clearContactSearchBar()
accountComboBox.resetAccountListModel() accountComboBox.resetAccountListModel()
} }
@@ -99,6 +95,13 @@ Rectangle {
onContactSearchBarTextChanged: { onContactSearchBarTextChanged: {
UtilsAdapter.setConversationFilter(text) UtilsAdapter.setConversationFilter(text)
} }
onReturnPressedWhileSearching: {
var convUid = conversationSmartListView.itemAtIndex(0).convUid()
var currentAccountId = AccountAdapter.currentAccountId
ConversationsAdapter.selectConversation(currentAccountId, convUid)
conversationSmartListView.repositionIndex(convUid)
}
} }
SidePanelTabBar { SidePanelTabBar {