diff --git a/src/xmlctrl.cpp b/src/xmlctrl.cpp index 7e8ed0f..bd1bc7c 100644 --- a/src/xmlctrl.cpp +++ b/src/xmlctrl.cpp @@ -622,9 +622,9 @@ void XmlCtrl::handleSpace ( wxKeyEvent& event ) return; } - int style = getLexerStyleAt ( pos - 1 ); - - char c = GetCharAt ( pos - 1 ); + int prevPos; + char c = getPrevNonSpaceChar ( pos, &prevPos ); + int style = getLexerStyleAt ( prevPos ); bool proceed = false; // space pressed after element name @@ -641,7 +641,7 @@ void XmlCtrl::handleSpace ( wxKeyEvent& event ) ( style == wxSTC_H_DOUBLESTRING || style == wxSTC_H_SINGLESTRING ) && ( c == '\'' || c == '"' ) && - GetCharAt ( pos - 2 ) != '=' ) + getPrevNonSpaceChar ( prevPos - 1, NULL ) != '=' ) { proceed = true; } @@ -2403,3 +2403,20 @@ void XmlCtrl::OnKillFocus ( wxFocusEvent &event ) AutoCompCancel(); event.Skip(); } + +int XmlCtrl::getPrevNonSpaceChar ( int curPos, int *charPos ) +{ + int c = 0; + int pos = curPos; + while ( pos-- > 0 ) + { + c = GetCharAt ( pos ); + if ( !wxIsspace ( c ) ) + break; + } + + if ( charPos ) + *charPos = pos; + + return c; +} diff --git a/src/xmlctrl.h b/src/xmlctrl.h index 3c1d3f0..aa4f432 100644 --- a/src/xmlctrl.h +++ b/src/xmlctrl.h @@ -162,6 +162,7 @@ class XmlCtrl: public wxStyledTextCtrl bool selectCurrentElement(); void toggleComment(); wxString getCurrentXPath(); + int getPrevNonSpaceChar ( int curPos, int *charPos ); private: ValidationThread *validationThread; // used for background validation XmlPromptGenerator *mPromptGeneratorThread;