Scroling document by text selection #388
Replies: 11 comments
-
@Gillibald do you think this could be fixed? AFAIK the textbox is able tondo that so it would be applying the same here I guess... |
Beta Was this translation helpful? Give feedback.
-
I am not so familiar with the code but it sounds like this should be possible |
Beta Was this translation helpful? Give feedback.
-
Can you please refer to the Avalonia code that fires the scrolling when the mouse is reaching the edges for reference? |
Beta Was this translation helpful? Give feedback.
-
i make some observations about this situation maybe this will be helpful. scroling (with mouse selection) is possible only for about 200 lines and stops.. becouse GetVisualLineFromVisualTop returns null at some point... AvaloniaEdit/src/AvaloniaEdit/Editing/SelectionMouseHandler.cs Lines 585 to 593 in be8fc93 AvaloniaEdit/src/AvaloniaEdit/Rendering/TextView.cs Lines 1648 to 1661 in be8fc93 when offset is -1 SetCaretOffsetToMousePosition fails.. i tried to fix GetVisualLineFromVisualTop by adding
to GetOffsetFromMousePosition becouse the is already simillar code
but this only cousing that scroll works for only few more lines... code that "works" (and probably breaks some other scenario..) is : instead AvaloniaEdit/src/AvaloniaEdit/Editing/SelectionMouseHandler.cs Lines 653 to 678 in be8fc93 private void SetCaretOffsetToMousePosition(PointerEventArgs e, ISegment allowedSegment = null)
{
int visualColumn;
bool isAtEndOfLine;
int offset;
if (_mode == SelectionMode.Rectangular)
{
offset = GetOffsetFromMousePositionFirstTextLineOnly(e.GetPosition(TextArea.TextView), out visualColumn);
isAtEndOfLine = true;
}
else
{
offset = GetOffsetFromMousePosition(e, out visualColumn, out isAtEndOfLine);
}
if (allowedSegment != null)
{
offset = offset.CoerceValue(allowedSegment.Offset, allowedSegment.EndOffset);
}
if (offset == -1)
{
var tmpLoc = TextArea.Caret.Position.Location;
int currentOffset = TextArea.Document.GetOffset(tmpLoc);
int addToOffset = TextArea.Document.Lines[tmpLoc.Line].Length;
if (tmpLoc.Line < TextArea.Document.LineCount - 1)
{
addToOffset += TextArea.Document.Lines[tmpLoc.Line +1].Length;
}
if (currentOffset + addToOffset < TextArea.Document.TextLength)
{
offset = currentOffset + addToOffset;
}
}
if (offset >= 0)
{
var loc = TextArea.Document.GetLocation(offset);
var newPos = new TextViewPosition(loc, visualColumn) { IsAtEndOfLine = isAtEndOfLine };
Debug.WriteLine("old pos" + TextArea.Caret.Position);
Debug.WriteLine("new pos" + newPos);
if (newPos == TextArea.Caret.Position && _mode == SelectionMode.Normal)
{
double actualY = e.GetPosition(TextArea.TextView).Y;
if (actualY > TextArea.TextView.Bounds.Height && loc.Line < TextArea.Document.LineCount) // fix scroll down
{
newPos = new TextViewPosition(loc.Line + 1, 0, visualColumn) { IsAtEndOfLine = isAtEndOfLine };
}
else if (actualY < 0 && loc.Line > 0) // fix scroll up
{
newPos = new TextViewPosition(loc.Line - 1, 0, visualColumn) { IsAtEndOfLine = isAtEndOfLine };
}
}
TextArea.Caret.Position = newPos;
TextArea.Caret.DesiredXPos = double.NaN;
}
//else
//{
// var line = TextArea.Caret.Position.Line + 1;
// var column = 0;
// TextArea.Caret.Position = new TextViewPosition(new TextLocation(line, column), visualColumn) { IsAtEndOfLine = isAtEndOfLine };
// TextArea.Caret.DesiredXPos = double.NaN;
//}
} |
Beta Was this translation helpful? Give feedback.
-
We should also check the original implementation (AvalonEdit) ... to see if all is ported fine. |
Beta Was this translation helpful? Give feedback.
-
In avalon edis issue is not present. |
Beta Was this translation helpful? Give feedback.
-
in WPF implemetation when selection scroling starts some part from above line is visible.... That imples one more visual line is avaiable without selecion starts and eds looks "normal" (no fraction of line is visible) in Avalonia implementation scrolling up do not trigger because no visual line number 65. on screen Question is.. can we use the same idea as AvalonEdit used ? Edit.. WOW this is very simple.. is ExtendSelectionToMouse.. PR: |
Beta Was this translation helpful? Give feedback.
-
Thanks for the PR. In fact I remember removing that extra space to avoid scroll jumps... See related PR. #254 I'm guessing if we can add some logic to make the scrolling only when we're dragging... |
Beta Was this translation helpful? Give feedback.
-
well i changed TextArea.Caret.BringCaretToView(0) -> TextArea.Caret.BringCaretToView(5) only in ExtendSelectionToMouse method. |
Beta Was this translation helpful? Give feedback.
-
I works with long SQL codes. Its common to select very long SQL and run it. In AvaloniaEdit selecting text by mouse above first visible line is not possible.. for some reason document is not scrolled automaticly.
Using Shift + arrow works fine- document is automaticly scrolled.
To reproduce try to select lines from 81 to 1 by mouse...
Simmilar issus is with selection is oposite direction from line 1 to 81 its not possible (by left mouse button + mouse gesture), document scrolls but only for few lines..
Is it possble to change this behavior ?
Beta Was this translation helpful? Give feedback.
All reactions