On Wed, Sep 3, 2008 at 5:49 AM, John Labenski <[EMAIL PROTECTED]> wrote: > On Tue, Sep 2, 2008 at 11:12 PM, Duncan Cross <[EMAIL PROTECTED]> wrote: >> Hi List, >> >> Could anyone help me with getting brace matching to work (i.e. when >> the text cursor is over a brace, highlight both the brace and its >> matching twin blue, unless the brace is mismatched, in which case >> highlight it red) for a wxStyledTextCtrl control? It seems like it >> should be obvious, but I can't seem to find this information anywhere. >> What change(s) would you make to the editor.wx.lua sample script to do >> this? (I know that it must be possible since wxLuaEditor supports it.) >> > > The wxLuaEditor does it on the C++ side, but perhaps it can be > translated to Lua. > > See: > > http://wxcode.cvs.sourceforge.net/wxcode/wxCode/components/wxstedit/src/stedit.cpp?view=markup > > 156 EVT_STC_UPDATEUI (wxID_ANY, wxSTEditor::OnSTCUpdateUI) > > 340 void wxSTEditor::OnSTCUpdateUI(wxStyledTextEvent &event) > > 1874 void wxSTEditor::DoBraceMatch() > > and > > 1792 bool wxSTEditor::DoFindMatchingBracePosition( > > > Hope this helps, > John
I have managed to get it working, by adding this function: function DoFindMatchingBracePosition(editor) local length = editor.Length; if (length == 0) then return -1,-1 end local pos = editor.CurrentPos; if (pos > 0) and (editor:PositionBefore(pos)==(pos-1)) then local prevc = editor:GetCharAt(pos-1); if (prevc == 91) or (prevc == 93) or (prevc == 123) or (prevc == 125) or (prevc == 40) or (prevc == 41) then return pos-1, editor:BraceMatch(pos-1); end end if (pos < length) and (editor:PositionAfter(pos)==(pos+1)) then local nextc = editor:GetCharAt(pos); if (nextc == 91) or (nextc == 93) or (nextc == 123) or (nextc == 125) or (nextc == 40) or (nextc == 41) then return pos, editor:BraceMatch(pos); end end return -1,-1 end ...and modifying the UPDATE_UI event handler to this: editor:Connect(wxstc.wxEVT_STC_UPDATEUI, function (event) UpdateStatusText(editor) local braceAtCaret,braceOpposite = DoFindMatchingBracePosition(editor) if (braceAtCaret > -1) and (braceOpposite == -1) then editor:BraceBadLight(braceAtCaret) editor:SetHighlightGuide(0) else editor:BraceHighlight(braceAtCaret, braceOpposite) end end) Thanks again for your help. -Duncan ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ wxlua-users mailing list wxlua-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wxlua-users