Browse Source

Revert text editor selection patch from revision 2469, it was causing problems like http://community.sharpdevelop.net/forums/thread/16254.aspx

(but keeping change to TextArea.cs - mouse cursor is arrow when it passes over selected text)

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/2.1@2482 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
c9b9615253
  1. 142
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/Selection/SelectionManager.cs
  2. 51
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaMouseHandler.cs

142
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/Selection/SelectionManager.cs

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

51
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaMouseHandler.cs

@ -143,14 +143,15 @@ namespace ICSharpCode.TextEditor
void TextAreaMouseMove(object sender, MouseEventArgs e) void TextAreaMouseMove(object sender, MouseEventArgs e)
{ {
textArea.mousepos = e.Location; //textArea.mousepos; Point mousepos = textArea.mousepos;
// honour the starting selection strategy // honour the starting selection strategy
switch (textArea.SelectionManager.selectFrom.where) switch (textArea.SelectionManager.selectFrom.where)
{ {
case WhereFrom.Gutter: case WhereFrom.Gutter:
//moveGutter(sender, e);
ExtendSelectionToMouse(); ExtendSelectionToMouse();
return; break;
case WhereFrom.TArea: case WhereFrom.TArea:
break; break;
@ -166,8 +167,8 @@ namespace ICSharpCode.TextEditor
textArea.mousepos = new Point(e.X, e.Y); textArea.mousepos = new Point(e.X, e.Y);
if (clickedOnSelectedText) { if (clickedOnSelectedText) {
if (Math.Abs(mousedownpos.X - e.X) >= SystemInformation.DragSize.Width / 2 || if (Math.Abs(mousedownpos.X - mousepos.X) >= SystemInformation.DragSize.Width / 2 ||
Math.Abs(mousedownpos.Y - e.Y) >= SystemInformation.DragSize.Height / 2) Math.Abs(mousedownpos.Y - mousepos.Y) >= SystemInformation.DragSize.Height / 2)
{ {
clickedOnSelectedText = false; clickedOnSelectedText = false;
ISelection selection = textArea.SelectionManager.GetSelectionAt(textArea.Caret.Offset); ISelection selection = textArea.SelectionManager.GetSelectionAt(textArea.Caret.Offset);
@ -219,11 +220,30 @@ namespace ICSharpCode.TextEditor
textArea.Caret.Position = textArea.SelectionManager.NextValidPosition(realmousepos.Y); textArea.Caret.Position = textArea.SelectionManager.NextValidPosition(realmousepos.Y);
} }
} }
else { else
textArea.Caret.Position = realmousepos; textArea.Caret.Position = realmousepos;
}
textArea.SelectionManager.ExtendSelection(oldPos, textArea.Caret.Position); if (minSelection != nilPoint && textArea.SelectionManager.SelectionCollection.Count > 0) {
// Extend selection when selection was started with double-click
ISelection selection = textArea.SelectionManager.SelectionCollection[0];
Point min = textArea.SelectionManager.GreaterEqPos(minSelection, maxSelection) ? maxSelection : minSelection;
Point max = textArea.SelectionManager.GreaterEqPos(minSelection, maxSelection) ? minSelection : maxSelection;
if (textArea.SelectionManager.GreaterEqPos(max, realmousepos) && textArea.SelectionManager.GreaterEqPos(realmousepos, min)) {
textArea.SelectionManager.SetSelection(min, max);
} else if (textArea.SelectionManager.GreaterEqPos(max, realmousepos)) {
//textArea.SelectionManager.SetSelection(realmousepos, max);
int moff = textArea.Document.PositionToOffset(realmousepos);
min = textArea.Document.OffsetToPosition(FindWordStart(textArea.Document, moff));
textArea.SelectionManager.SetSelection(min, max);
} else {
//textArea.SelectionManager.SetSelection(min, realmousepos);
int moff = textArea.Document.PositionToOffset(realmousepos);
max = textArea.Document.OffsetToPosition(FindWordEnd(textArea.Document, moff));
textArea.SelectionManager.SetSelection(min, max);
}
} else {
textArea.SelectionManager.ExtendSelection(oldPos, textArea.Caret.Position);
}
textArea.SetDesiredColumn(); textArea.SetDesiredColumn();
} }
@ -258,9 +278,7 @@ namespace ICSharpCode.TextEditor
break; break;
} }
textArea.Caret.Position = maxSelection;
textArea.SelectionManager.ExtendSelection(minSelection, maxSelection); textArea.SelectionManager.ExtendSelection(minSelection, maxSelection);
} }
// HACK WARNING !!! // HACK WARNING !!!
// must refresh here, because when a error tooltip is showed and the underlined // must refresh here, because when a error tooltip is showed and the underlined
@ -271,12 +289,12 @@ namespace ICSharpCode.TextEditor
} }
} }
DateTime lastTime = DateTime.Now; DateTime lastTime = DateTime.Now;
void OnMouseDown(object sender, MouseEventArgs e) void OnMouseDown(object sender, MouseEventArgs e)
{ {
Point mousepos; Point mousepos;
textArea.mousepos = e.Location; mousepos = textArea.mousepos;
mousepos = e.Location;
if (dodragdrop) if (dodragdrop)
{ {
@ -293,7 +311,6 @@ namespace ICSharpCode.TextEditor
textArea.SelectionManager.selectFrom.where = WhereFrom.TArea; textArea.SelectionManager.selectFrom.where = WhereFrom.TArea;
button = e.Button; button = e.Button;
// double-click
if (button == MouseButtons.Left && (DateTime.Now - lastTime).Milliseconds < SystemInformation.DoubleClickTime) { if (button == MouseButtons.Left && (DateTime.Now - lastTime).Milliseconds < SystemInformation.DoubleClickTime) {
int deltaX = Math.Abs(lastmousedownpos.X - e.X); int deltaX = Math.Abs(lastmousedownpos.X - e.X);
int deltaY = Math.Abs(lastmousedownpos.Y - e.Y); int deltaY = Math.Abs(lastmousedownpos.Y - e.Y);
@ -302,15 +319,6 @@ namespace ICSharpCode.TextEditor
DoubleClickSelectionExtend(); DoubleClickSelectionExtend();
lastTime = DateTime.Now; lastTime = DateTime.Now;
lastmousedownpos = new Point(e.X, e.Y); lastmousedownpos = new Point(e.X, e.Y);
if(minSelection != nilPoint && maxSelection != nilPoint) {
textArea.SelectionManager.SelectionCollection[0].StartPosition = minSelection;
textArea.SelectionManager.SelectionCollection[0].EndPosition = maxSelection;
textArea.SelectionManager.selectionStart = minSelection;
minSelection = nilPoint;
maxSelection = nilPoint;
}
return; return;
} }
} }
@ -446,7 +454,6 @@ namespace ICSharpCode.TextEditor
return; return;
} }
textArea.SelectionManager.selectFrom.where = WhereFrom.TArea;
doubleclick = true; doubleclick = true;
} }

Loading…
Cancel
Save