protected void OnDragOver(object sender, DragEventArgs e) { if (!textArea.Focused) { textArea.Focus(); } var p = textArea.PointToClient(new Point(e.X, e.Y)); if (textArea.TextView.DrawingPosition.Contains(p.X, p.Y)) { var realmousepos = textArea.TextView.GetLogicalPosition( p.X - textArea.TextView.DrawingPosition.X, p.Y - textArea.TextView.DrawingPosition.Y); var lineNr = Math.Min(textArea.Document.TotalNumberOfLines - 1, Math.Max(val1: 0, realmousepos.Y)); textArea.Caret.Position = new TextLocation(realmousepos.X, lineNr); textArea.SetDesiredColumn(); if (IsSupportedData(e.Data) && !textArea.IsReadOnly(textArea.Caret.Offset)) { e.Effect = GetDragDropEffect(e); } else { e.Effect = DragDropEffects.None; } } else { e.Effect = DragDropEffects.None; } }
protected void OnDragOver(object sender, DragEventArgs e) { if (!_textArea.Focused) { _textArea.Focus(); } Point p = _textArea.PointToClient(new Point(e.X, e.Y)); if (_textArea.TextView.DrawingPosition.Contains(p.X, p.Y)) { TextLocation realmousepos = _textArea.TextView.GetLogicalPosition(p.X - _textArea.TextView.DrawingPosition.X, p.Y - _textArea.TextView.DrawingPosition.Y); int lineNr = Math.Min(_textArea.Document.TotalNumberOfLines - 1, Math.Max(0, realmousepos.Y)); _textArea.Caret.Position = new TextLocation(realmousepos.X, lineNr); _textArea.SetDesiredColumn(); if (e.Data.GetDataPresent(typeof(string)) && !_textArea.IsReadOnly(_textArea.Caret.Offset)) { e.Effect = GetDragDropEffect(e); } else { e.Effect = DragDropEffects.None; } } else { e.Effect = DragDropEffects.None; } }
protected void OnDragOver(object sender, DragEventArgs e) { if (!textArea.Focused) { textArea.Focus(); } Point p = textArea.PointToClient(new Point(e.X, e.Y)); if (textArea.TextView.DrawingPosition.Contains(p.X, p.Y)) { Point realmousepos = textArea.TextView.GetLogicalPosition(p.X - textArea.TextView.DrawingPosition.X, p.Y - textArea.TextView.DrawingPosition.Y); int lineNr = Math.Min(textArea.Document.TotalNumberOfLines - 1, Math.Max(0, realmousepos.Y)); textArea.Caret.Position = new Point(realmousepos.X, lineNr); textArea.SetDesiredColumn(); if (textArea.EnableCutOrPaste == false) { e.Effect = DragDropEffects.None; return; } if (e.Data.GetDataPresent(typeof(string))) { e.Effect = GetDragDropEffect(e); } } }
public void JumpTo(int line, int column) { textArea.Focus(); textArea.SelectionManager.ClearSelection(); textArea.Caret.Position = new TextLocation(column, line); textArea.SetDesiredColumn(); ScrollToCaret(); }
public void HandleMouseDown(Point mousepos, MouseButtons mouseButtons) { bool showFolding = Shared.TEP.EnableFolding; int physicalLine = +(int)((mousepos.Y + TextArea.VirtualTop.Y) / TextArea._FontHeight); int realline = TextArea.Document.GetFirstLogicalLine(physicalLine); // focus the textarea if the user clicks on the line number view TextArea.Focus(); if (!showFolding || realline < 0 || realline + 1 >= TextArea.Document.TotalNumberOfLines) { return; } List <FoldMarker> foldMarkers = TextArea.Document.FoldingManager.GetFoldingsWithStart(realline); foreach (FoldMarker fm in foldMarkers) { fm.IsFolded = !fm.IsFolded; } TextArea.Document.FoldingManager.NotifyFoldingsChanged(EventArgs.Empty); }
void OnMouseDown(object sender, MouseEventArgs e) { Point mousepos; mousepos = textArea.mousepos; if (dodragdrop) { return; } if (doubleclick) { doubleclick = false; return; } if (textArea.TextView.DrawingPosition.Contains(mousepos.X, mousepos.Y)) { gotmousedown = true; textArea.SelectionManager.selectFrom.where = WhereFrom.TArea; button = e.Button; if (button == MouseButtons.Left && (DateTime.Now - lastTime).Milliseconds < SystemInformation.DoubleClickTime) { int deltaX = Math.Abs(lastmousedownpos.X - e.X); int deltaY = Math.Abs(lastmousedownpos.Y - e.Y); if (deltaX <= SystemInformation.DoubleClickSize.Width && deltaY <= SystemInformation.DoubleClickSize.Height) { DoubleClickSelectionExtend(); lastTime = DateTime.Now; lastmousedownpos = new Point(e.X, e.Y); return; } } minSelection = nilPoint; maxSelection = nilPoint; lastTime = DateTime.Now; lastmousedownpos = mousedownpos = new Point(e.X, e.Y); if (button == MouseButtons.Left) { FoldMarker marker = textArea.TextView.GetFoldMarkerFromPosition(mousepos.X - textArea.TextView.DrawingPosition.X, mousepos.Y - textArea.TextView.DrawingPosition.Y); if (marker != null && marker.IsFolded) { if (textArea.SelectionManager.HasSomethingSelected) { clickedOnSelectedText = true; } textArea.SelectionManager.SetSelection(new DefaultSelection(textArea.TextView.Document, new Point(marker.StartColumn, marker.StartLine), new Point(marker.EndColumn, marker.EndLine))); textArea.Focus(); return; } if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) { ExtendSelectionToMouse(); } else { Point realmousepos = textArea.TextView.GetLogicalPosition(mousepos.X - textArea.TextView.DrawingPosition.X, mousepos.Y - textArea.TextView.DrawingPosition.Y); clickedOnSelectedText = false; int offset = textArea.Document.PositionToOffset(realmousepos); if (textArea.SelectionManager.HasSomethingSelected && textArea.SelectionManager.IsSelected(offset)) { clickedOnSelectedText = true; } else { selbegin = selend = offset; textArea.SelectionManager.ClearSelection(); if (mousepos.Y > 0 && mousepos.Y < textArea.TextView.DrawingPosition.Height) { Point pos = new Point(); pos.Y = Math.Min(textArea.Document.TotalNumberOfLines - 1, realmousepos.Y); pos.X = realmousepos.X; textArea.Caret.Position = pos; //Math.Max(0, Math.Min(textArea.Document.TextLength, line.Offset + Math.Min(line.Length, pos.X))); textArea.SetDesiredColumn(); } } } } else if (button == MouseButtons.Right) { // Rightclick sets the cursor to the click position unless // the previous selection was clicked Point realmousepos = textArea.TextView.GetLogicalPosition(mousepos.X - textArea.TextView.DrawingPosition.X, mousepos.Y - textArea.TextView.DrawingPosition.Y); int offset = textArea.Document.PositionToOffset(realmousepos); if (!textArea.SelectionManager.HasSomethingSelected || !textArea.SelectionManager.IsSelected(offset)) { selbegin = selend = offset; textArea.SelectionManager.ClearSelection(); if (mousepos.Y > 0 && mousepos.Y < textArea.TextView.DrawingPosition.Height) { Point pos = new Point(); pos.Y = Math.Min(textArea.Document.TotalNumberOfLines - 1, realmousepos.Y); pos.X = realmousepos.X; textArea.Caret.Position = pos; //Math.Max(0, Math.Min(textArea.Document.TextLength, line.Offset + Math.Min(line.Length, pos.X))); textArea.SetDesiredColumn(); } } } } textArea.Focus(); }
void OnMouseDown(object sender, MouseEventArgs e) { Point mousepos; textArea.mousepos = e.Location; mousepos = e.Location; if (dodragdrop) { return; } if (doubleclick) { doubleclick = false; return; } if (textArea.TextView.DrawingPosition.Contains(mousepos.X, mousepos.Y)) { gotmousedown = true; textArea.SelectionManager.selectFrom.where = WhereFrom.TArea; button = e.Button; // double-click if (button == MouseButtons.Left && e.Clicks == 2) { int deltaX = Math.Abs(lastmousedownpos.X - e.X); int deltaY = Math.Abs(lastmousedownpos.Y - e.Y); if (deltaX <= SystemInformation.DoubleClickSize.Width && deltaY <= SystemInformation.DoubleClickSize.Height) { DoubleClickSelectionExtend(); lastmousedownpos = new Point(e.X, e.Y); if (textArea.SelectionManager.selectFrom.where == WhereFrom.Gutter) { if (!minSelection.IsEmpty && !maxSelection.IsEmpty && textArea.SelectionManager.SelectionCollection.Count > 0) { textArea.SelectionManager.SelectionCollection[0].StartPosition = minSelection; textArea.SelectionManager.SelectionCollection[0].EndPosition = maxSelection; textArea.SelectionManager.SelectionStart = minSelection; minSelection = TextLocation.Empty; maxSelection = TextLocation.Empty; } } return; } } minSelection = TextLocation.Empty; maxSelection = TextLocation.Empty; lastmousedownpos = mousedownpos = new Point(e.X, e.Y); if (button == MouseButtons.Left) { FoldMarker marker = textArea.TextView.GetFoldMarkerFromPosition(mousepos.X - textArea.TextView.DrawingPosition.X, mousepos.Y - textArea.TextView.DrawingPosition.Y); if (marker != null && marker.IsFolded) { if (textArea.SelectionManager.HasSomethingSelected) { clickedOnSelectedText = true; } TextLocation startLocation = new TextLocation(marker.StartColumn, marker.StartLine); TextLocation endLocation = new TextLocation(marker.EndColumn, marker.EndLine); textArea.SelectionManager.SetSelection(new DefaultSelection(textArea.TextView.Document, startLocation, endLocation)); textArea.Caret.Position = startLocation; textArea.SetDesiredColumn(); textArea.Focus(); return; } if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) { ExtendSelectionToMouse(); } else { TextLocation realmousepos = textArea.TextView.GetLogicalPosition(mousepos.X - textArea.TextView.DrawingPosition.X, mousepos.Y - textArea.TextView.DrawingPosition.Y); clickedOnSelectedText = false; int offset = textArea.Document.PositionToOffset(realmousepos); if (textArea.SelectionManager.HasSomethingSelected && textArea.SelectionManager.IsSelected(offset)) { clickedOnSelectedText = true; } else { textArea.SelectionManager.ClearSelection(); if (mousepos.Y > 0 && mousepos.Y < textArea.TextView.DrawingPosition.Height) { TextLocation pos = new TextLocation(); pos.Y = Math.Min(textArea.Document.TotalNumberOfLines - 1, realmousepos.Y); pos.X = realmousepos.X; textArea.Caret.Position = pos; textArea.SetDesiredColumn(); } } } } else if (button == MouseButtons.Right) { // Rightclick sets the cursor to the click position unless // the previous selection was clicked TextLocation realmousepos = textArea.TextView.GetLogicalPosition(mousepos.X - textArea.TextView.DrawingPosition.X, mousepos.Y - textArea.TextView.DrawingPosition.Y); int offset = textArea.Document.PositionToOffset(realmousepos); if (!textArea.SelectionManager.HasSomethingSelected || !textArea.SelectionManager.IsSelected(offset)) { textArea.SelectionManager.ClearSelection(); if (mousepos.Y > 0 && mousepos.Y < textArea.TextView.DrawingPosition.Height) { TextLocation pos = new TextLocation(); pos.Y = Math.Min(textArea.Document.TotalNumberOfLines - 1, realmousepos.Y); pos.X = realmousepos.X; textArea.Caret.Position = pos; textArea.SetDesiredColumn(); } } } } textArea.Focus(); }
void OnMouseDown(object sender, MouseEventArgs e) { Point mousepos; _textArea.MousePos = e.Location; mousepos = e.Location; if (_dodragdrop) { return; } if (_doubleclick) { _doubleclick = false; return; } if (_textArea.TextView.DrawingPosition.Contains(mousepos.X, mousepos.Y)) { _gotmousedown = true; _textArea.SelectionManager.WhereFrom = SelSource.TArea; _button = e.Button; // double-click if (_button == MouseButtons.Left && e.Clicks == 2) { int deltaX = Math.Abs(_lastmousedownpos.X - e.X); int deltaY = Math.Abs(_lastmousedownpos.Y - e.Y); if (deltaX <= SystemInformation.DoubleClickSize.Width && deltaY <= SystemInformation.DoubleClickSize.Height) { DoubleClickSelectionExtend(); _lastmousedownpos = new Point(e.X, e.Y); if (_textArea.SelectionManager.WhereFrom == SelSource.Gutter) { if (_minSelection.IsValid && _maxSelection.IsValid && _textArea.SelectionManager.IsValid) { _textArea.SelectionManager.StartPosition = _minSelection; _textArea.SelectionManager.EndPosition = _maxSelection; _minSelection = new TextLocation(); _maxSelection = new TextLocation(); } } return; } } _minSelection = new TextLocation(); _maxSelection = new TextLocation(); _lastmousedownpos = _mousedownpos = new Point(e.X, e.Y); bool isRect = (Control.ModifierKeys & Keys.Alt) != 0; if (_button == MouseButtons.Left) { FoldMarker marker = _textArea.TextView.GetFoldMarkerFromPosition(mousepos.X - _textArea.TextView.DrawingPosition.X, mousepos.Y - _textArea.TextView.DrawingPosition.Y); if (marker != null && marker.IsFolded) { if (_textArea.SelectionManager.HasSomethingSelected) { _clickedOnSelectedText = true; } TextLocation startLocation = new TextLocation(marker.StartColumn, marker.StartLine); TextLocation endLocation = new TextLocation(marker.EndColumn, marker.EndLine); _textArea.SelectionManager.SetSelection(startLocation, endLocation, isRect); _textArea.Caret.Position = startLocation; _textArea.SetDesiredColumn(); _textArea.Focus(); return; } if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) // Shift while selecting end point. { ExtendSelectionToMouse(); } else { TextLocation realmousepos = _textArea.TextView.GetLogicalPosition(mousepos.X - _textArea.TextView.DrawingPosition.X, mousepos.Y - _textArea.TextView.DrawingPosition.Y); _clickedOnSelectedText = false; int offset = _textArea.Document.PositionToOffset(realmousepos); if (_textArea.SelectionManager.HasSomethingSelected && _textArea.SelectionManager.IsSelected(offset)) { _clickedOnSelectedText = true; } else { _textArea.SelectionManager.ClearSelection(); if (mousepos.Y > 0 && mousepos.Y < _textArea.TextView.DrawingPosition.Height) { TextLocation pos = new TextLocation(); pos.Y = Math.Min(_textArea.Document.TotalNumberOfLines - 1, realmousepos.Y); pos.X = realmousepos.X; _textArea.Caret.Position = pos; _textArea.SelectionManager.SetSelection(pos, pos, isRect); _textArea.SetDesiredColumn(); } } } } else if (_button == MouseButtons.Right) { // Rightclick sets the cursor to the click position unless the previous selection was clicked TextLocation realmousepos = _textArea.TextView.GetLogicalPosition(mousepos.X - _textArea.TextView.DrawingPosition.X, mousepos.Y - _textArea.TextView.DrawingPosition.Y); int offset = _textArea.Document.PositionToOffset(realmousepos); if (!_textArea.SelectionManager.HasSomethingSelected || !_textArea.SelectionManager.IsSelected(offset)) { _textArea.SelectionManager.ClearSelection(); if (mousepos.Y > 0 && mousepos.Y < _textArea.TextView.DrawingPosition.Height) { TextLocation pos = new TextLocation(); pos.Y = Math.Min(_textArea.Document.TotalNumberOfLines - 1, realmousepos.Y); pos.X = realmousepos.X; _textArea.Caret.Position = pos; _textArea.SetDesiredColumn(); } } } } _textArea.Focus(); }
private void listBox1_MouseDoubleClick_1(object sender, MouseEventArgs e) { if (listBox1.SelectedItems == null) { return; } var s = listBox1.SelectedItems[0].Text; ICSharpCode.TextEditor.TextArea ta = MainForm.CurrentCodeFileDocument.TextEditor.ActiveTextAreaControl.TextArea; ta.Focus(); var full = schoolManager.ht.Keys.FirstOrDefault(st => st.StartsWith(s)); //if (schoolManager.ht.Keys.Select(st=>st.Substring(0,s.IndexOf('/'))).Contains(s)) if (full != null) { // Если шаблон начинается с begin и предыдущая конструкция с начала строки - управляющий оператор, то сдвинуть курсор, выровняв по предыдущей конструкции if (s.StartsWith("begin … end")) { var Prev = GetPrevLine(ta.Caret.Line); Match m = null; if (Prev != null) { m = Regex.Match(Prev, @"^\s*(loop|for|while|if|else)", RegexOptions.IgnoreCase); if (m.Groups[1].Value.Length > 0) { var Curr = GetLine(ta.Caret.Line); if (Curr.Length > m.Groups[1].Index) { ta.Caret.Column = Curr.Length; ta.InsertString(new string(' ', Curr.Length - m.Groups[1].Index)); } ta.Caret.Column = m.Groups[1].Index; var doc = ta.Document; var tl_beg = new TextLocation(ta.Caret.Column, ta.Caret.Line); int offset = doc.PositionToOffset(tl_beg); if (Curr.Length > ta.Caret.Column && Curr.Substring(ta.Caret.Column).TrimEnd().Length == 0) { doc.Remove(offset, Curr.Length - ta.Caret.Column); } } } var Next = GetNextLine(ta.Caret.Line); if (m != null && m.Groups[1].Value.ToLower().Equals("if") && Next != null && Next.TrimStart().ToLower().StartsWith("else")) { CodeCompletionActionsManager.GenerateTemplate(s, ta, schoolManager, false, str => str.Remove(str.Length - 1)); // Удалить ; в begin end перед else } else { CodeCompletionActionsManager.GenerateTemplate(s, ta, schoolManager, false); } } else { CodeCompletionActionsManager.GenerateTemplate(s, ta, schoolManager, false); } } else { ta.InsertString(s); } ta.Focus(); }