protected internal override void MousePressed (MarginMouseEventArgs args)
{
base.MousePressed (args);
if (args.TriggersContextMenu ())
return;
InSelectionDrag = false;
inDrag = false;
Selection selection = textEditor.MainSelection;
int oldOffset = textEditor.Caret.Offset;
string link = GetLink != null ? GetLink (args) : null;
if (!String.IsNullOrEmpty (link)) {
textEditor.ClearSelection ();
textEditor.FireLinkEvent (link, args.Button, args.ModifierState);
return;
}
if (args.Button == 1) {
if (!CalculateClickLocation (args.X, args.Y, out clickLocation))
return;
DocumentLine line = Document.GetLine (clickLocation.Line);
bool isHandled = false;
if (line != null) {
foreach (TextLineMarker marker in line.Markers) {
if (marker is IActionTextLineMarker) {
isHandled |= ((IActionTextLineMarker)marker).MousePressed (textEditor, args);
if (isHandled)
break;
}
}
var locNotSnapped = PointToLocation (args.X, args.Y, snapCharacters: false);
foreach (var marker in Document.GetTextSegmentMarkersAt (Document.GetOffset (locNotSnapped)).Where (m => m.IsVisible)) {
if (marker is IActionTextLineMarker) {
isHandled |= ((IActionTextLineMarker)marker).MousePressed (textEditor, args);
if (isHandled)
break;
}
}
}
if (isHandled)
return;
int offset = Document.LocationToOffset (clickLocation);
if (offset < 0) {
textEditor.RunAction (CaretMoveActions.ToDocumentEnd);
return;
}
if (args.Button == 2 && !selection.IsEmpty && selection.Contains (Document.OffsetToLocation (offset))) {
textEditor.ClearSelection ();
return;
}
if (args.Type == EventType.TwoButtonPress) {
var data = textEditor.GetTextEditorData ();
mouseWordStart = data.FindCurrentWordStart (offset);
mouseWordEnd = data.FindCurrentWordEnd (offset);
Caret.Offset = mouseWordEnd;
textEditor.MainSelection = new Selection (textEditor.Document.OffsetToLocation (mouseWordStart), textEditor.Document.OffsetToLocation (mouseWordEnd));
InSelectionDrag = true;
mouseSelectionMode = MouseSelectionMode.Word;
// folding marker
int lineNr = args.LineNumber;
foreach (var shownFolding in GetFoldRectangles (lineNr)) {
if (shownFolding.Item1.Contains ((int)(args.X + this.XOffset), (int)args.Y)) {
shownFolding.Item2.IsFolded = false;
return;
}
}
return;
} else if (args.Type == EventType.ThreeButtonPress) {
int lineNr = Document.OffsetToLineNumber (offset);
textEditor.SetSelectLines (lineNr, lineNr);
var range = textEditor.SelectionRange;
mouseWordStart = range.Offset;
mouseWordEnd = range.EndOffset;
InSelectionDrag = true;
mouseSelectionMode = MouseSelectionMode.WholeLine;
return;
}
mouseSelectionMode = MouseSelectionMode.SingleChar;
if (textEditor.IsSomethingSelected && IsInsideSelection (clickLocation) && clickLocation != textEditor.Caret.Location) {
inDrag = true;
} else {
if ((args.ModifierState & Gdk.ModifierType.ShiftMask) == ModifierType.ShiftMask) {
InSelectionDrag = true;
Caret.PreserveSelection = true;
if (!textEditor.IsSomethingSelected) {
textEditor.MainSelection = new Selection (Caret.Location, clickLocation);
Caret.Location = clickLocation;
} else {
Caret.Location = clickLocation;
textEditor.ExtendSelectionTo (clickLocation);
}
Caret.PreserveSelection = false;
} else {
textEditor.ClearSelection ();
Caret.Location = clickLocation;
InSelectionDrag = true;
textEditor.MainSelection = new Selection (clickLocation, clickLocation);
}
textEditor.RequestResetCaretBlink ();
}
}
DocumentLocation docLocation = PointToLocation (args.X, args.Y, snapCharacters: true);
if (docLocation.Line < DocumentLocation.MinLine || docLocation.Column < DocumentLocation.MinColumn)
return;
// disable middle click on windows.
if (!Platform.IsWindows && args.Button == 2 && this.textEditor.CanEdit (docLocation.Line)) {
TextSegment selectionRange = TextSegment.Invalid;
int offset = Document.LocationToOffset (docLocation);
if (!selection.IsEmpty)
selectionRange = selection.GetSelectionRange (this.textEditor.GetTextEditorData ());
var oldVersion = textEditor.Document.Version;
bool autoScroll = textEditor.Caret.AutoScrollToCaret;
textEditor.Caret.AutoScrollToCaret = false;
if (!selection.IsEmpty && selectionRange.Contains (offset)) {
textEditor.ClearSelection ();
textEditor.Caret.Offset = selectionRange.EndOffset;
return;
}
ClipboardActions.PasteFromPrimary (textEditor.GetTextEditorData (), offset);
textEditor.Caret.Offset = oldOffset;
if (!selectionRange.IsInvalid)
textEditor.SelectionRange = new TextSegment (oldVersion.MoveOffsetTo (Document.Version, selectionRange.Offset), selectionRange.Length);
if (autoScroll)
textEditor.Caret.ActivateAutoScrollWithoutMove ();
}
}