From 253356aafe2c6f0da1cedfb42068b9a0401de3dc Mon Sep 17 00:00:00 2001 From: Jonathan Pobst Date: Fri, 4 Jan 2008 20:26:26 +0000 Subject: [PATCH] 2008-01-03 Jonathan Pobst * LineTag.cs: If the line doesn't have any characters, return 0 for GetCharIndex. Fixes an AOORE exception after certain caret movements. Fixes bug #351683. svn path=/trunk/mcs/; revision=92254 --- .../System.Windows.Forms/ChangeLog | 6 ++++++ .../System.Windows.Forms/LineTag.cs | 11 ++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog index a8155abf63a..2e6b26a9934 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog @@ -1,3 +1,9 @@ +2008-01-03 Jonathan Pobst + + * LineTag.cs: If the line doesn't have any characters, return + 0 for GetCharIndex. Fixes an AOORE exception after certain + caret movements. Fixes bug #351683. + 2008-01-03 Jonathan Pobst * TextBoxBase.cs: Apply patch from Luke Page so when backspace diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/LineTag.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/LineTag.cs index 6868ca19512..986639537d5 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/LineTag.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/LineTag.cs @@ -499,19 +499,24 @@ namespace System.Windows.Forms // Gets the character at the x-coordinate. Index is based from the // line, not the start of the tag. + // returns 0 based index (0 means before character at 1, 1 means at character 1) public int GetCharIndex (int x) { int low = start; int high = low + Length; + int length_no_ending = line.TextLengthWithoutEnding (); if (Length == 0) return start; + + if (length_no_ending == 0) + return 0; if (x < line.widths[low]) return low - 1; - - if (x > line.widths[line.TextLengthWithoutEnding ()]) - return line.TextWithoutEnding ().Length; + + if (x > line.widths[length_no_ending]) + return length_no_ending; while (low < high - 1) { int mid = (high + low) / 2; -- 2.25.1