Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1250,32 +1250,46 @@ protected override void OnDragDataReceived (DragContext context, int x, int y, S
int dragOffset = Document.LocationToOffset (dragCaretPos);
if (context.Action == DragAction.Move) {
if (CanEdit (Caret.Line) && !selection.IsEmpty) {
var selectionRange = selection.GetSelectionRange (textEditorData);
if (selectionRange.Offset < dragOffset)
dragOffset -= selectionRange.Length;
if (selection.SelectionMode == MonoDevelop.Ide.Editor.SelectionMode.Normal)
{
var selectionRange = selection.GetSelectionRange(textEditorData);
if (selectionRange.Offset < dragOffset)
dragOffset -= selectionRange.Length;
}
else
{
int selectionRange = Math.Abs(selection.Anchor.Column - selection.Lead.Column) * (Math.Abs(selection.Anchor.Line - selection.Lead.Line) + 1);
selectionRange -= selection.GetVirtualSpacesCount (textEditorData);
if (Math.Min(selection.GetAnchorOffset(textEditorData), selection.GetLeadOffset(textEditorData)) < dragOffset)
dragOffset -= selectionRange;
}
Caret.PreserveSelection = true;
textEditorData.DeleteSelection (selection);
//textEditorData.DeleteSelection (selection);
ClipboardActions.Cut(textEditorData);
Caret.PreserveSelection = false;

selection = MonoDevelop.Ide.Editor.Selection.Empty;
//selection = MonoDevelop.Ide.Editor.Selection.Empty;
}
}
if (selection_data.Length > 0 && selection_data.Format == 8) {
Caret.Offset = dragOffset;
if (CanEdit (dragCaretPos.Line)) {
int offset = Caret.Offset;
if (!selection.IsEmpty && selection.GetSelectionRange (textEditorData).Offset >= offset) {
var start = Document.OffsetToLocation (selection.GetSelectionRange (textEditorData).Offset + selection_data.Text.Length);
var end = Document.OffsetToLocation (selection.GetSelectionRange (textEditorData).Offset + selection_data.Text.Length + selection.GetSelectionRange (textEditorData).Length);
selection = new MonoDevelop.Ide.Editor.Selection (start, end);
}
textEditorData.PasteText (offset, selection_data.Text, null, ref undo);
Caret.Offset = offset + selection_data.Text.Length;
MainSelection = new MonoDevelop.Ide.Editor.Selection (Document.OffsetToLocation (offset), Caret.Location);
}
dragOver = false;
context = null;
}
Caret.Offset = dragOffset;
//if (selection_data.Length > 0 && selection_data.Format == 8) {
// Caret.Offset = dragOffset;
// if (CanEdit (dragCaretPos.Line)) {
// int offset = Caret.Offset;
// if (!selection.IsEmpty && selection.GetSelectionRange (textEditorData).Offset >= offset) {
// var start = Document.OffsetToLocation (selection.GetSelectionRange (textEditorData).Offset + selection_data.Text.Length);
// var end = Document.OffsetToLocation (selection.GetSelectionRange (textEditorData).Offset + selection_data.Text.Length + selection.GetSelectionRange (textEditorData).Length);
// selection = new MonoDevelop.Ide.Editor.Selection (start, end);
// }
// textEditorData.PasteText (offset, selection_data.Text, null, ref undo);
// Caret.Offset = offset + selection_data.Text.Length;
// MainSelection = new MonoDevelop.Ide.Editor.Selection (Document.OffsetToLocation (offset), Caret.Location);
// }
// dragOver = false;
// context = null;
//}
ClipboardActions.Paste(textEditorData);
dragOver = false;
context = null;
mouseButtonPressed = 0;
undo.Dispose ();
base.OnDragDataReceived (context, x, y, selection_data, info, time_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2026,23 +2026,35 @@ void DrawLinePart (Cairo.Context cr, DocumentLine line, int lineNumber, int logi
DecorateTabsAndSpaces (cr, layout, offset, xPos, y, selectionStartOffset, selectionEndOffset);


if (textEditor.IsSomethingSelected && !isSelectionDrawn && BackgroundRenderer == null) {
if (lineNumber == textEditor.MainSelection.End.Line && textEditor.MainSelection.End.Column > line.Length + 1) {
using (var wrapper = GetVirtualSpaceLayout (line, textEditor.MainSelection.End)) {
double startX;
double endX;
startX = xPos;
endX = position + wrapper.Width + layout.Width;

DrawRectangleWithRuler (cr, xPos + textEditor.HAdjustment.Value - TextStartPosition, new Cairo.Rectangle (startX, y, endX - startX, _lineHeight), SyntaxHighlightingService.GetColor (textEditor.EditorTheme, EditorThemeColors.Selection), true);

if (lineNumber == Caret.Line &&
textEditor.Options.ShowWhitespaces == ShowWhitespaces.Selection &&
textEditor.IsSomethingSelected &&
(selectionStartOffset < offset || selectionStartOffset == selectionEndOffset) &&
BackgroundRenderer == null) {
DecorateTabsAndSpaces (cr, wrapper, offset, xPos, y, selectionStartOffset, selectionEndOffset + wrapper.Text.Length);
if (textEditor.IsSomethingSelected && !isSelectionDrawn && BackgroundRenderer == null && textEditor.MainSelection.SelectionMode == MonoDevelop.Ide.Editor.SelectionMode.Block) {
DocumentLocation rightCorner = new DocumentLocation(textEditor.MainSelection.End.Line, Math.Max(textEditor.MainSelection.Start.Column, textEditor.MainSelection.End.Column));
if (lineNumber >= textEditor.MainSelection.Start.Line && lineNumber <= textEditor.MainSelection.End.Line && rightCorner.Column > line.Length + 1) {
using (var wrapper = GetVirtualSpaceLayout (line, rightCorner)) {
if (line.Length >= Math.Min (textEditor.MainSelection.Anchor.Column, textEditor.MainSelection.Lead.Column))
{
double startX = Math.Floor (position + layout.Width);
double endX = Math.Ceiling (wrapper.Width);

DrawRectangleWithRuler(cr, xPos + textEditor.HAdjustment.Value - TextStartPosition, new Cairo.Rectangle(startX, y, endX, _lineHeight), SyntaxHighlightingService.GetColor(textEditor.EditorTheme, EditorThemeColors.Selection), true);
}
else if (line.Length < textEditor.MainSelection.Anchor.Column)
{
DocumentLine fakeLine = textEditor.Lines.MaxValue(x => x.Length);
LayoutWrapper fakeLineLayoutWrapper = CreateLinePartLayout(fakeLine, logicalRulerColumn, fakeLine.Offset, fakeLine.Length, -1, -1);
var startIndex = fakeLineLayoutWrapper.IndexToPos(Math.Min (textEditor.MainSelection.Anchor.Column, textEditor.MainSelection.Lead.Column) - 1);
var endIndex = fakeLineLayoutWrapper.IndexToPos(Math.Max(textEditor.MainSelection.Anchor.Column, textEditor.MainSelection.Lead.Column) - 1);
double startX = Math.Floor (startIndex.X / Pango.Scale.PangoScale) + position;
double endX = Math.Ceiling (endIndex.X / Pango.Scale.PangoScale) + position;

DrawRectangleWithRuler(cr, xPos + textEditor.HAdjustment.Value - TextStartPosition, new Cairo.Rectangle(startX, y, endX - startX, _lineHeight), SyntaxHighlightingService.GetColor(textEditor.EditorTheme, EditorThemeColors.Selection), true);
}
//if (lineNumber == Caret.Line &&
// textEditor.Options.ShowWhitespaces == ShowWhitespaces.Selection &&
// textEditor.IsSomethingSelected &&
// (selectionStartOffset < offset || selectionStartOffset == selectionEndOffset) &&
// BackgroundRenderer == null) {
// DecorateTabsAndSpaces (cr, wrapper, offset, xPos, y, selectionStartOffset, selectionEndOffset + wrapper.Text.Length);
//}

DrawIndent (cr, wrapper, line, position, y);
}
Expand Down Expand Up @@ -2208,14 +2220,14 @@ enum MouseSelectionMode

internal bool CalculateClickLocation (double x, double y, out DocumentLocation clickLocation)
{
VisualLocationTranslator trans = new VisualLocationTranslator (this);
VisualLocationTranslator trans = new VisualLocationTranslator (this, textEditor);

clickLocation = trans.PointToLocation (x, y, snapCharacters: true);
if (clickLocation.Line < DocumentLocation.MinLine || clickLocation.Column < DocumentLocation.MinColumn)
return false;
DocumentLine line = Document.GetLine (clickLocation.Line);
if (line != null && clickLocation.Column >= line.Length + 1 && GetWidth (Document.GetTextAt (line.SegmentIncludingDelimiter) + "-") < x) {
clickLocation = new DocumentLocation (clickLocation.Line, line.Length + 1);
//clickLocation = new DocumentLocation (clickLocation.Line, line.Length + 1);
if (textEditor.GetTextEditorData ().HasIndentationTracker && textEditor.Options.IndentStyle == IndentStyle.Virtual && clickLocation.Column == 1) {
int indentationColumn = this.textEditor.GetTextEditorData ().GetVirtualIndentationColumn (clickLocation);
if (indentationColumn > clickLocation.Column)
Expand Down Expand Up @@ -2681,8 +2693,10 @@ protected internal override void MouseHover (MarginMouseEventArgs args)
} else {
textEditor.ExtendSelectionTo (loc);
}
Caret.Location = loc;
//Caret.Location = loc;
}
else
return;
break;
case MouseSelectionMode.Word:
if (loc.Line != Caret.Line || !textEditor.GetTextEditorData ().IsCaretInVirtualLocation) {
Expand Down Expand Up @@ -3265,6 +3279,7 @@ protected internal override void MouseLeft ()
class VisualLocationTranslator
{
TextViewMargin margin;
MonoTextEditor textEditor;
int lineNumber;
DocumentLine line;
int xPos = 0;
Expand All @@ -3275,9 +3290,10 @@ public bool WasInLine {
set;
}

public VisualLocationTranslator (TextViewMargin margin)
public VisualLocationTranslator (TextViewMargin margin, MonoTextEditor textEditor)
{
this.margin = margin;
this.textEditor = textEditor;
}

int index;
Expand Down Expand Up @@ -3313,7 +3329,8 @@ static bool IsNearX1 (int pos, int x1, int x2)
public DocumentLocation PointToLocation (double xp, double yp, bool endAtEol = false, bool snapCharacters = false)
{
lineNumber = System.Math.Min (margin.YToLine (yp + margin.textEditor.VAdjustment.Value), margin.Document.LineCount);
line = lineNumber <= margin.Document.LineCount ? margin.Document.GetLine (lineNumber) : null;
//line = lineNumber <= margin.Document.LineCount ? margin.Document.GetLine (lineNumber) : null;
line = textEditor.Lines.MaxValue(x => x.Length);
this.snapCharacters = snapCharacters;
if (line == null)
return DocumentLocation.Empty;
Expand Down Expand Up @@ -3407,17 +3424,17 @@ public DocumentLocation PointToLocation (double xp, double yp, bool endAtEol = f

public DocumentLocation PointToLocation (double xp, double yp, bool endAtEol = false, bool snapCharacters = false)
{
return new VisualLocationTranslator (this).PointToLocation (xp, yp, endAtEol, snapCharacters);
return new VisualLocationTranslator (this, textEditor).PointToLocation (xp, yp, endAtEol, snapCharacters);
}

public DocumentLocation PointToLocation (Cairo.Point p, bool endAtEol = false, bool snapCharacters = false)
{
return new VisualLocationTranslator (this).PointToLocation (p.X, p.Y, endAtEol, snapCharacters);
return new VisualLocationTranslator (this, textEditor).PointToLocation (p.X, p.Y, endAtEol, snapCharacters);
}

public DocumentLocation PointToLocation (Cairo.PointD p, bool endAtEol = false, bool snapCharacters = false)
{
return new VisualLocationTranslator (this).PointToLocation (p.X, p.Y, endAtEol, snapCharacters);
return new VisualLocationTranslator (this, textEditor).PointToLocation (p.X, p.Y, endAtEol, snapCharacters);
}

public Cairo.Point LocationToPoint (int line, int column)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,12 @@ static int PasteFrom (Clipboard clipboard, TextEditorData data, bool preserveSel
if (curLine.Length + 1 < lineCol) {
result += lineCol - curLine.Length;
data.Insert (curLine.Offset + curLine.Length, new string (' ', lineCol - curLine.Length));
curLine = data.Document.GetLine (lineNr + i);
}
data.Insert (curLine.Offset + lineCol, lines [i]);
if (curLine.Length == 0)
data.Insert(curLine.Offset, lines[i]);
else
data.Insert (curLine.Offset + lineCol, lines [i]);
result += lines [i].Length;
}
if (!preserveState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,15 @@ public int GetVisualColumn (TextEditorData editor, int logicalColumn)
int offset = Offset;
var tabSize = editor.Options.TabSize;
if (editor.Options.IndentStyle == IndentStyle.Virtual && Length == 0 && logicalColumn > DocumentLocation.MinColumn) {
foreach (char ch in editor.GetIndentationString (Offset)) {
var indentString = editor.GetIndentationString (Offset);
foreach (char ch in indentString) {
if (ch == '\t') {
result += tabSize;
continue;
}
result++;
}
result += Math.Max (0, logicalColumn - indentString.Length - 1);
return result;
}

Expand Down
23 changes: 23 additions & 0 deletions main/src/core/Mono.TextEditor.Shared/Mono.TextEditor/Selection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,28 @@ public static int GetLeadOffset (this Selection selection, TextEditorData data)
{
return data.Document.LocationToOffset (selection.Lead);
}

public static int GetVirtualSpacesCount (this Selection selection, TextEditorData data)
{
if (selection.SelectionMode == SelectionMode.Normal)
return 0;

int result = 0;
int minColumn = Math.Min (selection.Anchor.Column, selection.Lead.Column);
int maxColumn = Math.Max (selection.Anchor.Column, selection.Lead.Column);

for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) {
var line = data.GetLine (lineNr);
if (line.Length < maxColumn) {
if (minColumn < line.Length) {
result += maxColumn - line.Length - 1;
} else {
result += maxColumn - minColumn;
}
}
}

return result;
}
}
}