Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RectangleSelection up to 150-200 lines slow #434

Open
alex8900vbs opened this issue Jan 11, 2025 · 0 comments
Open

RectangleSelection up to 150-200 lines slow #434

alex8900vbs opened this issue Jan 11, 2025 · 0 comments

Comments

@alex8900vbs
Copy link

hi, sorry for english but i use a translator. i tried for two days to speed up the management of the rectangular selection but without success, you can replicate the problem as follows: paste a text of 1000 lines, press and hold ALT and also hold down shift and the down arrow, to create a rectangular selection, go down until the program slows down around the 150-200 line. I tracked down the source of the problem and it is this:

public override Selection SetEndpoint(TextViewPosition endPosition)
in ICSharpCode.AvalonEdit.Editing

basically as it is designed every time you go down a line it calls
void CalculateSegments()
for all the lines

this means that at the 10th line the calculation it will do will be 10 lines, at the 150th line it will have to recalculate 150 lines, so the more you go down the slower the selection becomes, I tried with the following code to change the individual segments of the selection with excellent results in terms of speed but terrible in terms of consistency with everything else, is there any way to do it?

void CalculateSegmentsExists(TextViewPosition endPosition, int previousEndLine)
{
	for (int i = 0; i < segments.Count; i++) {
		SelectionSegment item = segments[i];
		DocumentLine myLine = textArea.Document.GetLineByOffset(item.EndOffset);
		int NewVC = endPosition.VisualColumn - item.EndVisualColumn;
		TextViewPosition textViewPosition = new TextViewPosition(myLine.LineNumber, endPosition.VisualColumn);
		if (myLine.Length < textViewPosition.Location.Column) {
			NewVC = 0;
		}
		segments[i] = new SelectionSegment(item.StartOffset, item.StartVisualColumn, item.EndOffset + NewVC, endPosition.VisualColumn);
	}
	if (endPosition.Line > previousEndLine) {
		for (int i = previousEndLine + 1; i <= endPosition.Line; i++) {
			VisualLine vl = textArea.TextView.GetOrConstructVisualLine(nextLine);
			int startVC = vl.GetVisualColumn(new Point(startXPos, 0), true);
			int endVC = vl.GetVisualColumn(new Point(endXPos, 0), true);

			int baseOffset = vl.FirstDocumentLine.Offset;
			int startOffset = baseOffset + vl.GetRelativeOffset(startVC);
			int endOffset = baseOffset + vl.GetRelativeOffset(endVC);
			segments.Add(new SelectionSegment(startOffset, startVC, endOffset, endVC));
		}
	}
}
				

what I thought is: instead of recreating the rectangular selection every time if there was a way to do some sort of update maybe it would be faster, the problem is that I'm faced with too many things that remain unaligned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant