From 793b375202467d880b598cc7ead5b08446a5b04f Mon Sep 17 00:00:00 2001 From: John Levon Date: Tue, 8 Apr 2003 00:02:32 +0000 Subject: [PATCH] alfredo's patch for 782 and 1020 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6732 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 4 +++ src/insets/ChangeLog | 4 +++ src/insets/insettabular.C | 21 ++++++++------- src/lyxfind.C | 55 +++++++++++---------------------------- 4 files changed, 34 insertions(+), 50 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 9107b98f8b..c3e63fa32e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2003-04-05 Alfredo Braunstein + + * lyxfind.C (searchForward, searchBackwards): bug 782 + 2003-04-07 John Levon * paragraph.C: remove dead comment diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 669b1ddba4..2260e7041d 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,7 @@ +2003-04-05 Alfredo Braunstein + + * insettabular.C (searchForward,searchBackward): fix bug 782 + 2003-04-07 John Levon * insettabular.C: diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index d8964618a8..312f91cce1 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -2720,6 +2720,7 @@ bool InsetTabular::nextChange(BufferView * bv, lyx::pos_type & length) bool InsetTabular::searchForward(BufferView * bv, string const & str, bool cs, bool mw) { + int cell = 0; if (the_locking_inset) { if (the_locking_inset->searchForward(bv, str, cs, mw)) { updateLocal(bv, CELL); @@ -2727,16 +2728,16 @@ bool InsetTabular::searchForward(BufferView * bv, string const & str, } if (tabular->IsLastCell(actcell)) return false; - ++actcell; + cell = actcell + 1; } - InsetText * inset = tabular->GetCellInset(actcell); + InsetText * inset = tabular->GetCellInset(cell); if (inset->searchForward(bv, str, cs, mw)) { updateLocal(bv, FULL); return true; } - while (!tabular->IsLastCell(actcell)) { - ++actcell; - inset = tabular->GetCellInset(actcell); + while (!tabular->IsLastCell(cell)) { + ++cell; + inset = tabular->GetCellInset(cell); if (inset->searchForward(bv, str, cs, mw)) { updateLocal(bv, FULL); return true; @@ -2749,18 +2750,18 @@ bool InsetTabular::searchForward(BufferView * bv, string const & str, bool InsetTabular::searchBackward(BufferView * bv, string const & str, bool cs, bool mw) { + int cell = tabular->GetNumberOfCells(); if (the_locking_inset) { if (the_locking_inset->searchBackward(bv, str, cs, mw)) { updateLocal(bv, CELL); return true; } + cell = actcell; } - if (!locked) - actcell = tabular->GetNumberOfCells(); - while (actcell) { - --actcell; - InsetText * inset = tabular->GetCellInset(actcell); + while (cell) { + --cell; + InsetText * inset = tabular->GetCellInset(cell); if (inset->searchBackward(bv, str, cs, mw)) { updateLocal(bv, CELL); return true; diff --git a/src/lyxfind.C b/src/lyxfind.C index 9570147e24..4fc2dcbba9 100644 --- a/src/lyxfind.C +++ b/src/lyxfind.C @@ -143,6 +143,7 @@ bool LyXFind(BufferView * bv, // we are! LyXText * text = bv->text; + if (text->selection.set()) text->cursor = forward ? text->selection.end : text->selection.start; @@ -233,27 +234,17 @@ SearchResult SearchForward(BufferView * bv, LyXText * text, string const & str, { Paragraph * par = text->cursor.par(); pos_type pos = text->cursor.pos(); - Paragraph * prev_par = par; UpdatableInset * inset; while (par && !IsStringInText(par, pos, str, cs, mw)) { - if (par->isInset(pos) && - (inset = (UpdatableInset *)par->getInset(pos)) && - (inset->isTextInset())) - { -#if 0 - // lock the inset! - text->setCursor(bv, par, pos); - inset->edit(bv); -#endif - if (inset->searchForward(bv, str, cs, mw)) - return SR_FOUND_NOUPDATE; - } + if (pos < par->size() + && par->isInset(pos) + && (inset = (UpdatableInset *)par->getInset(pos)) + && inset->isTextInset() + && inset->searchForward(bv, str, cs, mw)) + return SR_FOUND_NOUPDATE; - ++pos; - - if (pos >= par->size()) { - prev_par = par; + if (++pos >= par->size()) { par = par->next(); pos = 0; } @@ -262,12 +253,8 @@ SearchResult SearchForward(BufferView * bv, LyXText * text, string const & str, if (par) { text->setCursor(par, pos); return SR_FOUND; - } else { - // make sure we end up at the end of the text, - // not the start point of the last search - text->setCursor(prev_par, prev_par->size()); + } else return SR_NOT_FOUND; - } } @@ -280,13 +267,11 @@ SearchResult SearchBackward(BufferView * bv, LyXText * text, { Paragraph * par = text->cursor.par(); pos_type pos = text->cursor.pos(); - Paragraph * prev_par = par; do { if (pos > 0) --pos; else { - prev_par = par; // We skip empty paragraphs (Asger) do { par = par->previous(); @@ -295,28 +280,18 @@ SearchResult SearchBackward(BufferView * bv, LyXText * text, } while (par && pos < 0); } UpdatableInset * inset; - if (par && par->isInset(pos) && - (inset = (UpdatableInset *)par->getInset(pos)) && - (inset->isTextInset())) - { -#if 0 - // lock the inset! - text->setCursor(bv, par, pos); - inset->edit(bv, false); -#endif - if (inset->searchBackward(bv, str, cs, mw)) - return SR_FOUND_NOUPDATE; - } + if (par && par->isInset(pos) + && (inset = (UpdatableInset *)par->getInset(pos)) + && inset->isTextInset() + && inset->searchBackward(bv, str, cs, mw)) + return SR_FOUND_NOUPDATE; } while (par && !IsStringInText(par, pos, str, cs, mw)); if (par) { text->setCursor(par, pos); return SR_FOUND; - } else { - // go to the last part of the unsuccessful search - text->setCursor(prev_par, 0); + } else return SR_NOT_FOUND; - } }