Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

Issue about wxScintilla

(1/3) > >>

Loaden:
Hi, all!
I encountered a problem about scintilla.

--- Quote ---void CodeRefactoring::Find(cbStyledTextCtrl* control, const wxString& file, const wxString& target)
{
    const int end = control->GetLength();
    int start = 0;
    int pos = 0;

    for (;;)
    {
        int lengthFound;
        pos = control->FindText(start, end, target, wxSCI_FIND_WHOLEWORD | wxSCI_FIND_MATCHCASE, &lengthFound);
        if (pos != wxSCI_INVALID_POSITION)
        {
            start = pos + lengthFound;

           // TODO (Loaden) not work?
            const int style = control->GetStyleAt(pos); // always been zero?
            if (control->IsString(style) || control->IsComment(style))
                continue;

            int line = control->LineFromPosition(pos);
            wxString text = control->GetLine(line).Trim(true).Trim(false);
            m_SearchDataMap[file].push_back(crSearchData(pos, line, text));
        }
        else
            break;
    }
}
--- End quote ---
Please see the bold style code, why the return value always been zero.
Any comment are welcome!

Example code:

--- Code: ---int test()
{
    // test
    printf("test");
}
--- End code ---
When call control->FindText, we will get three result, include the comment(test) and string (test).

Here are "find references" result:

--- Quote ---main.cpp|1|int test()|
main.cpp|3|// test|
main.cpp|4|printf("test");|

--- End quote ---

Jenna:
I did a quick test with trunk (modified my IncrementalSearch-plugin to spit out the style for every found string, and I get:

--- Code: ---pos: 4; style: 11
pos: 20; style: 2
pos: 37; style: 6
--- End code ---
three different styles.

MortenMacFly:

--- Quote from: jens on September 30, 2010, 08:31:23 am ---
--- Code: ---pos: 4; style: 11
pos: 20; style: 2
pos: 37; style: 6
--- End code ---
three different styles.

--- End quote ---
Same here with a dummy project (plugin), however, debugging into the code Loaden mentioned I also get zero always. So the root must be somewhere else, not in scintilla.

ollydbg:

--- Quote from: MortenMacFly on September 30, 2010, 10:14:52 am ---debugging into the code Loaden mentioned I also get zero always.

--- End quote ---
Confirmed. strange...

Jenna:

--- Quote from: ollydbg on September 30, 2010, 10:56:03 am ---
--- Quote from: MortenMacFly on September 30, 2010, 10:14:52 am ---debugging into the code Loaden mentioned I also get zero always.

--- End quote ---
Confirmed. strange...

--- End quote ---
No, not strange.
The code do not use the cbEditor, but just the cbStyledTextctrl, but without a lexer and without highlighting any code, so GetStyleAt can not return anything but the default value, because the text is not styled.

The following patch should do the trick:

--- Code: ---Index: coderefactoring.cpp
===================================================================
--- coderefactoring.cpp (Revision 6654)
+++ coderefactoring.cpp (Arbeitskopie)
@@ -156,6 +156,9 @@
                 continue; // failed
             control->SetText(detector.GetWxStr());
         }
+        cbEditor::ApplyStyles(control);
+        EditorColourSet EdColSet;
+        EdColSet.Apply(EdColSet.GetLanguageForFilename(files[i]), control);
 
         Find(control, files[i], targetText);
     }

--- End code ---

Shall I commit it ?

Navigation

[0] Message Index

[#] Next page

Go to full version