From 4cb477a91d1d1244691ab89d26c9fc650168d6ec Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Wed, 9 Jun 2021 21:43:51 +0200 Subject: [PATCH] Macro IDE: replace only in selected text if multi-line selection is present --- src/lay/lay/layMacroEditorPage.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lay/lay/layMacroEditorPage.cc b/src/lay/lay/layMacroEditorPage.cc index ec1c42bb6..10003778b 100644 --- a/src/lay/lay/layMacroEditorPage.cc +++ b/src/lay/lay/layMacroEditorPage.cc @@ -1150,10 +1150,21 @@ MacroEditorPage::replace_all (const QString &replace) const QTextDocument *doc = mp_text->document (); + QTextBlock bs = doc->begin (), be = doc->end (); + QTextCursor c = mp_text->textCursor (); + if (c.hasSelection ()) { + QTextBlock s = mp_text->document ()->findBlock (mp_text->textCursor ().selectionStart ()); + QTextBlock e = mp_text->document ()->findBlock (mp_text->textCursor ().selectionEnd ()); + if (e != s) { + bs = s; + be = e; + } + } + c.beginEditBlock (); - for (QTextBlock b = doc->begin(); b != doc->end(); b = b.next()) { + for (QTextBlock b = bs; b != be; b = b.next()) { int o = 0;