From db1d5b38dc0deb62a3333b609963a01f2e4c0254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Sun, 10 Jun 2007 15:07:21 +0000 Subject: [PATCH] Fix bug 3160 and 3812: * src/lyxfind.cpp: - MatchString(), operator(): - findForward: - findBackwards: - find: pass bool find_del - replace: - replaceAll: do not replace or find (after replace) deleted text * src/BufferView.cpp: - getStatus: disable LFUN_WORD_REPLACE for deleted text. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18732 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.cpp | 15 +++++++++++---- src/lyxfind.cpp | 27 ++++++++++++++++++--------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index e5ded39267..59587b8130 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -665,6 +665,8 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd) { FuncStatus flag; + Cursor & cur = cursor_; + switch (cmd.action) { case LFUN_UNDO: @@ -678,7 +680,7 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd) case LFUN_FILE_INSERT_PLAINTEXT: case LFUN_BOOKMARK_SAVE: // FIXME: Actually, these LFUNS should be moved to Text - flag.enabled(cursor_.inTexted()); + flag.enabled(cur.inTexted()); break; case LFUN_FONT_STATE: case LFUN_LABEL_INSERT: @@ -691,7 +693,6 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd) case LFUN_NOTE_NEXT: case LFUN_REFERENCE_NEXT: case LFUN_WORD_FIND: - case LFUN_WORD_REPLACE: case LFUN_MARK_OFF: case LFUN_MARK_ON: case LFUN_MARK_TOGGLE: @@ -703,9 +704,13 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd) flag.enabled(true); break; + case LFUN_WORD_REPLACE: + flag.enabled(!cur.paragraph().isDeleted(cur.pos())); + break; + case LFUN_LABEL_GOTO: { flag.enabled(!cmd.argument().empty() - || getInsetByCode(cursor_, Inset::REF_CODE)); + || getInsetByCode(cur, Inset::REF_CODE)); break; } @@ -1617,7 +1622,9 @@ void BufferView::menuInsertLyXFile(string const & filenm) FileDialog fileDlg(_("Select LyX document to insert"), LFUN_FILE_INSERT, make_pair(_("Documents|#o#O"), from_utf8(lyxrc.document_path)), - make_pair(_("Examples|#E#e"), from_utf8(addPath(package().system_support().absFilename(), "examples")))); + make_pair(_("Examples|#E#e"), + from_utf8(addPath(package().system_support().absFilename(), + "examples")))); FileDialog::Result result = fileDlg.open(from_utf8(initpath), diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index ebfa51968e..f24ce695c1 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -62,7 +62,8 @@ public: {} // returns true if the specified string is at the specified position - bool operator()(Paragraph const & par, pos_type pos) const + // del specifies whether deleted strings in ct mode will be considered + bool operator()(Paragraph const & par, pos_type pos, bool del = true) const { docstring::size_type const size = str.length(); pos_type i = 0; @@ -74,6 +75,8 @@ public: break; if (!cs && uppercase(str[i]) != uppercase(par.getChar(pos + i))) break; + if (!del && par.isDeleted(pos + i)) + break; } if (size != docstring::size_type(i)) @@ -101,20 +104,24 @@ private: }; -bool findForward(DocIterator & cur, MatchString const & match) +bool findForward(DocIterator & cur, MatchString const & match, + bool find_del = true) { for (; cur; cur.forwardChar()) - if (cur.inTexted() && match(cur.paragraph(), cur.pos())) + if (cur.inTexted() && + match(cur.paragraph(), cur.pos(), find_del)) return true; return false; } -bool findBackwards(DocIterator & cur, MatchString const & match) +bool findBackwards(DocIterator & cur, MatchString const & match, + bool find_del = true) { while (cur) { cur.backwardChar(); - if (cur.inTexted() && match(cur.paragraph(), cur.pos())) + if (cur.inTexted() && + match(cur.paragraph(), cur.pos(), find_del)) return true; } return false; @@ -141,7 +148,8 @@ bool searchAllowed(BufferView * bv, docstring const & str) } -bool find(BufferView * bv, docstring const & searchstr, bool cs, bool mw, bool fw) +bool find(BufferView * bv, docstring const & searchstr, bool cs, bool mw, bool fw, + bool find_del = true) { if (!searchAllowed(bv, searchstr)) return false; @@ -150,7 +158,8 @@ bool find(BufferView * bv, docstring const & searchstr, bool cs, bool mw, bool f MatchString const match(searchstr, cs, mw); - bool found = fw ? findForward(cur, match) : findBackwards(cur, match); + bool found = fw ? findForward(cur, match, find_del) : + findBackwards(cur, match, find_del); if (found) bv->putSelectionAt(cur, searchstr.length(), !fw); @@ -177,7 +186,7 @@ int replaceAll(BufferView * bv, int const ssize = searchstr.size(); DocIterator cur = doc_iterator_begin(buf.inset()); - while (findForward(cur, match)) { + while (findForward(cur, match, false)) { pos_type pos = cur.pos(); Font const font = cur.paragraph().getFontSettings(buf.params(), pos); @@ -227,7 +236,7 @@ int replace(BufferView * bv, docstring const & searchstr, Cursor & cur = bv->cursor(); cap::replaceSelectionWithString(cur, replacestr, fw); bv->buffer()->markDirty(); - find(bv, searchstr, cs, mw, fw); + find(bv, searchstr, cs, mw, fw, false); bv->update(); return 1;