Skip to content

Commit

Permalink
perf: only invalidate InlineCollection layout when properties change
Browse files Browse the repository at this point in the history
  • Loading branch information
ramezgerges committed Jan 18, 2024
1 parent a1bb138 commit 190a824
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/Uno.UI/UI/Xaml/Documents/InlineCollection.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,35 @@ internal bool CaretAtEndOfSelection
get => _caretAtEndOfSelection;
set
{
_caretAtEndOfSelection = value;
((IBlock)_collection.GetParent()).Invalidate(false);
if (_caretAtEndOfSelection != value)
{
_caretAtEndOfSelection = value;
((IBlock)_collection.GetParent()).Invalidate(false);
}
}
}
internal bool RenderSelection
{
get => _renderSelection;
set
{
_renderSelection = value;
((IBlock)_collection.GetParent()).Invalidate(false);
if (_renderSelection != value)
{
_renderSelection = value;
((IBlock)_collection.GetParent()).Invalidate(false);
}
}
}
internal bool RenderCaret
{
get => _renderCaret;
set
{
_renderCaret = value;
((IBlock)_collection.GetParent()).Invalidate(false);
if (_renderCaret != value)
{
_renderCaret = value;
((IBlock)_collection.GetParent()).Invalidate(false);
}
}
}

Expand All @@ -97,11 +106,20 @@ internal bool RenderCaret
{
set
{
if (_selection is SelectionDetails sd && sd.StartIndex == value.start && sd.EndIndex == value.end)
{
return;
}

// TODO: we're passing twice to look for the start and end lines. Could easily be done in 1 pass
var startLine = GetRenderLineAt(GetRectForIndex(value.start).GetCenter().Y, true)?.index ?? 0;
var endLine = GetRenderLineAt(GetRectForIndex(value.end).GetCenter().Y, true)?.index ?? 0;
_selection = new SelectionDetails(startLine, value.start, endLine, value.end);
((IBlock)_collection.GetParent()).Invalidate(false);
var selection = new SelectionDetails(startLine, value.start, endLine, value.end);
if (selection != _selection)
{
_selection = selection;
((IBlock)_collection.GetParent()).Invalidate(false);
}
}
}

Expand Down

0 comments on commit 190a824

Please sign in to comment.