Skip to content

Commit

Permalink
Merge branch 'master' into bump-textmate-sharp
Browse files Browse the repository at this point in the history
  • Loading branch information
danipen authored Jul 29, 2024
2 parents 44dd24c + 5fa5f8b commit 89c9018
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/AvaloniaEdit.TextMate/Compatibility/Math.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace AvaloniaEdit.TextMate.Compatibility
{
internal static class Math
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static int Clamp(int value, int min, int max)
{
return (value < min) ? min : (value > max) ? max : value;
}
}
}
10 changes: 9 additions & 1 deletion src/AvaloniaEdit.TextMate/TextEditorModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

using TextMateSharp.Model;

#if NET6_0_OR_GREATER
using Math = System.Math;
#else
using Math = AvaloniaEdit.TextMate.Compatibility.Math;
#endif

namespace AvaloniaEdit.TextMate
{
public class TextEditorModel : AbstractLineList, IDisposable
Expand Down Expand Up @@ -168,7 +174,9 @@ void DocumentOnUpdateFinished(object sender, EventArgs e)

try
{
InvalidateLineRange(_invalidRange.StartLine, _invalidRange.EndLine);
int startLine = Math.Clamp(_invalidRange.StartLine, 0, _documentSnapshot.LineCount - 1);
int endLine = Math.Clamp(_invalidRange.EndLine, 0, _documentSnapshot.LineCount - 1);
InvalidateLineRange(startLine, endLine);
}
finally
{
Expand Down

0 comments on commit 89c9018

Please sign in to comment.