void HandleSelectionChanged_OnExpandSel(IGraphics g, SelectionChangedEventArgs e, int caretLine, int caretColumn) { Document doc = this.Document; int begin, beginL; int end, endL; int beginLineHead, endLineHead; // if anchor was moved, invalidate largest range made with four indexes if (e.OldAnchor != doc.AnchorIndex) { begin = Utl.Min(e.OldAnchor, e.OldCaret, doc.AnchorIndex, doc.CaretIndex); end = Utl.Max(e.OldAnchor, e.OldCaret, doc.AnchorIndex, doc.CaretIndex); Invalidate(begin, end); return; } // get range between old caret and current caret if (e.OldCaret < doc.CaretIndex) { begin = e.OldCaret; beginL = doc.ViewParam.PrevCaretLine; end = doc.CaretIndex; endL = caretLine; } else { begin = doc.CaretIndex; beginL = caretLine; end = e.OldCaret; endL = doc.ViewParam.PrevCaretLine; } beginLineHead = GetLineHeadIndex(beginL); endLineHead = GetLineHeadIndex(endL); // if old caret is the end pos and if the pos exceeds current text length, this will fail. // invalidate Invalidate_MultiLines(g, begin, end, beginL, endL, beginLineHead, endLineHead); }
void HandleSelectionChanged_OnExpandSelInLine(IGraphics g, SelectionChangedEventArgs e, int begin, int end, int beginL) { DebugUtl.Assert(beginL < LineCount); Debug.Assert(TextUtil.IsDividableIndex(Document.InternalBuffer, begin)); Debug.Assert(TextUtil.IsDividableIndex(Document.InternalBuffer, end)); var doc = Document; var rect = new Rectangle(); // if anchor was moved, invalidate largest range made with four indexes if (e.OldAnchor != doc.AnchorIndex) { begin = Utl.Min(e.OldAnchor, e.OldCaret, doc.AnchorIndex, doc.CaretIndex); end = Utl.Max(e.OldAnchor, e.OldCaret, doc.AnchorIndex, doc.CaretIndex); Invalidate(begin, end); return; } // calculate location of invalid rectangle var beginLineHead = GetLineHeadIndex(beginL); if (beginLineHead < begin) { rect.X = MeasureTokenEndX(g, new TextSegment(beginLineHead, begin), 0); } rect.Y = YofLine(beginL); // calculate width of invalid rectangle rect.Width = MeasureTokenEndX(g, new TextSegment(beginLineHead, end), 0) - rect.X; rect.Height = LineSpacing; // invalidate rect.X -= (ScrollPosX - XofTextArea); Invalidate(rect); }
void HandleSelectionChanged_OnExpandSelInLine(IGraphics g, SelectionChangedEventArgs e, int begin, int end, int beginL) { DebugUtl.Assert(beginL < LineCount); Document doc = Document; Rectangle rect = new Rectangle(); int beginLineHead; string token = String.Empty; // if anchor was moved, invalidate largest range made with four indexes if (e.OldAnchor != doc.AnchorIndex) { begin = Utl.Min(e.OldAnchor, e.OldCaret, doc.AnchorIndex, doc.CaretIndex); end = Utl.Max(e.OldAnchor, e.OldCaret, doc.AnchorIndex, doc.CaretIndex); Invalidate(begin, end); return; } // get chars at left of invalid rect beginLineHead = GetLineHeadIndex(beginL); if (beginLineHead < begin) { token = Document.GetTextInRangeRef(ref beginLineHead, ref begin); } // calculate invalid rect rect.X = MeasureTokenEndX(g, token, 0); rect.Y = YofLine(beginL); token = Document.GetTextInRangeRef(ref beginLineHead, ref end); rect.Width = MeasureTokenEndX(g, token, 0) - rect.X; rect.Height = LineSpacing; // invalidate rect.X -= (ScrollPosX - XofTextArea); Invalidate(rect); }