Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Markdig.Syntax;
using Markdig.Syntax.Inlines;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Automation;
using Microsoft.UI.Xaml.Controls;
using MarkdownRenderer.Layout;
using MarkdownRenderer.Layout.Boxes;
Expand Down Expand Up @@ -42,23 +43,16 @@ public sealed class TaskListItemRenderer : MarkdownNodeRenderer<ListItemBlock>

var marker = new InlineContainerBox(context, MarkdownElementKeys.ListMarker);
marker.BlockIndex = context.NextBlockIndex();
marker.Add(new InlineEmbedRun(20f, 20f, () => new CheckBox
{
IsChecked = isChecked,
IsEnabled = false,
MinWidth = 20,
MinHeight = 20,
Padding = new Thickness(0),
Margin = new Thickness(0),
HorizontalContentAlignment = HorizontalAlignment.Left,
VerticalContentAlignment = VerticalAlignment.Center,
})
marker.Add(new InlineEmbedRun(20f, 20f, () => CreateTaskCheckBox(isChecked))
{
ElementKey = MarkdownElementKeys.ListMarker,
SourceSpan = new MarkdownRenderer.SourceSpan(listItem.Span.Start, 0)
});

var content = new StackBox();
var content = new StackBox
{
FlowDirection = context.FlowDirection,
};
content.BlockIndex = context.NextBlockIndex();

foreach (var child in listItem)
Expand All @@ -69,7 +63,7 @@ public sealed class TaskListItemRenderer : MarkdownNodeRenderer<ListItemBlock>
contentBox.BlockIndex = context.NextBlockIndex();
// Skip the TaskList inline — it's the marker, not body content.
GfmChildBuilder.AddInlines(contentBox, p.Inline, skipFirstIf: i => i is TaskList);
content.Add(contentBox);
content.Add(contentBox);
}
else
{
Expand All @@ -78,6 +72,38 @@ public sealed class TaskListItemRenderer : MarkdownNodeRenderer<ListItemBlock>
}
}

return new ListItemBox(marker, content, markerWidth: 28f);
return new ListItemBox(marker, content, markerWidth: 28f)
{
FlowDirection = context.FlowDirection,
};
}

private static CheckBox CreateTaskCheckBox(bool isChecked)
{
var checkBox = new CheckBox
{
IsChecked = isChecked,
IsEnabled = true,
IsTabStop = true,
MinWidth = 20,
MinHeight = 20,
Padding = new Thickness(0),
Margin = new Thickness(0),
HorizontalContentAlignment = HorizontalAlignment.Left,
VerticalContentAlignment = VerticalAlignment.Center,
};

AutomationProperties.SetName(checkBox, isChecked ? "Completed task" : "Incomplete task");
AutomationProperties.SetHelpText(checkBox, "Read-only task checkbox");

void RestoreCheckedState(object sender, RoutedEventArgs e)
{
if (checkBox.IsChecked != isChecked)
checkBox.IsChecked = isChecked;
}

checkBox.Checked += RestoreCheckedState;
checkBox.Unchecked += RestoreCheckedState;
return checkBox;
}
}
1,175 changes: 1,100 additions & 75 deletions MarkdownRenderer/MarkdownRenderer.Sample.Automation/Program.cs

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions MarkdownRenderer/MarkdownRenderer.Sample/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Microsoft.UI.Xaml;

namespace MarkdownRenderer.Sample;
Expand All @@ -13,11 +14,9 @@ public App()

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
// Enable diagnostic logger by default in the sample app so any
// reproduction of the selection-shake bug captures per-frame paint
// coordinates to text_shaking2.log next to the repo root.
// Flip to false to silence.
MarkdownRenderer.Diagnostics.ShakeLogger.Enabled = true;
if (args.Arguments.Contains("--markdown-renderer-diagnostics", StringComparison.OrdinalIgnoreCase))
MarkdownRenderer.Diagnostics.ShakeLogger.Enabled = true;

_window = new MainWindow();
_window.Activate();
}
Expand Down
Loading
Loading