From 567d0e8fb4f42cefbce03487b57d51f17ed042cf Mon Sep 17 00:00:00 2001 From: Kornel Benko Date: Thu, 26 May 2022 17:17:49 +0200 Subject: [PATCH] FindAdv: Amend 652ffc9c: have to check inTexted() before using Paragraph --- src/lyxfind.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index 83bb13a22a..25b2d29a1f 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -4857,16 +4857,21 @@ bool findAdv(BufferView * bv, FindAndReplaceOptions & opt) num_replaced += findAdvReplace(bv, opt, matchAdv); cur = bv->cursor(); if (opt.forward) { - if (opt.matchword) { // Skip word-characters if we are in the mid of a word - Paragraph const & par = cur.paragraph(); - if ((cur.pos() > 0) && !par.isWordSeparator(cur.pos() -1, true)) { - while (cur.pos() < par.size()) { - if (par.isWordSeparator(cur.pos(), true)) - break; - else - cur.forwardPos(); + if (opt.matchword && cur.pos() > 0) { // Skip word-characters if we are in the mid of a word + if (cur.inTexted()) { + Paragraph const & par = cur.paragraph(); + if ((cur.pos() > 0) && !par.isWordSeparator(cur.pos() -1, true)) { + class Text *t = cur.text(); + CursorSlice to; + CursorSlice from = cur.top(); + t->getWord(from, to, WHOLE_WORD); + cur.pos() = to.pos(); + cur.pit() = to.pit(); } } + else if (cur.inMathed()) { + cur.pos() = cur.lastpos(); + } opt.matchword = false; } pos_len = findForwardAdv(cur, matchAdv);