Browse Source

patch from Troy Simpson improving gutter selection

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1859 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Markus Palme 20 years ago
parent
commit
165f9fe9e5
  1. 82
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/Selection/SelectionManager.cs
  2. 36
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/GutterMargin.cs
  3. 12
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs
  4. 191
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaMouseHandler.cs

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

@ -18,7 +18,11 @@ namespace ICSharpCode.TextEditor.Document
/// </summary> /// </summary>
public class SelectionManager : IDisposable public class SelectionManager : IDisposable
{ {
public Point selectionStart;
IDocument document; IDocument document;
TextArea textArea;
public SelectFrom selectFrom = new SelectFrom();
List<ISelection> selectionCollection = new List<ISelection>(); List<ISelection> selectionCollection = new List<ISelection>();
/// <value> /// <value>
@ -71,6 +75,16 @@ namespace ICSharpCode.TextEditor.Document
document.DocumentChanged += new DocumentEventHandler(DocumentChanged); document.DocumentChanged += new DocumentEventHandler(DocumentChanged);
} }
/// <summary>
/// Creates a new instance of <see cref="SelectionManager"/>
/// </summary>
public SelectionManager(IDocument document, TextArea textArea)
{
this.document = document;
this.textArea = textArea;
document.DocumentChanged += new DocumentEventHandler(DocumentChanged);
}
public void Dispose() public void Dispose()
{ {
if (this.document != null) { if (this.document != null) {
@ -154,7 +168,14 @@ namespace ICSharpCode.TextEditor.Document
} }
} else { } else {
if (selection.StartPosition != newPosition) { 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; selection.StartPosition = newPosition;
}
changed = true; changed = true;
} }
} }
@ -179,8 +200,30 @@ namespace ICSharpCode.TextEditor.Document
selection.StartPosition != newPosition) { selection.StartPosition != newPosition) {
changed = true; 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.EndPosition = selection.StartPosition;
selection.StartPosition = newPosition; selection.StartPosition = newPosition;
}
changed = true; changed = true;
} else { } else {
if (selection.EndPosition != newPosition) { if (selection.EndPosition != newPosition) {
@ -210,6 +253,19 @@ namespace ICSharpCode.TextEditor.Document
OnSelectionChanged(EventArgs.Empty); OnSelectionChanged(EventArgs.Empty);
} }
} }
// retrieve the next available line
// - checks that there are more lines available after the current one
// - if there are then the next line is returned
// - if there are NOT then the last position on the given line is returned
public Point NextValidPosition(int line)
{
if (line < document.TotalNumberOfLines - 1)
return new Point(0, line + 1);
else
return new Point(document.GetLineSegment(document.TotalNumberOfLines - 1).Length + 1, line);
}
void ClearWithoutUpdate() void ClearWithoutUpdate()
{ {
while (selectionCollection.Count > 0) { while (selectionCollection.Count > 0) {
@ -224,6 +280,15 @@ namespace ICSharpCode.TextEditor.Document
/// </remarks> /// </remarks>
public void ClearSelection() public void ClearSelection()
{ {
Point mousepos;
mousepos = textArea.mousepos;
// this is the most logical place to reset selection starting
// 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)
selectionStart.X = 0;
ClearWithoutUpdate(); ClearWithoutUpdate();
document.CommitUpdate(); document.CommitUpdate();
} }
@ -384,4 +449,21 @@ namespace ICSharpCode.TextEditor.Document
public event EventHandler SelectionChanged; public event EventHandler SelectionChanged;
} }
// selection initiated from...
public class SelectFrom {
public int where = WhereFrom.None; // last selection initiator
public int first = WhereFrom.None; // first selection initiator
public SelectFrom()
{
}
}
// selection initiated from type...
public class WhereFrom {
public const int None = 0;
public const int Gutter = 1;
public const int TArea = 2;
}
} }

36
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/GutterMargin.cs

@ -95,36 +95,37 @@ namespace ICSharpCode.TextEditor
public override void HandleMouseDown(Point mousepos, MouseButtons mouseButtons) public override void HandleMouseDown(Point mousepos, MouseButtons mouseButtons)
{ {
SelectFrom.where = WhereFrom.Gutter; Point selectionStartPos;
textArea.SelectionManager.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) {
// shift-select
if((Control.ModifierKeys & Keys.Shift) != 0) { if((Control.ModifierKeys & Keys.Shift) != 0) {
if(!textArea.SelectionManager.HasSomethingSelected && realline != textArea.Caret.Position.Y) { if(!textArea.SelectionManager.HasSomethingSelected && realline != textArea.Caret.Position.Y) {
if (realline >= textArea.Caret.Position.Y) if (realline >= textArea.Caret.Position.Y)
{ // at or below starting selection, place the cursor on the next line { // at or below starting selection, place the cursor on the next line
// nothing is selected so make a new selection from cursor // nothing is selected so make a new selection from cursor
TextAreaMouseHandler.selectionStartPos = textArea.Caret.Position; selectionStartPos = textArea.Caret.Position;
textArea.SelectionManager.ClearSelection();
// whole line selection - start of line to start of next line // whole line selection - start of line to start of next line
if (realline < textArea.Document.TotalNumberOfLines - 1) if (realline < textArea.Document.TotalNumberOfLines - 1)
{ {
textArea.SelectionManager.SetSelection(new DefaultSelection(textArea.Document, TextAreaMouseHandler.selectionStartPos, new Point(0, realline + 1))); textArea.SelectionManager.SetSelection(new DefaultSelection(textArea.Document, selectionStartPos, new Point(0, realline + 1)));
textArea.Caret.Position = new Point(0, realline + 1); textArea.Caret.Position = new Point(0, realline + 1);
} }
else else
{ {
textArea.SelectionManager.SetSelection(new DefaultSelection(textArea.Document, TextAreaMouseHandler.selectionStartPos, new Point(textArea.Document.GetLineSegment(realline).Length + 1, realline))); textArea.SelectionManager.SetSelection(new DefaultSelection(textArea.Document, selectionStartPos, new Point(textArea.Document.GetLineSegment(realline).Length + 1, realline)));
textArea.Caret.Position = new Point(textArea.Document.GetLineSegment(realline).Length + 1, realline); textArea.Caret.Position = new Point(textArea.Document.GetLineSegment(realline).Length + 1, realline);
} }
} }
else else
{ // prior lines to starting selection, place the cursor on the same line as the new selection { // 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 // nothing is selected so make a new selection from cursor
TextAreaMouseHandler.selectionStartPos = textArea.Caret.Position; selectionStartPos = textArea.Caret.Position;
textArea.SelectionManager.ClearSelection();
// whole line selection - start of line to start of next line // 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.SetSelection(new DefaultSelection(textArea.Document, selectionStartPos, new Point(selectionStartPos.X, selectionStartPos.Y)));
textArea.SelectionManager.ExtendSelection(new Point(TextAreaMouseHandler.selectionStartPos.X, TextAreaMouseHandler.selectionStartPos.Y), new Point(0, realline)); textArea.SelectionManager.ExtendSelection(new Point(selectionStartPos.X, selectionStartPos.Y), new Point(0, realline));
textArea.Caret.Position = new Point(0, realline); textArea.Caret.Position = new Point(0, realline);
} }
} }
@ -134,19 +135,24 @@ namespace ICSharpCode.TextEditor
MouseEventArgs e = new MouseEventArgs(mouseButtons, 1, mousepos.X, mousepos.Y, 0); MouseEventArgs e = new MouseEventArgs(mouseButtons, 1, mousepos.X, mousepos.Y, 0);
textArea.doMouseMove(e); textArea.doMouseMove(e);
} }
} else { } else { // this is a new selection with no shift-key
TextAreaMouseHandler.selectionStartPos = new Point(0, realline); // 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 Point(0, realline);
textArea.SelectionManager.ClearSelection(); textArea.SelectionManager.ClearSelection();
// whole line selection - start of line to start of next line // whole line selection - start of line to start of next line
if (realline < textArea.Document.TotalNumberOfLines - 1) 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.SelectionManager.SetSelection(new DefaultSelection(textArea.Document, selectionStartPos, new Point(selectionStartPos.X, selectionStartPos.Y + 1)));
textArea.Caret.Position = new Point(TextAreaMouseHandler.selectionStartPos.X, TextAreaMouseHandler.selectionStartPos.Y + 1); textArea.Caret.Position = new Point(selectionStartPos.X, selectionStartPos.Y + 1);
} }
else else
{ {
textArea.SelectionManager.SetSelection(new DefaultSelection(textArea.Document, new Point(0, realline), new Point(textArea.Document.GetLineSegment(realline).Length + 1, TextAreaMouseHandler.selectionStartPos.Y))); textArea.SelectionManager.SetSelection(new DefaultSelection(textArea.Document, new Point(0, realline), new Point(textArea.Document.GetLineSegment(realline).Length + 1, selectionStartPos.Y)));
textArea.Caret.Position = new Point(textArea.Document.GetLineSegment(realline).Length + 1, TextAreaMouseHandler.selectionStartPos.Y); textArea.Caret.Position = new Point(textArea.Document.GetLineSegment(realline).Length + 1, selectionStartPos.Y);
} }
} }
} }

12
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextArea.cs

@ -56,6 +56,9 @@ namespace ICSharpCode.TextEditor
SelectionManager selectionManager; SelectionManager selectionManager;
Caret caret; Caret caret;
public Point mousepos = new Point(0, 0);
//public Point selectionStartPos = new Point(0,0);
bool disposed; bool disposed;
[Browsable(false)] [Browsable(false)]
@ -179,7 +182,7 @@ namespace ICSharpCode.TextEditor
this.motherTextEditorControl = motherTextEditorControl; this.motherTextEditorControl = motherTextEditorControl;
caret = new Caret(this); caret = new Caret(this);
selectionManager = new SelectionManager(Document); selectionManager = new SelectionManager(Document, this);
this.textAreaClipboardHandler = new TextAreaClipboardHandler(this); this.textAreaClipboardHandler = new TextAreaClipboardHandler(this);
@ -298,8 +301,13 @@ namespace ICSharpCode.TextEditor
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e) protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
{ {
base.OnMouseDown(e); // this corrects weird problems when text is selected,
// then a menu item is selected, then the text is
// clicked again - it correctly synchronises the
// click position
mousepos = new Point(e.X, e.Y);
base.OnMouseDown(e);
CloseToolTip(); CloseToolTip();
foreach (AbstractMargin margin in leftMargins) { foreach (AbstractMargin margin in leftMargins) {

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

@ -23,7 +23,6 @@ namespace ICSharpCode.TextEditor
{ {
TextArea textArea; TextArea textArea;
bool doubleclick = false; bool doubleclick = false;
Point mousepos = new Point(0, 0);
int selbegin; int selbegin;
int selend; int selend;
bool clickedOnSelectedText = false; bool clickedOnSelectedText = false;
@ -33,14 +32,13 @@ namespace ICSharpCode.TextEditor
static readonly Point nilPoint = new Point(-1, -1); static readonly Point nilPoint = new Point(-1, -1);
Point mousedownpos = nilPoint; Point mousedownpos = nilPoint;
Point lastmousedownpos = nilPoint; Point lastmousedownpos = nilPoint;
public static Point selectionStartPos = nilPoint;
bool gotmousedown = false; bool gotmousedown = false;
bool dodragdrop = false; bool dodragdrop = false;
public TextAreaMouseHandler(TextArea textArea) public TextAreaMouseHandler(TextArea ttextArea)
{ {
this.textArea = textArea; textArea = ttextArea;
} }
public void Attach() public void Attach()
@ -115,17 +113,23 @@ namespace ICSharpCode.TextEditor
void OnMouseUp(object sender, MouseEventArgs e) void OnMouseUp(object sender, MouseEventArgs e)
{ {
textArea.SelectionManager.selectFrom.where = WhereFrom.None;
gotmousedown = false; gotmousedown = false;
mousedownpos = nilPoint; mousedownpos = nilPoint;
} }
void TextAreaClick(object sender, EventArgs e) void TextAreaClick(object sender, EventArgs e)
{ {
if (dodragdrop) { Point mousepos;
mousepos = textArea.mousepos;
if (dodragdrop)
{
return; return;
} }
if (clickedOnSelectedText && textArea.TextView.DrawingPosition.Contains(mousepos.X, mousepos.Y)) { if (clickedOnSelectedText && textArea.TextView.DrawingPosition.Contains(mousepos.X, mousepos.Y))
{
textArea.SelectionManager.ClearSelection(); textArea.SelectionManager.ClearSelection();
Point clickPosition = textArea.TextView.GetLogicalPosition(mousepos.X - textArea.TextView.DrawingPosition.X, Point clickPosition = textArea.TextView.GetLogicalPosition(mousepos.X - textArea.TextView.DrawingPosition.X,
@ -138,10 +142,15 @@ namespace ICSharpCode.TextEditor
void TextAreaMouseMove(object sender, MouseEventArgs e) void TextAreaMouseMove(object sender, MouseEventArgs e)
{ {
Point mousepos;
mousepos = textArea.mousepos;
// honour the starting selection strategy // honour the starting selection strategy
switch(SelectFrom.where) { switch (textArea.SelectionManager.selectFrom.where)
{
case WhereFrom.Gutter: case WhereFrom.Gutter:
moveGutter(sender, e); //moveGutter(sender, e);
ExtendSelectionToMouse();
break; break;
case WhereFrom.TArea: case WhereFrom.TArea:
@ -155,11 +164,12 @@ namespace ICSharpCode.TextEditor
} }
doubleclick = false; doubleclick = false;
mousepos = new Point(e.X, e.Y); textArea.mousepos = new Point(e.X, e.Y);
if (clickedOnSelectedText) { if (clickedOnSelectedText) {
if (Math.Abs(mousedownpos.X - mousepos.X) >= SystemInformation.DragSize.Width / 2 || if (Math.Abs(mousedownpos.X - mousepos.X) >= SystemInformation.DragSize.Width / 2 ||
Math.Abs(mousedownpos.Y - mousepos.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);
if (selection != null) { if (selection != null) {
@ -178,7 +188,8 @@ namespace ICSharpCode.TextEditor
} }
if (e.Button == MouseButtons.Left) { if (e.Button == MouseButtons.Left) {
if (gotmousedown) { if (gotmousedown && textArea.SelectionManager.selectFrom.where == WhereFrom.TArea)
{
ExtendSelectionToMouse(); ExtendSelectionToMouse();
} }
} }
@ -186,15 +197,32 @@ namespace ICSharpCode.TextEditor
void ExtendSelectionToMouse() void ExtendSelectionToMouse()
{ {
Point mousepos;
mousepos = textArea.mousepos;
Point realmousepos = textArea.TextView.GetLogicalPosition(Math.Max(0, mousepos.X - textArea.TextView.DrawingPosition.X), Point realmousepos = textArea.TextView.GetLogicalPosition(Math.Max(0, mousepos.X - textArea.TextView.DrawingPosition.X),
mousepos.Y - textArea.TextView.DrawingPosition.Y); mousepos.Y - textArea.TextView.DrawingPosition.Y);
int y = realmousepos.Y; int y = realmousepos.Y;
realmousepos = textArea.Caret.ValidatePosition(realmousepos); realmousepos = textArea.Caret.ValidatePosition(realmousepos);
Point oldPos = textArea.Caret.Position; Point oldPos = textArea.Caret.Position;
if (oldPos == realmousepos) { if (oldPos == realmousepos && textArea.SelectionManager.selectFrom.where != WhereFrom.Gutter)
{
return; return;
} }
if (textArea.SelectionManager.selectFrom.where == WhereFrom.Gutter)
if(realmousepos.Y < textArea.SelectionManager.selectionStart.Y) {
// the selection is from the gutter and it has moved above the startpoint
textArea.Caret.Position = new Point(0, realmousepos.Y);
} else {
if(realmousepos.Y == textArea.SelectionManager.selectionStart.Y) {
textArea.Caret.Position = textArea.SelectionManager.NextValidPosition(realmousepos.Y);
} else {
textArea.Caret.Position = textArea.SelectionManager.NextValidPosition(realmousepos.Y);
}
}
else
textArea.Caret.Position = realmousepos; textArea.Caret.Position = realmousepos;
if (minSelection != nilPoint && textArea.SelectionManager.SelectionCollection.Count > 0) { if (minSelection != nilPoint && textArea.SelectionManager.SelectionCollection.Count > 0) {
// Extend selection when selection was started with double-click // Extend selection when selection was started with double-click
ISelection selection = textArea.SelectionManager.SelectionCollection[0]; ISelection selection = textArea.SelectionManager.SelectionCollection[0];
@ -221,8 +249,12 @@ namespace ICSharpCode.TextEditor
void DoubleClickSelectionExtend() void DoubleClickSelectionExtend()
{ {
Point mousepos;
mousepos = textArea.mousepos;
textArea.SelectionManager.ClearSelection(); textArea.SelectionManager.ClearSelection();
if (textArea.TextView.DrawingPosition.Contains(mousepos.X, mousepos.Y)) { if (textArea.TextView.DrawingPosition.Contains(mousepos.X, mousepos.Y))
{
FoldMarker marker = textArea.TextView.GetFoldMarkerFromPosition(mousepos.X - textArea.TextView.DrawingPosition.X, FoldMarker marker = textArea.TextView.GetFoldMarkerFromPosition(mousepos.X - textArea.TextView.DrawingPosition.X,
mousepos.Y - textArea.TextView.DrawingPosition.Y); mousepos.Y - textArea.TextView.DrawingPosition.Y);
if (marker != null && marker.IsFolded) { if (marker != null && marker.IsFolded) {
@ -261,7 +293,11 @@ namespace ICSharpCode.TextEditor
DateTime lastTime = DateTime.Now; DateTime lastTime = DateTime.Now;
void OnMouseDown(object sender, MouseEventArgs e) void OnMouseDown(object sender, MouseEventArgs e)
{ {
if (dodragdrop) { Point mousepos;
mousepos = textArea.mousepos;
if (dodragdrop)
{
return; return;
} }
@ -272,7 +308,7 @@ namespace ICSharpCode.TextEditor
if (textArea.TextView.DrawingPosition.Contains(mousepos.X, mousepos.Y)) { if (textArea.TextView.DrawingPosition.Contains(mousepos.X, mousepos.Y)) {
gotmousedown = true; gotmousedown = true;
SelectFrom.where = WhereFrom.TArea; textArea.SelectionManager.selectFrom.where = WhereFrom.TArea;
button = e.Button; button = e.Button;
if (button == MouseButtons.Left && (DateTime.Now - lastTime).Milliseconds < SystemInformation.DoubleClickTime) { if (button == MouseButtons.Left && (DateTime.Now - lastTime).Milliseconds < SystemInformation.DoubleClickTime) {
@ -412,8 +448,6 @@ namespace ICSharpCode.TextEditor
Point minSelection = nilPoint; Point minSelection = nilPoint;
Point maxSelection = nilPoint; Point maxSelection = nilPoint;
void OnDoubleClick(object sender, System.EventArgs e) void OnDoubleClick(object sender, System.EventArgs e)
{ {
if (dodragdrop) { if (dodragdrop) {
@ -423,128 +457,5 @@ namespace ICSharpCode.TextEditor
doubleclick = true; doubleclick = true;
} }
bool selectionGutterDirectionDown = true; // direction of gutter selection affects whether a selection starts at the start of a line or at the end of a line
int gutterlastmoveline = -1; // last gutter movement line
public int gutterxstart = 0; // if initial selection is made from the gutter then set to zero, otherwise take the original starting position (from a mouse or keyboard select)
void moveGutter(object sender, MouseEventArgs e)
{
MouseButtons mouseButtons = e.Button;
if (mouseButtons == MouseButtons.Left)
{
bool directionChanged = false; // gone from a downward moving selection to an upward, or vice-versa
int realline = textArea.TextView.GetLogicalLine(mousepos);
Point realmousepos = new Point(0, realline);
// avoid reprocessing the same selected line (prevent flicker)
if (gutterlastmoveline == realmousepos.Y)
return;
else
{
if (realmousepos.Y < selectionStartPos.Y)
{
// we need to record when the behaviour changes
// used down further
if (selectionGutterDirectionDown)
directionChanged = true;
// determine the selection strategy
selectionGutterDirectionDown = false;
}
else
{
// we need to record when the behaviour changes
// used down further
if (!selectionGutterDirectionDown)
directionChanged = true;
// determine the selection strategy
selectionGutterDirectionDown = true;
}
gutterlastmoveline = realmousepos.Y;
}
// between 1st and last lines - last line is handled differently
if (realmousepos.Y < textArea.Document.TotalNumberOfLines - 1)
{
if (selectionStartPos.Y == realmousepos.Y)
{
// this setselection defaults for a upward moving selection
textArea.SelectionManager.SetSelection(new DefaultSelection(textArea.Document, realmousepos, new Point(selectionStartPos.X, realmousepos.Y + 1)));
}
else if (selectionStartPos.Y < realmousepos.Y && textArea.SelectionManager.HasSomethingSelected)
{
// this fixes the selection for moving the selection down
if (directionChanged)
{
textArea.SelectionManager.SetSelection(new DefaultSelection(textArea.Document, selectionStartPos, new Point(selectionStartPos.X, 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
{
// when something is already selected we must repect the existing selection
if (textArea.SelectionManager.HasSomethingSelected)
{
// this fixes the selection for moving the selection up
if (realmousepos.Y < selectionStartPos.Y && directionChanged) // the first time an upward selection moves above the first selection line
{
textArea.SelectionManager.ClearSelection();
selectionStartPos = new Point(selectionStartPos.X, TextAreaMouseHandler.selectionStartPos.Y);
if ((Control.ModifierKeys & Keys.Shift) != 0 && selectionStartPos.X != 0)
{
// shift-click
textArea.SelectionManager.SetSelection(new DefaultSelection(textArea.Document, selectionStartPos, new Point(selectionStartPos.X, selectionStartPos.Y)));
}
else
{
textArea.SelectionManager.SetSelection(new DefaultSelection(textArea.Document, selectionStartPos, new Point(selectionStartPos.X, selectionStartPos.Y + 1)));
}
textArea.SelectionManager.ExtendSelection(new Point(selectionStartPos.X, selectionStartPos.Y), new Point(realmousepos.X, realmousepos.Y));
}
else
{
textArea.SelectionManager.ExtendSelection(textArea.Caret.Position, realmousepos);
}
}
}
if (realmousepos.Y >= selectionStartPos.Y) // at or below starting selection, place the cursor on the next line
textArea.Caret.Position = new Point(0, realmousepos.Y + 1);
else // prior lines to starting selection, place the cursor on the same line as the new selection
textArea.Caret.Position = new Point(0, realmousepos.Y);
}
else
{
if (realmousepos.Y == textArea.Document.TotalNumberOfLines - 1)
{
// selection is last line of text
textArea.SelectionManager.ClearSelection();
textArea.SelectionManager.SetSelection(new DefaultSelection(textArea.Document, new Point(selectionStartPos.X, selectionStartPos.Y), new Point(textArea.Document.GetLineSegment(realline).Length + 1, realline)));
textArea.Caret.Position = new Point(textArea.Document.GetLineSegment(realline).Length + 1, realline);
}
}
}
else
gutterlastmoveline = -1;
}
}
public class SelectFrom {
public static int where = WhereFrom.None;
}
public class WhereFrom {
public const int None = 0;
public const int Gutter = 1;
public const int TArea = 2;
} }
} }

Loading…
Cancel
Save