/// <summary> /// manages Brace highlighting /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void TextArea_UpdateUI(object sender, UpdateUIEventArgs e) { // Has the caret changed position? var caretPos = TextArea.CurrentPosition; if (lastCaretPos != caretPos) { UpdateStatusEventArgs evt = new UpdateStatusEventArgs(); evt.Text = "Pos: " + caretPos.ToString(); FireUpdateStatus(this, evt); lastCaretPos = caretPos; var bracePos1 = -1; var bracePos2 = -1; //TODO Brace higligthing not working or overridden by Lexer?? // Is there a brace to the left or right? if (caretPos > 0 && IsBrace(TextArea.GetCharAt(caretPos - 1))) { bracePos1 = (caretPos - 1); } else if (IsBrace(TextArea.GetCharAt(caretPos))) { bracePos1 = caretPos; } if (bracePos1 >= 0) { // Find the matching brace bracePos2 = TextArea.BraceMatch(bracePos1); if (bracePos2 == Scintilla.InvalidPosition) { TextArea.BraceBadLight(bracePos1); TextArea.HighlightGuide = 0; } else { TextArea.BraceHighlight(bracePos1, bracePos2); TextArea.HighlightGuide = TextArea.GetColumn(bracePos1); } } else { // Turn off brace matching TextArea.BraceHighlight(Scintilla.InvalidPosition, Scintilla.InvalidPosition); TextArea.HighlightGuide = 0; } } }
private void scintilla_UpdateUI(object sender, UpdateUIEventArgs e) { // Has the caret changed position? var caretPos = scintilla1.CurrentPosition; if (lastCaretPos != caretPos) { lastCaretPos = caretPos; var bracePos1 = -1; var bracePos2 = -1; // Is there a brace to the left or right? if (caretPos > 0 && IsBrace(scintilla1.GetCharAt(caretPos - 1))) { bracePos1 = (caretPos - 1); } else if (IsBrace(scintilla1.GetCharAt(caretPos))) { bracePos1 = caretPos; } if (bracePos1 >= 0) { // Find the matching brace bracePos2 = scintilla1.BraceMatch(bracePos1); if (bracePos2 == ScintillaNET.Scintilla.InvalidPosition) { scintilla1.BraceBadLight(bracePos1); } else { scintilla1.BraceHighlight(bracePos1, bracePos2); } } else { // Turn off brace matching scintilla1.BraceHighlight(ScintillaNET.Scintilla.InvalidPosition, ScintillaNET.Scintilla.InvalidPosition); } } }