From 0a5c83adfd16308d1a59d63f4e170500d1b69816 Mon Sep 17 00:00:00 2001 From: "Zane U. Ji" Date: Sun, 12 Oct 2014 20:49:08 +0800 Subject: [PATCH] Feature #170 I did a small patch that allows SPACE to trigger autocompletion on any space (Thanassis Tsiodras) --- src/xmlctrl.cpp | 25 +++++++++++++++++++++---- src/xmlctrl.h | 1 + 2 files changed, 22 insertions(+), 4 deletions(-) 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;