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

This fixes #314 #320

Merged
merged 1 commit into from
Dec 24, 2022
Merged
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
20 changes: 12 additions & 8 deletions TextControlBox/TextControlBox.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime;
using System.Text;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -189,8 +190,7 @@ private void UpdateZoom()
NeedsTextFormatUpdate = true;

int Line = CursorPosition.LineNumber;
//Check whether the current line is outside the bounds of the visible area
if (Line < NumberOfStartLine || Line >= NumberOfStartLine + NumberOfRenderedLines)
if (OutOfRenderedArea(Line))
{
VerticalScrollbar.Value = (Line - NumberOfRenderedLines / 2) * SingleLineHeight;
}
Expand Down Expand Up @@ -667,7 +667,12 @@ private void UpdateWhenScrolled()
UpdateAll();
}
}


private bool OutOfRenderedArea(int line)
{
//Check whether the current line is outside the bounds of the visible area
return line < NumberOfStartLine || line >= NumberOfStartLine + NumberOfRenderedLines;
}
//Trys running the code and clears the memory if OutOfMemoryException gets thrown
private async void Safe_Paste(bool HandleException = true)
{
Expand Down Expand Up @@ -1898,11 +1903,8 @@ public void Redo()
/// <param name="index">The line to center</param>
public void ScrollLineToCenter(int index)
{
//Check whether the current line is outside the bounds of the visible area
if (index < NumberOfStartLine || index >= NumberOfStartLine + NumberOfRenderedLines)
{
if (OutOfRenderedArea(index))
ScrollLineIntoView(index);
}
}

/// <summary>
Expand Down Expand Up @@ -2105,7 +2107,9 @@ public void DuplicateLine(int index)
CursorPosition.LineNumber += 1;
}, TotalLines, index, 1, 2, NewLineCharacter);

ScrollOneLineDown();
if(OutOfRenderedArea(index))
ScrollOneLineDown();

UpdateText();
UpdateCursor();
}
Expand Down