mirror of https://github.com/KLayout/klayout.git
Some more enhancements for search & replace in macro editor
This commit is contained in:
parent
71487af411
commit
2e4153c04a
|
|
@ -1220,15 +1220,18 @@ MacroEditorPage::replace_in_selection (const QString &replace, bool first)
|
||||||
int pe = be.length ();
|
int pe = be.length ();
|
||||||
|
|
||||||
QTextCursor c = mp_text->textCursor ();
|
QTextCursor c = mp_text->textCursor ();
|
||||||
if (c.hasSelection ()) {
|
bool has_selection = c.hasSelection ();
|
||||||
|
bool anchor_at_end = false;
|
||||||
|
|
||||||
ps = mp_text->textCursor ().selectionStart ();
|
if (has_selection) {
|
||||||
pe = mp_text->textCursor ().selectionEnd ();
|
|
||||||
|
anchor_at_end = (c.selectionStart () == c.position ());
|
||||||
|
|
||||||
|
ps = c.selectionStart ();
|
||||||
|
pe = c.selectionEnd ();
|
||||||
|
|
||||||
bs = mp_text->document ()->findBlock (ps);
|
bs = mp_text->document ()->findBlock (ps);
|
||||||
be = mp_text->document ()->findBlock (pe);
|
be = mp_text->document ()->findBlock (pe);
|
||||||
ps -= bs.position ();
|
|
||||||
pe -= be.position ();
|
|
||||||
|
|
||||||
} else if (first) {
|
} else if (first) {
|
||||||
|
|
||||||
|
|
@ -1237,6 +1240,9 @@ MacroEditorPage::replace_in_selection (const QString &replace, bool first)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ps -= bs.position ();
|
||||||
|
pe -= be.position ();
|
||||||
|
|
||||||
c.beginEditBlock ();
|
c.beginEditBlock ();
|
||||||
|
|
||||||
bool done = false;
|
bool done = false;
|
||||||
|
|
@ -1252,13 +1258,13 @@ MacroEditorPage::replace_in_selection (const QString &replace, bool first)
|
||||||
int i = m_current_search.indexIn (b.text (), o);
|
int i = m_current_search.indexIn (b.text (), o);
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
break;
|
break;
|
||||||
} else if (b == bs && i < ps) {
|
|
||||||
// ignore
|
|
||||||
} else if (b == be && i >= pe) {
|
|
||||||
// ignore
|
|
||||||
done = true;
|
|
||||||
} else if (m_current_search.matchedLength () == 0) {
|
} else if (m_current_search.matchedLength () == 0) {
|
||||||
break; // avoid an infinite loop
|
break; // avoid an infinite loop
|
||||||
|
} else if (b == bs && i < ps) {
|
||||||
|
// ignore
|
||||||
|
} else if (b == be && i + m_current_search.matchedLength () > pe) {
|
||||||
|
// ignore
|
||||||
|
done = true;
|
||||||
} else {
|
} else {
|
||||||
substitute = true;
|
substitute = true;
|
||||||
}
|
}
|
||||||
|
|
@ -1273,7 +1279,16 @@ MacroEditorPage::replace_in_selection (const QString &replace, bool first)
|
||||||
|
|
||||||
o = i + r.size ();
|
o = i + r.size ();
|
||||||
|
|
||||||
done = first;
|
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 ());
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
@ -1289,6 +1304,13 @@ MacroEditorPage::replace_in_selection (const QString &replace, bool first)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (has_selection) {
|
||||||
|
// restore selection which might have changed due to insert
|
||||||
|
c.setPosition (anchor_at_end ? be.position () + pe : bs.position () + ps);
|
||||||
|
c.setPosition (!anchor_at_end ? be.position () + pe : bs.position () + ps, QTextCursor::KeepAnchor);
|
||||||
|
}
|
||||||
|
|
||||||
|
mp_text->setTextCursor (c);
|
||||||
c.endEditBlock ();
|
c.endEditBlock ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue