Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 7c29b4a7 authored by David Faure's avatar David Faure

Implement "find previous" in KTextEdit.

parent e6ea3fbd
......@@ -481,6 +481,9 @@ bool KTextEdit::Private::handleShortcut(const QKeyEvent* event)
} else if (findReplaceEnabled && KStandardShortcut::findNext().contains(key)) {
parent->slotFindNext();
return true;
} else if (findReplaceEnabled && KStandardShortcut::findPrev().contains(key)) {
parent->slotFindPrevious();
return true;
} else if (findReplaceEnabled && KStandardShortcut::replace().contains(key)) {
if (!parent->isReadOnly())
parent->slotReplace();
......@@ -560,15 +563,19 @@ QMenu *KTextEdit::mousePopupMenu()
if (d->findReplaceEnabled) {
KAction *findAction = KStandardAction::find(this, SLOT(slotFind()), popup);
KAction *findNextAction = KStandardAction::findNext(this, SLOT(slotFindNext()), popup);
KAction *findPrevAction = KStandardAction::findPrev(this, SLOT(slotFindPrevious()), popup);
if (emptyDocument) {
findAction->setEnabled(false);
findNextAction->setEnabled(false);
findPrevAction->setEnabled(false);
} else {
findNextAction->setEnabled(d->find != 0);
findPrevAction->setEnabled(d->find != 0);
}
popup->addSeparator();
popup->addAction(findAction);
popup->addAction(findNextAction);
popup->addAction(findPrevAction);
if (!isReadOnly()) {
KAction *replaceAction = KStandardAction::replace(this, SLOT(slotReplace()), popup);
......@@ -969,6 +976,18 @@ void KTextEdit::slotDoFind()
slotFindNext();
}
void KTextEdit::slotFindPrevious()
{
if (!d->find) {
return;
}
const long oldOptions = d->find->options();
d->find->setOptions(oldOptions ^ KFind::FindBackwards);
slotFindNext();
if (d->find) {
d->find->setOptions(oldOptions);
}
}
void KTextEdit::slotFindNext()
{
......@@ -1047,6 +1066,7 @@ void KTextEdit::setSpellInterface(KTextEditSpellInterface *spellInterface)
bool KTextEdit::Private::overrideShortcut(const QKeyEvent* event)
{
const int key = event->key() | event->modifiers();
qDebug() << key;
if ( KStandardShortcut::copy().contains( key ) ) {
return true;
......@@ -1084,6 +1104,8 @@ bool KTextEdit::Private::overrideShortcut(const QKeyEvent* event)
return true;
} else if (findReplaceEnabled && KStandardShortcut::findNext().contains(key)) {
return true;
} else if (findReplaceEnabled && KStandardShortcut::findPrev().contains(key)) {
return true;
} else if (findReplaceEnabled && KStandardShortcut::replace().contains(key)) {
return true;
} else if (event->matches(QKeySequence::SelectAll)) { // currently missing in QTextEdit
......
......@@ -386,6 +386,10 @@ class KDEUI_EXPORT KTextEdit : public QTextEdit //krazy:exclude=qclasses
void slotReplaceNext();
void slotDoFind();
void slotFind();
/**
* @since 4.14.8
*/
void slotFindPrevious();
void slotFindNext();
void slotReplace();
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment