private void Intellua_SelectionChanged(object sender, EventArgs e) { if (!Parse) { return; } ShowCalltip(); const string lbracket = "([{"; const string rbracket = ")]}"; int pos = CurrentPos; int style = Styles.GetStyleAt(pos - 1); int start, end; start = end = -1; Byte[] str = RawText; Stack <char> stk = new Stack <char>(); for (int p = pos - 1; p >= 0; p--) { // if (Styles.GetStyleAt(p) != style) continue; if (p >= str.Length) { continue; } if (str[p] > 127) { continue; } char c = Convert.ToChar(str[p]); if (rbracket.Contains(c)) { stk.Push(c); } if (lbracket.Contains(c)) { if (stk.Count == 0) { start = p; break; } char pc = stk.Pop(); if ((pc == ')' && c != '(') || (pc == ']' && c != '[') || (pc == '}' && c != '{')) { break; } } } stk.Clear(); for (int p = pos; p < str.Length; p++) { // if (Styles.GetStyleAt(p) != style) continue; if (str[p] > 127) { continue; } char c = Convert.ToChar(str[p]); if (lbracket.Contains(c)) { stk.Push(c); } if (rbracket.Contains(c)) { if (stk.Count == 0) { end = p; break; } char pc = stk.Pop(); if ((pc != ')' && c == '(') || (pc != ']' && c == '[') || (pc != '}' && c == '{')) { break; } } } if (start >= 0 && end >= 0) { char c = Convert.ToChar(str[start]); char pc = Convert.ToChar(str[end]); if ((pc != ')' && c == '(') || (pc != ']' && c == '[') || (pc != '}' && c == '{')) { start = -1; } } if (start != -1) { //start = Encoding.GetByteCount(Text.ToCharArray(), 0, start+1)-1; } if (end != -1) { //end = Encoding.GetByteCount(Text.ToCharArray(), 0, end + 1) - 1; } if (start == -1) { if (end != -1) { NativeInterface.BraceBadLight(end); } else { NativeInterface.BraceHighlight(-1, -1); } } else if (end == -1) { if (start != -1) { NativeInterface.BraceBadLight(start); } else { NativeInterface.BraceHighlight(-1, -1); } } else { NativeInterface.BraceHighlight(start, end); } }