diff --git a/src/tabs.cpp b/src/tabs.cpp index 693bc5f..5899f01 100644 --- a/src/tabs.cpp +++ b/src/tabs.cpp @@ -145,27 +145,50 @@ int brackets; } +bool IsWhite(int c) +{ + return c==' ' || c=='\t'; +} + + +bool IsOpeningOperand(int c) +{ + return c=='-' || c=='+' || c=='*' ||c=='/' || c=='%' ||c=='^' || c=='('; +} + + +bool IsOpeningOperandBefore(const char * buf, int end) +{ + while( end > 0 && IsWhite(buf[end-1]) ) + end -= 1; + + if( end == 0 ) + return false; + +return IsOpeningOperand(buf[end-1]); +} + + + void CalcBracketsPos(HWND input, int & start, int & end) { DWORD sel_start, sel_end; SendMessage(input, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end); - if( sel_start != sel_end ) - { - start = sel_start; - end = sel_end; + start = sel_start; + end = sel_end; + + if( start != end ) return; - } char * buf = GetPrgRes()->GetBufferTemp(); - start = 0; - end = SendMessage(input, WM_GETTEXT, GetPrgRes()->GetBufferSize(), (LPARAM)buf); + int len = SendMessage(input, WM_GETTEXT, GetPrgRes()->GetBufferSize(), (LPARAM)buf); - if( end > 0 ) + if( len > 0 && !IsOpeningOperandBefore(buf, end) ) { start = CalcBracketsPrev(buf, sel_start); - end = CalcBracketsNext(buf, end, sel_start); + end = CalcBracketsNext(buf, len, sel_start); } }