@ -154,17 +154,11 @@ namespace ICSharpCode.TextEditor.Document
@@ -154,17 +154,11 @@ namespace ICSharpCode.TextEditor.Document
public void ExtendSelection ( Point oldPosition , Point newPosition )
{
// where oldposition is where the cursor was,
// and newposition is where it has ended up from a click (both zero based)
if ( oldPosition = = newPosition )
{
if ( oldPosition = = newPosition ) {
return ;
}
Point min ;
Point max ;
int oldnewX = newPosition . X ;
bool oldIsGreater = GreaterEqPos ( oldPosition , newPosition ) ;
if ( oldIsGreater ) {
min = newPosition ;
@ -173,59 +167,104 @@ namespace ICSharpCode.TextEditor.Document
@@ -173,59 +167,104 @@ namespace ICSharpCode.TextEditor.Document
min = oldPosition ;
max = newPosition ;
}
if ( min = = max ) {
return ;
}
if ( ! HasSomethingSelected ) {
SetSelection ( new DefaultSelection ( document , min , max ) ) ;
return ;
}
ISelection selection = this . selectionCollection [ 0 ] ;
if ( min = = max ) {
//selection.StartPosition = newPosition;
return ;
} else {
// changed selection via gutter
if ( selectFrom . where = = WhereFrom . Gutter ) {
// selection new position is always at the left edge for gutter selections
newPosition . X = 0 ;
bool changed = false ;
if ( selection . ContainsPosition ( newPosition ) ) {
if ( oldIsGreater ) {
if ( selection . EndPosition ! = newPosition ) {
selection . EndPosition = newPosition ;
changed = true ;
}
} else {
if ( selection . StartPosition ! = newPosition ) {
// we're back to the line we started from and it was a gutter selection
if ( selectFrom . where = = WhereFrom . Gutter & & newPosition . Y > = selectionStart . Y )
{
selection . StartPosition = selectionStart ;
selection . EndPosition = NextValidPosition ( selection . StartPosition . Y ) ;
} else {
selection . StartPosition = newPosition ;
}
changed = true ;
}
}
if ( newPosition . Y > = selectionStart . Y ) {
// selecting down
if ( GreaterEqPos ( newPosition , selectionStart ) ) {
selection . StartPosition = selectionStart ;
// this handles last line selection
//if( textArea.Document.TotalNumberOfLines - 1 == newPosition.Y)
if ( selectFrom . where = = WhereFrom . Gutter ) //&& newPosition.Y != oldPosition.Y)
//selection.EndPosition = NextValidPosition(newPosition.Y - 1);
selection . EndPosition = new Point ( textArea . Caret . Column , textArea . Caret . Line ) ;
els e {
newPosition . X = oldnewX ;
selection . EndPosition = newPosition ;
} else {
if ( oldPosition = = selection . StartPosition ) {
if ( GreaterEqPos ( newPosition , selection . EndPosition ) ) {
if ( selection . StartPosition ! = selection . EndPosition | |
selection . EndPosition ! = newPosition ) {
selection . StartPosition = selection . EndPosition ;
selection . EndPosition = newPosition ;
changed = true ;
}
} else {
if ( s election . StartPosition ! = n ewPosition ) {
selection . StartPosition = newPosition ;
changed = true ;
}
} else { // generally this occurs if the selection is on the same line, at a point less than the start position
selection . StartPosition = newPosition ;
selection . EndPosition = selectionStart ;
}
} else { // selecting up
if ( selectFrom . where = = WhereFrom . Gutter & & selectFrom . first = = WhereFrom . Gutter ) {
// gutter selection
selection . EndPosition = NextValidPosition ( selectionStart . Y ) ;
} else { // internal text selection
selection . EndPosition = selectionStart ; //selection.StartPosition;
} else {
if ( GreaterEqPos ( selection . StartPosition , newPosition ) ) {
if ( selection . EndPosition ! = selection . StartPosition | |
selection . StartPosition ! = newPosition ) {
changed = true ;
}
if ( selectFrom . where = = WhereFrom . Gutter )
{
if ( selectFrom . first = = WhereFrom . Gutter )
{
if ( newPosition . Y = = selectionStart . Y ) {
selection . EndPosition = NextValidPosition ( selection . StartPosition . Y ) ;
selection . StartPosition = new Point ( 0 , newPosition . Y ) ;
} else {
selection . EndPosition = NextValidPosition ( selection . StartPosition . Y ) ;
selection . StartPosition = newPosition ;
}
} else {
if ( newPosition . Y = = selectionStart . Y ) {
selection . EndPosition = NextValidPosition ( selection . StartPosition . Y ) ;
selection . StartPosition = new Point ( selectionStart . X , newPosition . Y ) ;
} else {
selection . EndPosition = new Point ( selectionStart . X , selection . StartPosition . Y ) ;
selection . StartPosition = newPosition ;
}
}
} else {
selection . EndPosition = selection . StartPosition ;
selection . StartPosition = newPosition ;
}
changed = true ;
} else {
if ( selection . EndPosition ! = newPosition ) {
selection . EndPosition = newPosition ;
changed = true ;
}
}
selection . StartPosition = newPosition ;
}
}
document . RequestUpdate ( new TextAreaUpdate ( TextAreaUpdateType . LinesBetween , min . Y , max . Y ) ) ;
document . CommitUpdate ( ) ;
OnSelectionChanged ( EventArgs . Empty ) ;
// if (GreaterEqPos(selection.StartPosition, min) && GreaterEqPos(selection.EndPosition, max)) {
// if (oldIsGreater) {
// selection.StartPosition = min;
// } else {
// selection.StartPosition = max;
// }
// } else {
// if (oldIsGreater) {
// selection.EndPosition = min;
// } else {
// selection.EndPosition = max;
// }
// }
if ( changed ) {
document . RequestUpdate ( new TextAreaUpdate ( TextAreaUpdateType . LinesBetween , min . Y , max . Y ) ) ;
document . CommitUpdate ( ) ;
OnSelectionChanged ( EventArgs . Empty ) ;
}
}
// retrieve the next available line
@ -260,9 +299,8 @@ namespace ICSharpCode.TextEditor.Document
@@ -260,9 +299,8 @@ namespace ICSharpCode.TextEditor.Document
// positions because it is always called before a new selection
selectFrom . first = selectFrom . where ;
selectionStart = textArea . TextView . GetLogicalPosition ( mousepos . X - textArea . TextView . DrawingPosition . X , mousepos . Y - textArea . TextView . DrawingPosition . Y ) ;
if ( selectFrom . where = = WhereFrom . Gutter ) {
if ( selectFrom . where = = WhereFrom . Gutter )
selectionStart . X = 0 ;
}
ClearWithoutUpdate ( ) ;
document . CommitUpdate ( ) ;
@ -326,7 +364,7 @@ namespace ICSharpCode.TextEditor.Document
@@ -326,7 +364,7 @@ namespace ICSharpCode.TextEditor.Document
{
return GetSelectionAt ( offset ) ! = null ;
}
/// <remarks>
/// Returns a <see cref="ISelection"/> object giving the selection in which
/// the offset points to.