Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several improvements to tags editing #7708

Merged
merged 1 commit into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/Entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ QString Entry::tags() const

QStringList Entry::tagList() const
{
static QRegExp rx("(\\ |\\,|\\t|\\;)");
static QRegExp rx("(\\,|\\t|\\;)");
auto taglist = tags().split(rx, QString::SkipEmptyParts);
std::sort(taglist.begin(), taglist.end());
return taglist;
Expand Down
1 change: 1 addition & 0 deletions src/gui/entry/EditEntryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ void EditEntryWidget::setupEntryUpdate()
#ifdef WITH_XC_NETWORKING
connect(m_mainUi->urlEdit, SIGNAL(textChanged(QString)), this, SLOT(updateFaviconButtonEnable(QString)));
#endif
connect(m_mainUi->tagsList, SIGNAL(tagsEdited()), this, SLOT(setModified()));
connect(m_mainUi->expireCheck, SIGNAL(stateChanged(int)), this, SLOT(setModified()));
connect(m_mainUi->expireDatePicker, SIGNAL(dateTimeChanged(QDateTime)), this, SLOT(setModified()));
connect(m_mainUi->notesEdit, SIGNAL(textChanged()), this, SLOT(setModified()));
Expand Down
16 changes: 15 additions & 1 deletion src/gui/tag/TagsEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "TagsEdit.h"
#include "gui/MainWindow.h"
#include <QApplication>
#include <QClipboard>
#include <QCompleter>
#include <QDebug>
#include <QPainter>
Expand Down Expand Up @@ -701,6 +702,7 @@ void TagsEdit::mousePressEvent(QMouseEvent* event)
if (i <= impl->editing_index) {
--impl->editing_index;
}
emit tagsEdited();
found = true;
break;
}
Expand Down Expand Up @@ -797,6 +799,15 @@ void TagsEdit::keyPressEvent(QKeyEvent* event)
} else if (event == QKeySequence::SelectNextChar) {
impl->moveCursor(impl->text_layout.nextCursorPosition(impl->cursor), true);
event->accept();
} else if (event == QKeySequence::Paste) {
auto clipboard = QApplication::clipboard();
if (clipboard) {
for (auto tagtext : clipboard->text().split(",")) {
Copy link

@michaelk83 michaelk83 Mar 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this use the same regex as when editing manually, the one on Entry.cpp line 195?
Also, what happens when you paste a tag that was already added (or enter a duplicate tag manually, for that matter)?

Copy link
Member Author

@droidmonkey droidmonkey Mar 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tags don't duplicate so non issue. I am just trying to get this out the door right now. This needs far more work to synch the various pieces. Not doing that right now. (aka this is good enough for now)

impl->currentText().insert(impl->cursor, tagtext);
impl->editNewTag(impl->editing_index + 1);
}
}
event->accept();
} else {
switch (event->key()) {
case Qt::Key_Left:
Expand Down Expand Up @@ -839,7 +850,10 @@ void TagsEdit::keyPressEvent(QKeyEvent* event)
}
event->accept();
break;
case Qt::Key_Space:
case Qt::Key_Return:
case Qt::Key_Enter:
case Qt::Key_Comma:
case Qt::Key_Semicolon:
if (!impl->currentText().isEmpty()) {
impl->editNewTag(impl->editing_index + 1);
}
Expand Down
16 changes: 9 additions & 7 deletions tests/gui/TestGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ void TestGui::init()
config()->set(Config::GUI_ShowTrayIcon, true);
// Disable the update check first time alert
config()->set(Config::UpdateCheckMessageShown, true);
// Disable quick unlock
config()->set(Config::Security_QuickUnlock, false);

// Copy the test database file to the temporary file
auto origFilePath = QDir(KEEPASSX_TEST_DATA_DIR).absoluteFilePath("NewDatabase.kdbx");
Expand Down Expand Up @@ -451,15 +453,15 @@ void TestGui::testEditEntry()
// Test tags
auto* tags = editEntryWidget->findChild<TagsEdit*>("tagsList");
QTest::keyClicks(tags, "_tag1");
QTest::keyClick(tags, Qt::Key_Space);
QTest::keyClick(tags, Qt::Key_Return);
QCOMPARE(tags->tags().last(), QString("_tag1"));
QTest::keyClick(tags, Qt::Key_Space);
QTest::keyClicks(tags, "_tag2"); // adds another tag
QCOMPARE(tags->tags().last(), QString("_tag2"));
QTest::keyClicks(tags, "tag 2"); // adds another tag
QTest::keyClick(tags, Qt::Key_Return);
QCOMPARE(tags->tags().last(), QString("tag 2"));
QTest::keyClick(tags, Qt::Key_Backspace); // Back into editing last tag
QTest::keyClicks(tags, "gers");
QTest::keyClick(tags, Qt::Key_Space);
QCOMPARE(tags->tags().last(), QString("_taggers"));
QTest::keyClicks(tags, "_is!awesome");
QTest::keyClick(tags, Qt::Key_Return);
QCOMPARE(tags->tags().last(), QString("tag 2_is!awesome"));

// Test entry colors (simulate choosing a color)
editEntryWidget->setCurrentPage(1);
Expand Down