public void HandleMouseDown(Point mousepos, MouseButtons mouseButtons) { TextLocation selectionStartPos; TextArea.SelectionManager.WhereFrom = SelSource.Gutter; int realline = TextArea.GetLogicalLine(mousepos.Y); bool isRect = (Control.ModifierKeys & Keys.Alt) != 0; if (realline >= 0 && realline < TextArea.Document.TotalNumberOfLines) { // shift-select if ((Control.ModifierKeys & Keys.Shift) != 0) { if (!TextArea.SelectionManager.HasSomethingSelected && realline != TextArea.Caret.Position.Y) { if (realline >= TextArea.Caret.Position.Y) { // at or below starting selection, place the cursor on the next line // nothing is selected so make a new selection from cursor selectionStartPos = TextArea.Caret.Position; // whole line selection - start of line to start of next line if (realline < TextArea.Document.TotalNumberOfLines - 1) { TextArea.SelectionManager.SetSelection(selectionStartPos, new TextLocation(0, realline + 1), isRect); TextArea.Caret.Position = new TextLocation(0, realline + 1); } else { TextArea.SelectionManager.SetSelection(selectionStartPos, new TextLocation(TextArea.Document.GetLineSegment(realline).Length + 1, realline), isRect); TextArea.Caret.Position = new TextLocation(TextArea.Document.GetLineSegment(realline).Length + 1, realline); } } else { // prior lines to starting selection, place the cursor on the same line as the new selection // nothing is selected so make a new selection from cursor selectionStartPos = TextArea.Caret.Position; // whole line selection - start of line to start of next line TextArea.SelectionManager.SetSelection(selectionStartPos, new TextLocation(0, realline + 1), isRect); // textArea.SelectionManager.SetSelection(selectionStartPos, new TextLocation(selectionStartPos.X, selectionStartPos.Y), isRect); // textArea.SelectionManager.ExtendSelection(new TextLocation(selectionStartPos.X, selectionStartPos.Y), new TextLocation(0, realline), false); TextArea.Caret.Position = new TextLocation(0, realline); } } else { // let MouseMove handle a shift-click in a gutter MouseEventArgs e = new MouseEventArgs(mouseButtons, 1, mousepos.X, mousepos.Y, 0); TextArea.RaiseMouseMove(e); } } else // this is a new selection with no shift-key { // sync the textareamousehandler mouse location // (fixes problem with clicking out into a menu then back to the gutter whilst there is a selection) TextArea.MousePos = mousepos; selectionStartPos = new TextLocation(0, realline); //textArea.SelectionManager.ClearSelection(); // whole line selection - start of line to start of next line if (realline < TextArea.Document.TotalNumberOfLines - 1) { TextArea.SelectionManager.SetSelection(selectionStartPos, new TextLocation(selectionStartPos.X, selectionStartPos.Y + 1), isRect); TextArea.Caret.Position = new TextLocation(selectionStartPos.X, selectionStartPos.Y + 1); } else { TextArea.SelectionManager.SetSelection(new TextLocation(0, realline), new TextLocation(TextArea.Document.GetLineSegment(realline).Length + 1, selectionStartPos.Y), isRect); TextArea.Caret.Position = new TextLocation(TextArea.Document.GetLineSegment(realline).Length + 1, selectionStartPos.Y); } } } }