diff --git a/src/icons/icons.qrc b/src/icons/icons.qrc
index 7067e958d..e7c2d7a30 100644
--- a/src/icons/icons.qrc
+++ b/src/icons/icons.qrc
@@ -284,5 +284,9 @@
images/bookmark_16px@2x.png
images/bookmark_24px.png
images/bookmark_24px@2x.png
+ images/find_next_16px.png
+ images/find_next_16px@2x.png
+ images/find_prev_16px.png
+ images/find_prev_16px@2x.png
diff --git a/src/icons/images/find_next_16px.png b/src/icons/images/find_next_16px.png
new file mode 100644
index 000000000..aeb6b16f7
Binary files /dev/null and b/src/icons/images/find_next_16px.png differ
diff --git a/src/icons/images/find_next_16px@2x.png b/src/icons/images/find_next_16px@2x.png
new file mode 100644
index 000000000..dbad2baa3
Binary files /dev/null and b/src/icons/images/find_next_16px@2x.png differ
diff --git a/src/icons/images/find_prev_16px.png b/src/icons/images/find_prev_16px.png
new file mode 100644
index 000000000..cf9d4b6a4
Binary files /dev/null and b/src/icons/images/find_prev_16px.png differ
diff --git a/src/icons/images/find_prev_16px@2x.png b/src/icons/images/find_prev_16px@2x.png
new file mode 100644
index 000000000..fe78865c3
Binary files /dev/null and b/src/icons/images/find_prev_16px@2x.png differ
diff --git a/src/icons/svg/find_next_16px.svg b/src/icons/svg/find_next_16px.svg
new file mode 100644
index 000000000..21650bc0c
--- /dev/null
+++ b/src/icons/svg/find_next_16px.svg
@@ -0,0 +1,231 @@
+
+
+
+
diff --git a/src/icons/svg/find_prev_16px.svg b/src/icons/svg/find_prev_16px.svg
new file mode 100644
index 000000000..51d796955
--- /dev/null
+++ b/src/icons/svg/find_prev_16px.svg
@@ -0,0 +1,231 @@
+
+
+
+
diff --git a/src/lay/lay/MacroEditorDialog.ui b/src/lay/lay/MacroEditorDialog.ui
index 80f62e53c..fa02c8421 100644
--- a/src/lay/lay/MacroEditorDialog.ui
+++ b/src/lay/lay/MacroEditorDialog.ui
@@ -463,10 +463,6 @@
...
-
-
- :/breakpoint_16px.png:/breakpoint_16px.png
-
F9
@@ -636,7 +632,7 @@
- :/find_16px.png:/find_16px.png
+ :/find_next_16px.png:/find_next_16px.png
Ctrl+F
@@ -646,6 +642,23 @@
+ -
+
+
+ ...
+
+
+
+ :/find_prev_16px.png:/find_prev_16px.png
+
+
+ Ctrl+Shift+F
+
+
+ true
+
+
+
-
diff --git a/src/lay/lay/layMacroEditorDialog.cc b/src/lay/lay/layMacroEditorDialog.cc
index e75c60dfa..bf8c9ed03 100644
--- a/src/lay/lay/layMacroEditorDialog.cc
+++ b/src/lay/lay/layMacroEditorDialog.cc
@@ -493,6 +493,7 @@ MacroEditorDialog::MacroEditorDialog (lay::Dispatcher *pr, lym::MacroCollection
connect (replaceModeButton, SIGNAL (clicked ()), this, SLOT (replace_mode_button_clicked ()));
connect (replaceNextButton, SIGNAL (clicked ()), this, SLOT (replace_next_button_clicked ()));
connect (findNextButton, SIGNAL (clicked ()), this, SLOT (find_next_button_clicked ()));
+ connect (findPrevButton, SIGNAL (clicked ()), this, SLOT (find_prev_button_clicked ()));
connect (replaceAllButton, SIGNAL (clicked ()), this, SLOT (replace_all_button_clicked ()));
connect (allVariables, SIGNAL (clicked (bool)), variableList, SLOT (set_show_all (bool)));
@@ -2021,7 +2022,7 @@ MacroEditorDialog::replace_all_button_clicked ()
}
void
-MacroEditorDialog::search_requested (const QString &s)
+MacroEditorDialog::search_requested (const QString &s, bool prev)
{
if (! s.isNull ()) {
searchEditBox->setText (s);
@@ -2029,7 +2030,21 @@ MacroEditorDialog::search_requested (const QString &s)
searchEditBox->selectAll ();
}
searchEditBox->setFocus ();
- search_editing ();
+
+ MacroEditorPage *page = dynamic_cast (tabWidget->currentWidget ());
+ if (! page) {
+ return;
+ }
+
+ apply_search ();
+ page->find_reset (); // search from the initial position
+ if (! page->has_multi_block_selection ()) {
+ if (! prev) {
+ page->find_next ();
+ } else {
+ page->find_prev ();
+ }
+ }
}
void
@@ -3511,7 +3526,7 @@ MacroEditorDialog::create_page (lym::Macro *macro)
editor->exec_model ()->set_run_mode (m_in_exec);
editor->connect_macro (macro);
connect (editor.get (), SIGNAL (help_requested (const QString &)), this, SLOT (help_requested (const QString &)));
- connect (editor.get (), SIGNAL (search_requested (const QString &)), this, SLOT (search_requested (const QString &)));
+ connect (editor.get (), SIGNAL (search_requested (const QString &, bool)), this, SLOT (search_requested (const QString &, bool)));
connect (editor.get (), SIGNAL (edit_trace (bool)), this, SLOT (add_edit_trace (bool)));
return editor.release ();
}
diff --git a/src/lay/lay/layMacroEditorDialog.h b/src/lay/lay/layMacroEditorDialog.h
index 54d9428df..24bd3eccf 100644
--- a/src/lay/lay/layMacroEditorDialog.h
+++ b/src/lay/lay/layMacroEditorDialog.h
@@ -222,7 +222,7 @@ private slots:
void find_next_button_clicked ();
void find_prev_button_clicked ();
void help_requested (const QString &s);
- void search_requested (const QString &s);
+ void search_requested (const QString &s, bool prev);
void macro_changed (lym::Macro *macro);
void macro_deleted (lym::Macro *macro);
void macro_collection_deleted (lym::MacroCollection *collection);
diff --git a/src/lay/lay/layMacroEditorPage.cc b/src/lay/lay/layMacroEditorPage.cc
index 408949cd2..3abaa328b 100644
--- a/src/lay/lay/layMacroEditorPage.cc
+++ b/src/lay/lay/layMacroEditorPage.cc
@@ -1077,12 +1077,10 @@ MacroEditorPage::find_prev ()
first = false;
int i = -1;
- int l = 0;
int p = 0;
while (true) {
int ii = m_current_search.indexIn (b.text (), p);
if (ii >= 0 && (o < 0 || ii < o)) {
- l = m_current_search.matchedLength ();
i = ii;
p = ii + 1;
} else {
@@ -1091,8 +1089,7 @@ MacroEditorPage::find_prev ()
}
if (i >= 0) {
QTextCursor newc (b);
- newc.setPosition (i + b.position () + l);
- newc.setPosition (i + b.position (), QTextCursor::KeepAnchor);
+ newc.setPosition (i + b.position ());
m_ignore_cursor_changed_event = true;
mp_text->setTextCursor (newc);
m_ignore_cursor_changed_event = false;
@@ -1136,8 +1133,7 @@ MacroEditorPage::find_next ()
int i = m_current_search.indexIn (b.text (), o);
if (i >= 0) {
QTextCursor newc (b);
- newc.setPosition (i + b.position () + m_current_search.matchedLength ());
- newc.setPosition (i + b.position (), QTextCursor::KeepAnchor);
+ newc.setPosition (i + b.position ());
m_ignore_cursor_changed_event = true;
mp_text->setTextCursor (newc);
m_ignore_cursor_changed_event = false;
@@ -1158,6 +1154,39 @@ MacroEditorPage::find_next ()
return false;
}
+bool
+MacroEditorPage::select_match_here ()
+{
+ if (m_current_search == QRegExp ()) {
+ return false;
+ }
+
+ QTextCursor c = mp_text->textCursor ();
+ if (c.isNull ()) {
+ return false;
+ }
+
+ if (c.hasSelection ()) {
+ return true;
+ }
+
+ QTextBlock b = c.block ();
+ int pos = c.position () - b.position ();
+ int i = m_current_search.indexIn (b.text (), pos);
+ if (i == pos) {
+ QTextCursor newc (b);
+ newc.setPosition (i + b.position () + m_current_search.matchedLength ());
+ newc.setPosition (i + b.position (), QTextCursor::KeepAnchor);
+ m_ignore_cursor_changed_event = true;
+ mp_text->setTextCursor (newc);
+ m_ignore_cursor_changed_event = false;
+ emit edit_trace (false);
+ return true;
+ } else {
+ return false;
+ }
+}
+
void
MacroEditorPage::set_editor_focus ()
{
@@ -1196,7 +1225,9 @@ MacroEditorPage::replace_and_find_next (const QString &replace)
return;
}
- replace_in_selection (replace, true);
+ if (select_match_here ()) {
+ replace_in_selection (replace, true);
+ }
find_next ();
}
@@ -1280,12 +1311,8 @@ MacroEditorPage::replace_in_selection (const QString &replace, bool first)
o = i + r.size ();
if (first) {
-
- // in single-selection mode, put cursor past substitution
- c.setPosition (i + b.position ());
has_selection = false;
done = true;
-
} else if (b == be) {
pe += int (r.size ()) - int (m_current_search.matchedLength ());
}
@@ -1734,6 +1761,11 @@ static bool is_find_key (QKeyEvent *ke)
return ke->key () == Qt::Key_F && (ke->modifiers () & Qt::ControlModifier) != 0;
}
+static bool is_find_backwards_key (QKeyEvent *ke)
+{
+ return ke->key () == Qt::Key_F && (ke->modifiers () & Qt::ControlModifier) != 0 && (ke->modifiers () & Qt::ShiftModifier) != 0;
+}
+
static bool is_up_key (QKeyEvent *ke)
{
return ke->key () == Qt::Key_Up;
@@ -1755,6 +1787,7 @@ static bool is_any_known_key (QKeyEvent *ke)
is_help_key (ke) ||
is_find_next_key (ke) ||
is_find_key (ke) ||
+ is_find_backwards_key (ke) ||
is_up_key (ke) ||
is_down_key (ke);
}
@@ -1848,19 +1881,21 @@ MacroEditorPage::eventFilter (QObject *watched, QEvent *event)
QApplication::sendEvent (mp_completer_list, event);
return true;
- } else if (is_find_key (ke)) {
+ } else if (is_find_key (ke) || is_find_backwards_key (ke)) {
+
+ bool prev = is_find_backwards_key (ke);
QTextCursor c = mp_text->textCursor ();
if (c.selectionStart () != c.selectionEnd ()) {
QTextBlock s = mp_text->document ()->findBlock (c.selectionStart ());
QTextBlock e = mp_text->document ()->findBlock (c.selectionEnd ());
if (e == s) {
- emit search_requested (c.selectedText ());
+ emit search_requested (c.selectedText (), prev);
} else {
- emit search_requested (QString ());
+ emit search_requested (QString (), prev);
}
} else {
- emit search_requested (QString ());
+ emit search_requested (QString (), prev);
}
return true;
diff --git a/src/lay/lay/layMacroEditorPage.h b/src/lay/lay/layMacroEditorPage.h
index a689aefe5..c298a32b4 100644
--- a/src/lay/lay/layMacroEditorPage.h
+++ b/src/lay/lay/layMacroEditorPage.h
@@ -271,7 +271,7 @@ public:
signals:
void help_requested (const QString &s);
- void search_requested (const QString &s);
+ void search_requested (const QString &s, bool backward);
void edit_trace (bool);
public slots:
@@ -314,6 +314,7 @@ private:
void fill_completer_list ();
void complete ();
QTextCursor get_completer_cursor (int &pos0, int &pos);
+ bool select_match_here ();
void replace_in_selection (const QString &replace, bool first);
bool eventFilter (QObject *watched, QEvent *event);