#4 Bug in ReplaceText()

closed
nobody
None
5
2007-09-13
2007-08-24
cfreeer
No

Version:0.2.7 and svn
Condition: If the lenth of text selected is shorter or longer than the text string that is to be replaced, the selected one will not be replace in the first replace action.

patch:
--- MadEdit.cpp 2007-08-24 15:06:12.000000000 +0800
+++ madedit-0.2.7/src/MadEdit/MadEdit.cpp 2007-02-27 22:57:14.000000000 +0800
@@ -13532,15 +13532,33 @@
if(expr.Len()==0)
return true;

+ bool selok=false;
+
MadCaretPos bpos=*m_SelectionBegin;
MadCaretPos epos=*m_SelectionEnd;

if(m_Selection) // test the selection is wanted text
{
- m_Selection = false;
- m_CaretPos = *m_SelectionBegin;
+ int state=Search(bpos, epos, expr, bRegex, bCaseSensitive, bWholeWord);
+
+ if(state==SR_EXPR_ERROR)
+ {
+ return false;
+ }
+
+ if(state==SR_YES)
+ {
+ if(bpos.pos==m_SelectionBegin->pos && epos.pos==m_SelectionEnd->pos)
+ {
+ selok=true;
+ }
+ }
+ }
+
+ if(!selok) // just find next
+ {
+ return SR_EXPR_ERROR!=FindTextNext(expr, bRegex, bCaseSensitive, bWholeWord, false);
}
- FindTextNext(expr, bRegex, bCaseSensitive, bWholeWord, false);

ucs4string out;

Discussion

  • cfreeer
    cfreeer
    2007-08-24

    Logged In: YES
    user_id=1834931
    Originator: YES

    Sorry for the wrong diff file.

    --- madedit-0.2.7/src/MadEdit/MadEdit.cpp 2007-02-27 22:57:14.000000000 +0800
    +++ MadEdit.cpp 2007-08-24 15:06:12.000000000 +0800
    @@ -13532,33 +13532,15 @@
    if(expr.Len()==0)
    return true;

    - bool selok=false;
    -
    MadCaretPos bpos=*m_SelectionBegin;
    MadCaretPos epos=*m_SelectionEnd;

    if(m_Selection) // test the selection is wanted text
    {
    - int state=Search(bpos, epos, expr, bRegex, bCaseSensitive, bWholeWord);
    -
    - if(state==SR_EXPR_ERROR)
    - {
    - return false;
    - }
    -
    - if(state==SR_YES)
    - {
    - if(bpos.pos==m_SelectionBegin->pos && epos.pos==m_SelectionEnd->pos)
    - {
    - selok=true;
    - }
    - }
    - }
    -
    - if(!selok) // just find next
    - {
    - return SR_EXPR_ERROR!=FindTextNext(expr, bRegex, bCaseSensitive, bWholeWord, false);
    + m_Selection = false;
    + m_CaretPos = *m_SelectionBegin;
    }
    + FindTextNext(expr, bRegex, bCaseSensitive, bWholeWord, false);

    ucs4string out;
    File Added: diiff.patch

     
  • cfreeer
    cfreeer
    2007-08-27

    Logged In: YES
    user_id=1834931
    Originator: YES

    File Added: diiff.patch

     
  • cfreeer
    cfreeer
    2007-08-27

     
    Attachments
  • madedit
    madedit
    2007-09-13

    • status: open --> closed
     
  • madedit
    madedit
    2007-09-13

    Logged In: YES
    user_id=1131399
    Originator: NO

    I think that it isn't a bug.

    MadEdit always find/replace text from the position of SelectionEnd if the selected text isn't matched.

    Now I have changed the behavior in SVN,
    It will find/replace text from current CaretPos rather than SelectionEnd.

     
  • cfreeer
    cfreeer
    2007-09-14

    Logged In: YES
    user_id=1834931
    Originator: YES

    OK, just fix it if you have better one.

     
  • cfreeer
    cfreeer
    2007-09-14

    Logged In: YES
    user_id=1834931
    Originator: YES

    I tested your patch. I don't think it's a perfect one and my test cases failed. I debugged and I got the reason.
    If the caretpos == m_SelectionBegin, it works fine. But if the caretpos == m_SelectionEnd(what are my test cases), it dosen't work.
    So I think you may change the "else if(m_Selection)" branch as I indicated as below instead of comment them out.
    Please think about it.
    MadSearchResult MadEdit::FindTextNext(const wxString &text, bool bRegex, bool bCaseSensitive, bool bWholeWord, bool bFromDocBegin)

    else if(m_Selection)
    {
    bpos=*m_SelectionBegin;
    }