[LyX/master] Show suggestions containing the input in the command buffer
Jean-Marc Lasgouttes
lasgouttes at lyx.org
Fri Nov 4 20:43:31 UTC 2022
commit 89394bcd0f3b5079a066d8c3f6f7a5e606073db3
Author: Daniel Ramoeller <d.lyx at web.de>
Date: Sat Aug 6 07:13:51 2022 +0200
Show suggestions containing the input in the command buffer
Previously, only the suggestions starting with the current input were
shown.
Contains the following minor improvements:
- Add space to indicate when only one suggestion is found
- Select first item in suggestion-list in order to make selecting with
arrow keys more intuitive
- Fix selection with Shift+Up/Down in text-field
Fix for bug #12572.
---
src/frontends/qt/GuiCommandBuffer.cpp | 14 +++++++++-
src/frontends/qt/GuiCommandEdit.cpp | 41 +++++++++++++++++---------------
2 files changed, 34 insertions(+), 21 deletions(-)
diff --git a/src/frontends/qt/GuiCommandBuffer.cpp b/src/frontends/qt/GuiCommandBuffer.cpp
index 4d28bfb..ee68013 100644
--- a/src/frontends/qt/GuiCommandBuffer.cpp
+++ b/src/frontends/qt/GuiCommandBuffer.cpp
@@ -184,9 +184,12 @@ void GuiCommandBuffer::complete()
string new_input;
vector<string> const & comp = completions(input, new_input);
- if (comp.empty()) {
+ if (comp.empty() || comp.size() == 1) {
if (new_input != input)
edit_->setText(toqstr(new_input));
+ // If there is only one match, indicate this by adding a space
+ if (comp.size() == 1)
+ edit_->setText(edit_->text() + " ");
return;
}
@@ -208,6 +211,8 @@ void GuiCommandBuffer::showList(vector<string> const & list,
else
listBox->addItem(toqstr(item));
}
+ // Select the first item
+ listBox->setCurrentItem(listBox->item(0));
listBox->resize(listBox->sizeHint());
@@ -296,6 +301,11 @@ GuiCommandBuffer::completions(string const & prefix, string & new_prefix)
if (prefixIs(act.first, prefix))
comp.push_back(act.first);
}
+ // now add all the other items that contain the prefix
+ for (auto const & act : lyxaction) {
+ if (!prefixIs(act.first, prefix) && contains(act.first, prefix))
+ comp.push_back(act.first);
+ }
if (comp.empty()) {
new_prefix = prefix;
@@ -304,7 +314,7 @@ GuiCommandBuffer::completions(string const & prefix, string & new_prefix)
if (comp.size() == 1) {
new_prefix = comp[0];
- return vector<string>();
+ return comp;
}
// find maximal available prefix
diff --git a/src/frontends/qt/GuiCommandEdit.cpp b/src/frontends/qt/GuiCommandEdit.cpp
index 22dd9c8..89883da 100644
--- a/src/frontends/qt/GuiCommandEdit.cpp
+++ b/src/frontends/qt/GuiCommandEdit.cpp
@@ -29,26 +29,29 @@ GuiCommandEdit::GuiCommandEdit(QWidget * parent)
void GuiCommandEdit::keyPressEvent(QKeyEvent * e)
{
- switch (e->key()) {
- case Qt::Key_Escape:
- // emit signal
- escapePressed();
- break;
-
- case Qt::Key_Up:
- // emit signal
- upPressed();
- break;
-
- case Qt::Key_Down:
- // emit signal
- downPressed();
- break;
-
- default:
- QLineEdit::keyPressEvent(e);
- break;
+ if (e->modifiers() == Qt::NoModifier) {
+ switch (e->key()) {
+ case Qt::Key_Escape:
+ // emit signal
+ escapePressed();
+ return;
+
+ case Qt::Key_Up:
+ // emit signal
+ upPressed();
+ return;
+
+ case Qt::Key_Down:
+ // emit signal
+ downPressed();
+ return;
+
+ default:
+ // do nothing
+ break;
+ }
}
+ QLineEdit::keyPressEvent(e);
}
More information about the lyx-cvs
mailing list