@ -93,83 +93,63 @@ namespace ICSharpCode.TextEditor
}
}
}
}
Point selectionStartPos ;
bool selectionComeFromGutter = false ;
bool selectionGutterDirectionDown = false ; // direction of gutter selection affects whether a selection starts at the start of a line or at the end of a line
public override void HandleMouseDown ( Point mousepos , MouseButtons mouseButtons )
public override void HandleMouseDown ( Point mousepos , MouseButtons mouseButtons )
{
{
selectionComeFromGutter = true ;
SelectFrom . where = WhereFrom . Gutter ;
int realline = textArea . TextView . GetLogicalLine ( mousepos ) ;
int realline = textArea . TextView . GetLogicalLine ( mousepos ) ;
if ( realline > = 0 & & realline < textArea . Document . TotalNumberOfLines ) {
if ( realline > = 0 & & realline < textArea . Document . TotalNumberOfLines ) {
if ( ( Control . ModifierKeys & Keys . Shift ) ! = 0 & & textArea . SelectionManager . HasSomethingSelected ) {
if ( ( Control . ModifierKeys & Keys . Shift ) ! = 0 ) {
// let MouseMove handle a shift-click in a gutter
if ( ! textArea . SelectionManager . HasSomethingSelected & & realline ! = textArea . Caret . Position . Y ) {
HandleMouseMove ( mousepos , mouseButtons ) ;
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
TextAreaMouseHandler . selectionStartPos = textArea . Caret . Position ;
textArea . SelectionManager . ClearSelection ( ) ;
// whole line selection - start of line to start of next line
if ( realline < textArea . Document . TotalNumberOfLines - 1 )
{
textArea . SelectionManager . SetSelection ( new DefaultSelection ( textArea . Document , TextAreaMouseHandler . selectionStartPos , new Point ( 0 , realline + 1 ) ) ) ;
textArea . Caret . Position = new Point ( 0 , realline + 1 ) ;
}
else
{
textArea . SelectionManager . SetSelection ( new DefaultSelection ( textArea . Document , TextAreaMouseHandler . selectionStartPos , new Point ( textArea . Document . GetLineSegment ( realline ) . Length + 1 , realline ) ) ) ;
textArea . Caret . Position = new Point ( 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
TextAreaMouseHandler . selectionStartPos = textArea . Caret . Position ;
textArea . SelectionManager . ClearSelection ( ) ;
// whole line selection - start of line to start of next line
textArea . SelectionManager . SetSelection ( new DefaultSelection ( textArea . Document , TextAreaMouseHandler . selectionStartPos , new Point ( TextAreaMouseHandler . selectionStartPos . X , TextAreaMouseHandler . selectionStartPos . Y ) ) ) ;
textArea . SelectionManager . ExtendSelection ( new Point ( TextAreaMouseHandler . selectionStartPos . X , TextAreaMouseHandler . selectionStartPos . Y ) , new Point ( 0 , realline ) ) ;
textArea . Caret . Position = new Point ( 0 , realline ) ;
}
}
else
{
// let MouseMove handle a shift-click in a gutter
MouseEventArgs e = new MouseEventArgs ( mouseButtons , 1 , mousepos . X , mousepos . Y , 0 ) ;
textArea . doMouseMove ( e ) ;
}
} else {
} else {
selectionGutterDirectionDown = false ; // reset the flag for handling in mousemove
TextAreaMouseHandler . selectionStartPos = new Point ( 0 , realline ) ;
selectionStartPos = new Point ( 0 , realline ) ;
textArea . SelectionManager . ClearSelection ( ) ;
textArea . SelectionManager . ClearSelection ( ) ;
textArea . SelectionManager . SetSelection ( new DefaultSelection ( textArea . Document , selectionStartPos , new Point ( textArea . Document . GetLineSegment ( realline ) . Length + 1 , realline ) ) ) ;
// whole line selection - start of line to start of next line
textArea . Caret . Position = selectionStartPos ;
if ( realline < textArea . Document . TotalNumberOfLines - 1 )
}
{
}
textArea . SelectionManager . SetSelection ( new DefaultSelection ( textArea . Document , TextAreaMouseHandler . selectionStartPos , new Point ( TextAreaMouseHandler . selectionStartPos . X , TextAreaMouseHandler . selectionStartPos . Y + 1 ) ) ) ;
}
textArea . Caret . Position = new Point ( TextAreaMouseHandler . selectionStartPos . X , TextAreaMouseHandler . selectionStartPos . Y + 1 ) ;
}
public override void HandleMouseLeave ( EventArgs e )
else
{
{
selectionComeFromGutter = false ;
textArea . SelectionManager . SetSelection ( new DefaultSelection ( textArea . Document , new Point ( 0 , realline ) , new Point ( textArea . Document . GetLineSegment ( realline ) . Length + 1 , TextAreaMouseHandler . selectionStartPos . Y ) ) ) ;
}
textArea . Caret . Position = new Point ( textArea . Document . GetLineSegment ( realline ) . Length + 1 , TextAreaMouseHandler . selectionStartPos . Y ) ;
}
public override void HandleMouseMove ( Point mousepos , MouseButtons mouseButtons )
}
{
if ( mouseButtons = = MouseButtons . Left ) {
if ( selectionComeFromGutter ) {
//TODO: Fix handling of mouse moving off to the left of the gutter before moving the selection down. Behaviour of selection changes after mouse moves left of gutter while selecting lines
int realline = textArea . TextView . GetLogicalLine ( mousepos ) ;
Point realmousepos = new Point ( 0 , realline ) ;
if ( realmousepos . Y < textArea . Document . TotalNumberOfLines ) {
if ( selectionStartPos . Y = = realmousepos . Y ) {
// this setselection defaults for a upward moving selection
textArea . SelectionManager . SetSelection ( new DefaultSelection ( textArea . Document , realmousepos , new Point ( 0 , realmousepos . Y + 1 ) ) ) ;
selectionGutterDirectionDown = false ;
} else if ( selectionStartPos . Y < realmousepos . Y & & textArea . SelectionManager . HasSomethingSelected ) {
// this fixes the selection for moving the selection down
if ( ! selectionGutterDirectionDown ) { //realmousepos.Y - selectionStartPos.Y == 1) {
selectionGutterDirectionDown = true ;
textArea . SelectionManager . SetSelection ( new DefaultSelection ( textArea . Document , selectionStartPos , new Point ( 0 , selectionStartPos . Y ) ) ) ;
// this enforces the screen area update
textArea . SelectionManager . ExtendSelection ( textArea . SelectionManager . SelectionCollection [ 0 ] . EndPosition , new Point ( 0 , realmousepos . Y + 1 ) ) ;
} else {
// selection is extended to the end of the current line
textArea . SelectionManager . ExtendSelection ( textArea . SelectionManager . SelectionCollection [ 0 ] . EndPosition , new Point ( 0 , realmousepos . Y + 1 ) ) ;
}
} else {
if ( textArea . SelectionManager . HasSomethingSelected ) {
// this fixes the selection for moving the selection up
if ( selectionGutterDirectionDown ) { // selectionStartPos.Y - realmousepos.Y == 1) { // only fix for first line movement
selectionGutterDirectionDown = false ;
textArea . SelectionManager . SetSelection ( new DefaultSelection ( textArea . Document , selectionStartPos , new Point ( 0 , realmousepos . Y + 1 ) ) ) ;
// move the extendselection to here to fix textarea update issues
textArea . SelectionManager . ExtendSelection ( selectionStartPos , realmousepos ) ;
} else {
textArea . SelectionManager . ExtendSelection ( textArea . Caret . Position , realmousepos ) ;
}
}
}
textArea . Caret . Position = realmousepos ;
}
} else {
if ( textArea . SelectionManager . HasSomethingSelected ) {
selectionStartPos = textArea . Document . OffsetToPosition ( textArea . SelectionManager . SelectionCollection [ 0 ] . Offset ) ;
int realline = textArea . TextView . GetLogicalLine ( mousepos ) ;
Point realmousepos = new Point ( 0 , realline ) ;
if ( realmousepos . Y < textArea . Document . TotalNumberOfLines ) {
textArea . SelectionManager . ExtendSelection ( textArea . Caret . Position , realmousepos ) ;
}
textArea . Caret . Position = realmousepos ;
}
}
}
}
}
}
}
}
}
}