private void Caret_PositionChanged(object sender, EventArgs e) { var offset = TextArea.Caret.Offset - 1; if (offset > 0) { var letter = base.TextArea.Document.GetCharAt(offset); if (letter == '[' || letter == ']') { var loc = base.Document.GetLocation(offset); var cuppledLoc = MatchingFarenthesisFinder.Find(base.Document, loc).Location; var cuppledLocOffset = cuppledLoc.IsEmpty ? -1 : base.Document.GetOffset(cuppledLoc); _pointsColorizer.Points = new[] { offset, cuppledLocOffset }; } else { _pointsColorizer.Clear(); } this.TextArea.TextView.Redraw(); } }
private void TextArea_TextEntered(object sender, TextCompositionEventArgs e) { var lastLine = this.TextArea.Document.GetLineByNumber(this.TextArea.Document.LineCount); if (lastLine.Length != 0) { var caretOffset = TextArea.Caret.Offset; this.TextArea.Document.Insert(lastLine.EndOffset, LocalEnvironmental.Delimiter); TextArea.Caret.Offset = caretOffset; } if (e.Text.Length == 1) { if (this.TextArea.Selection.Length == 0) { base.TextArea.Document.BeginUpdate(); if (e.Text[0] == '[') { TextArea.Document.Insert(TextArea.Caret.Offset, "]"); TextArea.Caret.Offset--; } else if (e.Text[0] == ']') { if (TextArea.Caret.Offset < TextArea.Document.TextLength && TextArea.Document.GetCharAt(TextArea.Caret.Offset) == ']') { TextArea.Document.Remove(TextArea.Caret.Offset, 1); } #region 自動インデント var loc = TextArea.Document.GetLocation(TextArea.Caret.Offset - 1); var matchedLoc = MatchingFarenthesisFinder.Find(TextArea.Document, loc).Location; TextArea.IndentationStrategy?.IndentLines(TextArea.Document, matchedLoc.IsEmpty ? 1 : matchedLoc.Line, loc.Line); #endregion } base.TextArea.Document.EndUpdate(); } } }