Skip to content

A Swiss Army knife for developers.

Merged PR 98: Added text diff

Etienne Baudoux1ffbb631cb1b
diff --git a/src/Directory.Build.props b/src/Directory.Build.props
index fd502b034..9f58428e6 100644
--- a/src/Directory.Build.props
+++ b/src/Directory.Build.props
@@ -40,7 +40,6 @@
<PropertyGroup>
<Nuget_ColorCodeUwp>2.0.9</Nuget_ColorCodeUwp>
<Nuget_DiffPlex>1.7.0</Nuget_DiffPlex>
- <Nuget_DirectN>1.9.1</Nuget_DirectN>
<NuGet_MicrosoftNETCoreUniversalWindowsPlatform>6.2.12</NuGet_MicrosoftNETCoreUniversalWindowsPlatform>
<NuGet_MicrosoftToolkitMvvm>7.0.2</NuGet_MicrosoftToolkitMvvm>
<Nuget_MicrosoftToolkitUwpUIBehaviors>7.0.2</Nuget_MicrosoftToolkitUwpUIBehaviors>
diff --git a/src/dev/def/DevTools.Core/Assumes.cs b/src/dev/def/DevTools.Core/Assumes.cs
index 29896f0c8..ff61a0879 100644
--- a/src/dev/def/DevTools.Core/Assumes.cs
+++ b/src/dev/def/DevTools.Core/Assumes.cs
@@ -27,5 +27,13 @@ namespace DevTools.Core
throw new NullReferenceException(argumentName);
}
}
+
+ public static void IsTrue(bool value, string argumentName)
+ {
+ if (!value)
+ {
+ throw new Exception($"'{argumentName}' is expected to be True");
+ }
+ }
}
}
diff --git a/src/dev/def/DevTools.Providers/IsFooterItemAttribute.cs b/src/dev/def/DevTools.Providers/IsFooterItemAttribute.cs
index 29a1f1073..bcee85426 100644
--- a/src/dev/def/DevTools.Providers/IsFooterItemAttribute.cs
+++ b/src/dev/def/DevTools.Providers/IsFooterItemAttribute.cs
@@ -10,6 +10,6 @@ namespace DevTools.Providers
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public sealed class IsFooterItemAttribute : Attribute
{
- public bool IsFooterItem { get; set; } = true;
+ public bool IsFooterItem { get; } = true;
}
}
diff --git a/src/dev/def/DevTools.Providers/NotScrollableAttribute.cs b/src/dev/def/DevTools.Providers/NotScrollableAttribute.cs
new file mode 100644
index 000000000..cdab8e3ea
--- /dev/null
+++ b/src/dev/def/DevTools.Providers/NotScrollableAttribute.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Composition;
+
+namespace DevTools.Providers
+{
+ /// <summary>
+ /// Indicates that the tool view can not be scrolled.
+ /// </summary>
+ [MetadataAttribute]
+ [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
+ public sealed class NotScrollableAttribute : Attribute
+ {
+ public bool NotScrollable { get; } = true;
+ }
+}
diff --git a/src/dev/def/DevTools.Providers/ToolProviderMetadata.cs b/src/dev/def/DevTools.Providers/ToolProviderMetadata.cs
index b889367bc..ae0888e2f 100644
--- a/src/dev/def/DevTools.Providers/ToolProviderMetadata.cs
+++ b/src/dev/def/DevTools.Providers/ToolProviderMetadata.cs
@@ -45,5 +45,11 @@ namespace DevTools.Providers
/// </remarks>
[DefaultValue(500)]
public int CompactOverlayWidth { get; set; }
+
+ /// <summary>
+ /// Gets or sets whether the tool view can be scrolled.
+ /// </summary>
+ [DefaultValue(false)]
+ public bool NotScrollable { get; set; }
}
}
diff --git a/src/dev/impl/DevTools.Common/DevTools.Common.csproj b/src/dev/impl/DevTools.Common/DevTools.Common.csproj
index 0b32b2a23..68b3a71ca 100644
--- a/src/dev/impl/DevTools.Common/DevTools.Common.csproj
+++ b/src/dev/impl/DevTools.Common/DevTools.Common.csproj
@@ -80,13 +80,23 @@
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
+ <Compile Include="UI\Controls\FormattedTextBlock\CustomDelimiterChunker.cs" />
+ <Compile Include="UI\Controls\FormattedTextBlock\CustomWordChunker.cs" />
+ <Compile Include="UI\Controls\FormattedTextBlock\FormattedTextBlock.xaml.cs">
+ <DependentUpon>FormattedTextBlock.xaml</DependentUpon>
+ </Compile>
+ <Compile Include="UI\Controls\FormattedTextBlock\IFormattedTextBlock.cs" />
<Compile Include="UI\Controls\TextEditor\CommandHandlerResult.cs" />
<Compile Include="UI\Controls\TextEditor\ICommandHandler.cs" />
<Compile Include="UI\Controls\TextEditor\IKeyboardCommand.cs" />
<Compile Include="UI\Controls\TextEditor\KeyboardCommand.cs" />
<Compile Include="UI\Controls\TextEditor\KeyboardCommandHandler.cs" />
+ <Compile Include="UI\Controls\TextEditor\RtfBuilder.cs" />
+ <Compile Include="UI\Controls\TextEditor\RtfFormat.cs" />
<Compile Include="UI\Controls\TextEditor\TextFormatter.cs" />
- <Compile Include="UI\Extensions\ColorHelper.cs" />
+ <Compile Include="UI\Converters\BooleanToScrollBarVisibilityConverter.cs" />
+ <Compile Include="UI\Converters\BooleanToScrollModeConverter.cs" />
+ <Compile Include="UI\Converters\BooleanToGridLengthConverter.cs" />
<Compile Include="UI\Controls\CustomPathIcon.cs" />
<Compile Include="UI\Controls\ExpandableSettingControl.xaml.cs">
<DependentUpon>ExpandableSettingControl.xaml</DependentUpon>
@@ -114,7 +124,6 @@
<ItemGroup>
<PackageReference Include="ColorCode.UWP" Version="$(Nuget_ColorCodeUwp)" />
<PackageReference Include="DiffPlex" Version="$(Nuget_DiffPlex)" />
- <PackageReference Include="DirectN" Version="$(Nuget_DirectN)" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="$(NuGet_MicrosoftNETCoreUniversalWindowsPlatform)" />
<PackageReference Include="Microsoft.Toolkit.Mvvm" Version="$(NuGet_MicrosoftToolkitMvvm)" />
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls" Version="$(Nuget_MicrosoftToolkitUwpUIControls)" />
@@ -143,6 +152,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
+ <Page Include="UI\Controls\FormattedTextBlock\FormattedTextBlock.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
</ItemGroup>
<ItemGroup>
<PRIResource Include="Strings\en\Base64EncoderDecoder.resw" />
@@ -172,7 +185,9 @@
<ItemGroup>
<Content Include="Assets\CascadiaMono.ttf" />
</ItemGroup>
- <ItemGroup />
+ <ItemGroup>
+ <PRIResource Include="Strings\en\TextDiff.resw" />
+ </ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
diff --git a/src/dev/impl/DevTools.Common/LanguageManager.cs b/src/dev/impl/DevTools.Common/LanguageManager.cs
index 37c76bdbe..35212546b 100644
--- a/src/dev/impl/DevTools.Common/LanguageManager.cs
+++ b/src/dev/impl/DevTools.Common/LanguageManager.cs
@@ -26,6 +26,7 @@ namespace DevTools.Common
private readonly JsonFormatterStrings _jsonformatter = new JsonFormatterStrings();
private readonly MainPageStrings _mainpage = new MainPageStrings();
private readonly SettingsStrings _settings = new SettingsStrings();
+ private readonly TextDiffStrings _textdiff = new TextDiffStrings();
/// <summary>
/// Gets an instance of <see cref="LanguageManager"/>.
@@ -62,6 +63,11 @@ namespace DevTools.Common
/// </summary>
public SettingsStrings Settings => _settings;
+ /// <summary>
+ /// Gets the <see cref="TextDiffStrings"/>.
+ /// </summary>
+ public TextDiffStrings TextDiff => _textdiff;
+
/// <summary>
/// Retrieves the current culture.
/// </summary>
@@ -282,4 +288,14 @@ namespace DevTools.Common
/// </summary>
public string WordWrap => _resources.GetString("WordWrap");
}
+
+ public class TextDiffStrings : ObservableObject
+ {
+ private readonly ResourceLoader _resources = ResourceLoader.GetForViewIndependentUse("DevTools.Common/TextDiff");
+
+ /// <summary>
+ /// Gets the resource DisplayName.
+ /// </summary>
+ public string DisplayName => _resources.GetString("DisplayName");
+ }
}
\ No newline at end of file
diff --git a/src/dev/impl/DevTools.Common/Strings/en/TextDiff.resw b/src/dev/impl/DevTools.Common/Strings/en/TextDiff.resw
new file mode 100644
index 000000000..8c7dcced1
--- /dev/null
+++ b/src/dev/impl/DevTools.Common/Strings/en/TextDiff.resw
@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <data name="DisplayName" xml:space="preserve">
+ <value>Text Diff</value>
+ </data>
+</root>
\ No newline at end of file
diff --git a/src/dev/impl/DevTools.Common/Themes/Custom.xaml b/src/dev/impl/DevTools.Common/Themes/Custom.xaml
index f194c220c..6395846c6 100644
--- a/src/dev/impl/DevTools.Common/Themes/Custom.xaml
+++ b/src/dev/impl/DevTools.Common/Themes/Custom.xaml
@@ -14,6 +14,7 @@
<x:String x:Key="Base64EncoderDecoderToolProvider">M 0.008 0.008 L 0.008 31.992 L 31.992 31.992 L 31.992 0.008 Z M 2.916 2.916 L 29.084 2.916 L 29.084 29.084 L 2.916 29.084 Z M 11.957 10.094 L 8.777 13.774 C 7.823 14.87 7.276 16.273 7.276 17.727 L 7.276 18.18 C 7.276 20.169 8.924 21.816 10.912 21.816 L 12.366 21.816 C 14.353 21.816 16 20.169 16 18.18 C 16 16.193 14.353 14.546 12.366 14.546 L 11.957 14.546 L 14.137 12.002 Z M 21.816 10.184 L 21.816 14.546 L 20.362 14.546 L 20.362 10.231 L 17.454 10.231 L 17.454 17.454 L 21.816 17.454 L 21.816 21.816 L 24.722 21.816 L 24.722 10.184 Z M 10.276 17.454 L 12.366 17.454 C 12.781 17.454 13.092 17.766 13.092 18.18 C 13.092 18.595 12.781 18.908 12.366 18.908 L 10.912 18.908 C 10.497 18.908 10.184 18.595 10.184 18.18 L 10.184 17.727 C 10.184 17.629 10.264 17.55 10.276 17.454 Z</x:String>
<x:String x:Key="JsonFormatterToolProvider">M 9.5703125 4 C 5.9553125 4 4.4385 5.3040312 4.4375 8.4570312 L 4.4375 10.648438 C 4.4375 12.498437 3.9412656 13.115234 2.4472656 13.115234 L 2.4472656 16.398438 C 3.9402656 16.398437 4.4375 17.014563 4.4375 18.851562 L 4.4375 21.435547 C 4.4375 24.660547 5.9673125 26 9.5703125 26 L 10.816406 26 L 10.816406 23.404297 L 10.283203 23.404297 C 8.3622031 23.404297 7.7460938 22.835328 7.7460938 20.986328 L 7.7460938 17.904297 C 7.7460938 16.091297 6.8912969 15.024141 5.2792969 14.869141 L 5.2792969 14.65625 C 6.9632969 14.50225 7.7460938 13.578656 7.7460938 11.847656 L 7.7460938 9.0371094 C 7.7460938 7.1761094 8.3512031 6.6074219 10.283203 6.6074219 L 10.816406 6.6074219 L 10.816406 4 L 9.5703125 4 z M 19.183594 4 L 19.183594 6.6074219 L 19.716797 6.6074219 C 21.648797 6.6074219 22.253906 7.1761094 22.253906 9.0371094 L 22.253906 11.847656 C 22.253906 13.577656 23.037703 14.50225 24.720703 14.65625 L 24.720703 14.871094 C 23.107703 15.025094 22.253906 16.090297 22.253906 17.904297 L 22.253906 20.986328 C 22.253906 22.835328 21.636797 23.404297 19.716797 23.404297 L 19.183594 23.404297 L 19.183594 26.001953 L 20.429688 26.001953 C 24.033688 26.001953 25.5625 24.6615 25.5625 21.4375 L 25.5625 18.853516 C 25.5625 17.015516 26.058734 16.398438 27.552734 16.398438 L 27.552734 13.115234 C 26.059734 13.115234 25.5625 12.499391 25.5625 10.650391 L 25.5625 8.4570312 C 25.5625 5.3040312 24.044687 4 20.429688 4 L 19.183594 4 z</x:String>
+ <x:String x:Key="TextDiffToolProvider">M 6 3 L 6 29 L 13 29 L 13 27 L 8 27 L 8 5 L 13 5 L 13 3 L 6 3 z M 15 3 L 15 5 L 17 5 L 17 3 L 15 3 z M 19 3 L 19 5 L 24 5 L 24 27 L 19 27 L 19 29 L 26 29 L 26 3 L 19 3 z M 15 7 L 15 9 L 17 9 L 17 7 L 15 7 z M 15 11 L 15 13 L 17 13 L 17 11 L 15 11 z M 15 15 L 15 17 L 17 17 L 17 15 L 15 15 z M 15 19 L 15 21 L 17 21 L 17 19 L 15 19 z M 15 23 L 15 25 L 17 25 L 17 23 L 15 23 z M 15 27 L 15 29 L 17 29 L 17 27 L 15 27 z</x:String>
<!-- From https://github.com/morning4coffe-dev/storylines -->
<Style x:Key="RightAlignedToggleSwitchStyle" TargetType="ToggleSwitch">
diff --git a/src/dev/impl/DevTools.Common/Themes/Generic.xaml b/src/dev/impl/DevTools.Common/Themes/Generic.xaml
index 1dedb74f4..32463e223 100644
--- a/src/dev/impl/DevTools.Common/Themes/Generic.xaml
+++ b/src/dev/impl/DevTools.Common/Themes/Generic.xaml
@@ -134,7 +134,7 @@
Background="{TemplateBinding Background}"
BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}"
- CornerRadius="{TemplateBinding CornerRadius}"
+ CornerRadius="4"
MinHeight="{ThemeResource TextControlThemeMinHeight}"
MinWidth="{ThemeResource TextControlThemeMinWidth}"
Grid.Row="1"/>
diff --git a/src/dev/impl/DevTools.Common/UI/Controls/ExpandableSettingControl.xaml b/src/dev/impl/DevTools.Common/UI/Controls/ExpandableSettingControl.xaml
index 6c2cabb51..430ad08b2 100644
--- a/src/dev/impl/DevTools.Common/UI/Controls/ExpandableSettingControl.xaml
+++ b/src/dev/impl/DevTools.Common/UI/Controls/ExpandableSettingControl.xaml
@@ -29,10 +29,15 @@
<Grid>
<!-- Use an Expander control if there is content to expand. -->
- <Grid x:Name="ExpanderGrid" x:Load="{x:Bind ExpandableContent, Mode=OneWay, Converter={StaticResource NullToFalseConverter}}">
+ <Grid
+ x:Name="ExpanderGrid"
+ x:Load="{x:Bind ExpandableContent, Mode=OneWay, Converter={StaticResource NullToFalseConverter}}">
<muxc:Expander
HorizontalAlignment="Stretch"
- HorizontalContentAlignment="Stretch">
+ HorizontalContentAlignment="Stretch"
+ VerticalAlignment="Stretch"
+ VerticalContentAlignment="Stretch"
+ IsExpanded="{x:Bind IsExpanded, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<muxc:Expander.Header>
<local:ExpandableSettingHeaderControl
Title="{x:Bind Title, Mode=OneWay}"
@@ -44,7 +49,6 @@
<ContentPresenter
HorizontalAlignment="Stretch"
- Margin="24,0,0,0"
Content="{x:Bind ExpandableContent, Mode=OneWay}" />
</muxc:Expander>
</Grid>
diff --git a/src/dev/impl/DevTools.Common/UI/Controls/ExpandableSettingControl.xaml.cs b/src/dev/impl/DevTools.Common/UI/Controls/ExpandableSettingControl.xaml.cs
index 2670291b0..dc6c4afa9 100644
--- a/src/dev/impl/DevTools.Common/UI/Controls/ExpandableSettingControl.xaml.cs
+++ b/src/dev/impl/DevTools.Common/UI/Controls/ExpandableSettingControl.xaml.cs
@@ -63,6 +63,19 @@ namespace DevTools.Common.UI.Controls
set => SetValue(ExpandableContentProperty, value);
}
+ public static readonly DependencyProperty IsExpandedProperty
+ = DependencyProperty.Register(
+ nameof(IsExpanded),
+ typeof(bool),
+ typeof(ExpandableSettingControl),
+ new PropertyMetadata(false));
+
+ public bool IsExpanded
+ {
+ get => (bool)GetValue(IsExpandedProperty);
+ set => SetValue(IsExpandedProperty, value);
+ }
+
public ExpandableSettingControl()
{
InitializeComponent();
diff --git a/src/dev/impl/DevTools.Common/UI/Controls/ExpandableSettingHeaderControl.xaml b/src/dev/impl/DevTools.Common/UI/Controls/ExpandableSettingHeaderControl.xaml
index e91f7515e..0519981cf 100644
--- a/src/dev/impl/DevTools.Common/UI/Controls/ExpandableSettingHeaderControl.xaml
+++ b/src/dev/impl/DevTools.Common/UI/Controls/ExpandableSettingHeaderControl.xaml
@@ -24,7 +24,8 @@
<Grid
x:Name="MainPanel"
HorizontalAlignment="Stretch"
- VerticalAlignment="Center">
+ VerticalAlignment="Center"
+ SizeChanged="MainPanel_SizeChanged">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
diff --git a/src/dev/impl/DevTools.Common/UI/Controls/FormattedTextBlock/CustomDelimiterChunker.cs b/src/dev/impl/DevTools.Common/UI/Controls/FormattedTextBlock/CustomDelimiterChunker.cs
new file mode 100644
index 000000000..5fa96d7b8
--- /dev/null
+++ b/src/dev/impl/DevTools.Common/UI/Controls/FormattedTextBlock/CustomDelimiterChunker.cs
@@ -0,0 +1,79 @@
+using DiffPlex;
+using System;
+using System.Collections.Generic;
+
+namespace DevTools.Common.UI.Controls.FormattedTextBlock
+{
+ public class CustomDelimiterChunker : IChunker
+ {
+ private readonly string[] delimiters;
+
+ public CustomDelimiterChunker(string[] delimiters)
+ {
+ if (delimiters is null || delimiters.Length == 0)
+ {
+ throw new ArgumentException($"{nameof(delimiters)} cannot be null or empty.", nameof(delimiters));
+ }
+
+ this.delimiters = delimiters;
+ }
+
+ public string[] Chunk(string str)
+ {
+ var list = new List<string>();
+ int begin = 0;
+ for (int i = 0; i < str.Length; i++)
+ {
+ var delimiterFound = IndexOfAnySubString(str, delimiters, i, out int delimiterLength);
+ if (delimiterFound != -1)
+ {
+ string word = str.Substring(begin, i - begin);
+ string delimiter = str.Substring(i, delimiterLength);
+
+ if (!string.IsNullOrEmpty(word))
+ {
+ list.Add(word);
+ }
+
+ if (!string.IsNullOrEmpty(delimiter))
+ {
+ list.Add(delimiter);
+ }
+
+ begin = i + delimiterLength;
+ i += delimiterLength - 1;
+ }
+ else if (i == str.Length - 1)
+ {
+ string lastWord = str.Substring(begin, str.Length - begin);
+
+ if (!string.IsNullOrEmpty(lastWord))
+ {
+ list.Add(lastWord);
+ }
+ }
+ }
+
+ return list.ToArray();
+ }
+
+ private int IndexOfAnySubString(string str, string[] delimiters, int startIndex, out int delimiterLength)
+ {
+ var bestMatch = -1;
+ delimiterLength = 0;
+
+ for (int i = 0; i < delimiters.Length; i++)
+ {
+ string delimiter = delimiters[i];
+ var index = str.IndexOf(delimiter, startIndex);
+ if (index == startIndex && delimiter.Length > delimiterLength)
+ {
+ bestMatch = index;
+ delimiterLength = delimiter.Length;
+ }
+ }
+
+ return bestMatch;
+ }
+ }
+}
diff --git a/src/dev/impl/DevTools.Common/UI/Controls/FormattedTextBlock/CustomWordChunker.cs b/src/dev/impl/DevTools.Common/UI/Controls/FormattedTextBlock/CustomWordChunker.cs
new file mode 100644
index 000000000..52a33f8b4
--- /dev/null
+++ b/src/dev/impl/DevTools.Common/UI/Controls/FormattedTextBlock/CustomWordChunker.cs
@@ -0,0 +1,35 @@
+#nullable enable
+
+namespace DevTools.Common.UI.Controls.FormattedTextBlock
+{
+ internal sealed class CustomWordChunker : CustomDelimiterChunker
+ {
+ private static string[] WordSeparaters { get; }
+ =
+ {
+ " ",
+ "\t",
+ "\r\n",
+ "\r",
+ "\n",
+ ".",
+ "(",
+ ")",
+ "{",
+ "}",
+ ",",
+ "!",
+ "?",
+ ";"
+ };
+
+ /// <summary>
+ /// Gets the default singleton instance of the chunker.
+ /// </summary>
+ public static CustomWordChunker Instance { get; } = new CustomWordChunker();
+
+ public CustomWordChunker() : base(WordSeparaters)
+ {
+ }
+ }
+}
diff --git a/src/dev/impl/DevTools.Common/UI/Controls/FormattedTextBlock/FormattedTextBlock.xaml b/src/dev/impl/DevTools.Common/UI/Controls/FormattedTextBlock/FormattedTextBlock.xaml
new file mode 100644
index 000000000..775a179a1
--- /dev/null
+++ b/src/dev/impl/DevTools.Common/UI/Controls/FormattedTextBlock/FormattedTextBlock.xaml
@@ -0,0 +1,117 @@
+<UserControl
+ x:Class="DevTools.Common.UI.Controls.FormattedTextBlock.FormattedTextBlock"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:local="using:DevTools.Common.UI.Controls.FormattedTextBlock"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ mc:Ignorable="d"
+ d:DesignHeight="300"
+ d:DesignWidth="400">
+
+ <Grid>
+ <VisualStateManager.VisualStateGroups>
+ <VisualStateGroup x:Name="CommonStates">
+ <VisualState x:Name="Disabled">
+ <Storyboard>
+ <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="Background">
+ <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBackgroundDisabled}"/>
+ </ObjectAnimationUsingKeyFrames>
+ <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="BorderBrush">
+ <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBorderBrushDisabled}"/>
+ </ObjectAnimationUsingKeyFrames>
+ <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" Storyboard.TargetProperty="Foreground">
+ <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlForegroundDisabled}"/>
+ </ObjectAnimationUsingKeyFrames>
+ </Storyboard>
+ </VisualState>
+ <VisualState x:Name="Normal"/>
+ <VisualState x:Name="PointerOver">
+ <Storyboard>
+ <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="BorderBrush">
+ <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBorderBrushPointerOver}"/>
+ </ObjectAnimationUsingKeyFrames>
+ <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="Background">
+ <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBackgroundPointerOver}"/>
+ </ObjectAnimationUsingKeyFrames>
+ <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" Storyboard.TargetProperty="Foreground">
+ <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlForegroundPointerOver}"/>
+ </ObjectAnimationUsingKeyFrames>
+ </Storyboard>
+ </VisualState>
+ <VisualState x:Name="Focused">
+ <Storyboard>
+ <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="Background">
+ <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBackgroundFocused}"/>
+ </ObjectAnimationUsingKeyFrames>
+ <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="BorderBrush">
+ <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBorderBrushFocused}"/>
+ </ObjectAnimationUsingKeyFrames>
+ <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" Storyboard.TargetProperty="Foreground">
+ <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlForegroundFocused}"/>
+ </ObjectAnimationUsingKeyFrames>
+ </Storyboard>
+ </VisualState>
+ </VisualStateGroup>
+ </VisualStateManager.VisualStateGroups>
+ <Border
+ x:Name="BorderElement"
+ Background="{ThemeResource TextControlBackground}"
+ BorderThickness="{ThemeResource TextControlBorderThemeThickness}"
+ BorderBrush="{ThemeResource TextControlBorderBrush}"
+ CornerRadius="4"
+ MinHeight="{ThemeResource TextControlThemeMinHeight}"
+ MinWidth="{ThemeResource TextControlThemeMinWidth}"/>
+ <ScrollViewer
+ x:Name="ContentElement"
+ AutomationProperties.AccessibilityView="Raw"
+ HorizontalScrollBarVisibility="Auto"
+ HorizontalScrollMode="Enabled"
+ VerticalScrollBarVisibility="Auto"
+ VerticalScrollMode="Enabled"
+ IsHorizontalRailEnabled="true"
+ IsVerticalRailEnabled="true"
+ IsDeferredScrollingEnabled="false"
+ IsTabStop="False"
+ Margin="{ThemeResource TextControlBorderThemeThickness}"
+ Padding="0"
+ ZoomMode="Disabled">
+ <Grid x:Name="RootGrid">
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition x:Name="LineNumberColumnDefinition" Width="Auto"/>
+ <ColumnDefinition x:Name="TextEditorColumnDefinition" Width="*"/>
+ </Grid.ColumnDefinitions>
+ <Canvas x:Name="LineHighlighterAndIndicatorCanvas" Grid.ColumnSpan="2">
+ <Border
+ x:Name="LineIndicator"
+ BorderBrush="{StaticResource SystemControlForegroundAccentBrush}"
+ Visibility="Collapsed"/>
+ <Grid
+ x:Name="LineHighlighter"
+ Background="{ThemeResource SystemControlBackgroundListLowBrush}"
+ Opacity="0.65"
+ BorderThickness="0"
+ Visibility="Collapsed"/>
+ </Canvas>
+ <StackPanel
+ x:Name="LineNumberGrid"
+ Grid.Column="0"
+ Orientation="Vertical"
+ HorizontalAlignment="Stretch"
+ BorderThickness="0,0,0,0"
+ BorderBrush="{ThemeResource SystemControlBackgroundTransparentRevealBorderBrush}"
+ Margin="0,3,0,0"
+ VerticalAlignment="Stretch">
+ </StackPanel>
+ <RichTextBlock
+ x:Name="RichTextBlock"
+ Grid.Column="1"
+ Padding="2,4,0,0"
+ LineHeight="18"
+ ManipulationMode="All"
+ HorizontalAlignment="Stretch"
+ VerticalAlignment="Stretch"/>
+ </Grid>
+ </ScrollViewer>
+ </Grid>
+</UserControl>
diff --git a/src/dev/impl/DevTools.Common/UI/Controls/FormattedTextBlock/FormattedTextBlock.xaml.cs b/src/dev/impl/DevTools.Common/UI/Controls/FormattedTextBlock/FormattedTextBlock.xaml.cs
new file mode 100644
index 000000000..f27453170
--- /dev/null
+++ b/src/dev/impl/DevTools.Common/UI/Controls/FormattedTextBlock/FormattedTextBlock.xaml.cs
@@ -0,0 +1,558 @@
+#nullable enable
+
+using ColorCode;
+using DevTools.Core;
+using DevTools.Core.Settings;
+using DiffPlex;
+using DiffPlex.Chunkers;
+using DiffPlex.DiffBuilder;
+using DiffPlex.DiffBuilder.Model;
+using Microsoft.Toolkit.Uwp.Helpers;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Windows.Foundation;
+using Windows.UI;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Documents;
+using Windows.UI.Xaml.Input;
+using Windows.UI.Xaml.Media;
+
+namespace DevTools.Common.UI.Controls.FormattedTextBlock
+{
+ public sealed partial class FormattedTextBlock : UserControl, IFormattedTextBlock
+ {
+ private readonly Dictionary<string, double> _miniRequisiteIntegerTextRenderingWidthCache = new();
+ private readonly SolidColorBrush _lineNumberDarkModeForegroundBrush = new("#99EEEEEE".ToColor());
+ private readonly SolidColorBrush _lineNumberLightModeForegroundBrush = new("#99000000".ToColor());
+
+ private bool _showLineNumbers;
+ private bool _highlightCurrentLine;
+ private bool _loaded;
+ private string? _document;
+
+ public static readonly DependencyProperty SettingsProviderProperty
+ = DependencyProperty.Register(
+ nameof(SettingsProvider),
+ typeof(ISettingsProvider),
+ typeof(FormattedTextBlock),
+ new PropertyMetadata(null, OnSettingsProviderPropertyChangedCallback));
+
+ public ISettingsProvider? SettingsProvider
+ {
+ get => (ISettingsProvider?)GetValue(SettingsProviderProperty);
+ set => SetValue(SettingsProviderProperty, value);
+ }
+
+ public FormattedTextBlock()
+ {
+ InitializeComponent();
+
+ RichTextBlock.Loaded += OnLoaded;
+ RichTextBlock.SelectionChanged += OnSelectionChanged;
+ RichTextBlock.SizeChanged += OnSizeChanged;
+ RichTextBlock.AddHandler(PointerPressedEvent, new PointerEventHandler(OnPointerPressed), true);
+ }
+
+ public void SetText(string? text, ILanguage? language = null)
+ {
+ _document = text;
+
+ RichTextBlock.Blocks.Clear();
+ RichTextBlock.TextHighlighters.Clear();
+
+ if (!string.IsNullOrEmpty(text))
+ {
+ var formatter = new RichTextBlockFormatter(ActualTheme);
+ formatter.FormatRichTextBlock(text, language, RichTextBlock);
+ }
+
+ ApplySettings();
+ }
+
+ public void SetInlineTextDiff(string? oldText, string? newText, bool lineDiff)
+ {
+ oldText ??= string.Empty;
+ newText ??= string.Empty;
+
+ var inlineDiffBuilder
+ = new InlineDiffBuilder(new Differ());
+
+ IChunker chunker;
+ if (lineDiff)
+ {
+ chunker = LineChunker.Instance;
+ }
+ else
+ {
+ chunker = CustomWordChunker.Instance;
+ }
+
+ DiffPaneModel diffPaneModel
+ = inlineDiffBuilder.BuildDiffModel(
+ oldText,
+ newText,
+ ignoreWhitespace: false,
+ ignoreCase: false,
+ chunker);
+
+ if (!diffPaneModel.HasDifferences)
+ {
+ _document = newText;
+ var p = new Paragraph();
+ var r = new Run()
+ {
+ Text = _document
+ };
+ p.Inlines.Add(r);
+ RichTextBlock.Blocks.Clear();
+ RichTextBlock.TextHighlighters.Clear();
+ RichTextBlock.Blocks.Add(p);
+ ApplySettings();
+ return;
+ }
+ else
+ {
+ _document = DiffPaneModelToString(diffPaneModel, lineDiff);
+ }
+
+ var insertedTextLength = 0;
+
+ var deletedHighlighter
+ = new TextHighlighter()
+ {
+ Background = new SolidColorBrush(Colors.Red)
+ };
+ var insertedHighlighter
+ = new TextHighlighter()
+ {
+ Background = new SolidColorBrush(Colors.Green)
+ };
+ var modifiedHighlighter
+ = new TextHighlighter()
+ {
+ Background = new SolidColorBrush(Colors.Yellow)
+ };
+
+ for (int i = 0; i < diffPaneModel.Lines.Count; i++)
+ {
+ DiffPiece diffPiece = diffPaneModel.Lines[i];
+
+ if (diffPiece.Type != ChangeType.Unchanged)
+ {
+ int startIndex = insertedTextLength;
+
+ var textRange
+ = new TextRange()
+ {
+ StartIndex = startIndex,
+ Length = diffPiece.Text.Length
+ };
+
+ if (diffPiece.Type == ChangeType.Inserted)
+ {
+ insertedHighlighter.Ranges.Add(textRange);
+ }
+ else if (diffPiece.Type == ChangeType.Deleted)
+ {
+ deletedHighlighter.Ranges.Add(textRange);
+ }
+ else if (diffPiece.Type == ChangeType.Modified)
+ {
+ modifiedHighlighter.Ranges.Add(textRange);
+ }
+ }
+
+ insertedTextLength += diffPiece.Text.Length;
+ if (lineDiff)
+ {
+ insertedTextLength += "\r\n".Length;
+ }
+ }
+
+ var documentParagraph = new Paragraph();
+ var run = new Run()
+ {
+ Text = _document
+ };
+ documentParagraph.Inlines.Add(run);
+ RichTextBlock.Blocks.Clear();
+ RichTextBlock.TextHighlighters.Clear();
+
+ RichTextBlock.TextHighlighters.Add(deletedHighlighter);
+ RichTextBlock.TextHighlighters.Add(insertedHighlighter);
+ RichTextBlock.TextHighlighters.Add(modifiedHighlighter);
+ RichTextBlock.Blocks.Add(documentParagraph);
+
+ ApplySettings();
+ }
+
+ protected override void OnApplyTemplate()
+ {
+ base.OnApplyTemplate();
+
+ ContentElement.ViewChanged += OnContentScrollViewerViewChanged;
+ ContentElement.SizeChanged += OnContentScrollViewerSizeChanged;
+ ContentElement.ApplyTemplate();
+
+ RootGrid.SizeChanged += OnRootGridSizeChanged;
+ }
+
+ private void ApplySettings()
+ {
+ ISettingsProvider? settingsProvider = SettingsProvider;
+ if (settingsProvider is not null)
+ {
+ RichTextBlock.FontFamily = (FontFamily)Application.Current.Resources[settingsProvider.GetSetting(PredefinedSettings.TextEditorFont)];
+ RichTextBlock.TextWrapping = settingsProvider.GetSetting(PredefinedSettings.TextEditorTextWrapping) ? TextWrapping.Wrap : TextWrapping.NoWrap;
+ _showLineNumbers = settingsProvider.GetSetting(PredefinedSettings.TextEditorLineNumbers);
+ _highlightCurrentLine = settingsProvider.GetSetting(PredefinedSettings.TextEditorHighlightCurrentLine);
+
+ UpdateLayout();
+
+ if (_showLineNumbers)
+ {
+ ShowLineNumbers();
+ }
+ else
+ {
+ HideLineNumbers();
+ }
+ }
+ }
+
+ private void ShowLineNumbers()
+ {
+ if (!_loaded)
+ {
+ return;
+ }
+
+ UpdateLineNumbersRendering();
+
+ // Call UpdateLineHighlighterAndIndicator to adjust it's state
+ UpdateLineHighlighterAndIndicator();
+ }
+
+ private void HideLineNumbers()
+ {
+ if (!_loaded)
+ {
+ return;
+ }
+
+ LineNumberGrid!.Children.Clear();
+ LineNumberGrid.BorderThickness = new Thickness(0, 0, 0, 0);
+ LineNumberGrid.Width = .0f;
+
+ // Call UpdateLineHighlighterAndIndicator to adjust it's state
+ // Since when line highlighter is disabled, we still show the line indicator when line numbers are showing
+ UpdateLineHighlighterAndIndicator();
+ }
+
+ private void UpdateLineNumbersRendering()
+ {
+ if (!_loaded || !_showLineNumbers)
+ {
+ return;
+ }
+
+ LineNumberGrid!.Children.Clear();
+
+ int lineCount = LineCount(_document);
+
+ double minLineNumberTextRenderingWidth
+ = CalculateMinimumRequisiteIntegerTextRenderingWidth(
+ RichTextBlock.FontFamily,
+ RichTextBlock.FontSize,
+ lineCount.ToString().Length);
+
+ double padding = RichTextBlock.FontSize / 2;
+ Thickness lineNumberPadding = new(padding, 0, padding + 2, 1);
+ //double lineHeight = RichTextBlock.LineHeight;
+ double lineHeight = GetTextSize(RichTextBlock.FontFamily, RichTextBlock.FontSize, "1").Height;
+ double lineNumberTextBlockHeight = lineHeight + RichTextBlock.Padding.Top + lineNumberPadding.Top;
+ SolidColorBrush? lineNumberForeground = (ActualTheme == ElementTheme.Dark) ? _lineNumberDarkModeForegroundBrush : _lineNumberLightModeForegroundBrush;
+
+ for (int i = 0; i < lineCount; i++)
+ {
+ int lineNumber = i + 1;
+
+ var margin
+ = new Thickness(
+ lineNumberPadding.Left,
+ lineNumberPadding.Top,
+ lineNumberPadding.Right,
+ lineNumberPadding.Bottom);
+
+ var lineNumberBlock = new TextBlock()
+ {
+ Text = lineNumber.ToString(),
+ // Height = lineNumberTextBlockHeight,
+ // Width = minLineNumberTextRenderingWidth,
+ Margin = margin,
+ TextAlignment = TextAlignment.Right,
+ HorizontalAlignment = HorizontalAlignment.Right,
+ VerticalAlignment = VerticalAlignment.Top,
+ HorizontalTextAlignment = TextAlignment.Right,
+ Foreground = lineNumberForeground,
+ FontFamily = RichTextBlock.FontFamily,
+ FontSize = RichTextBlock.FontSize
+ };
+
+ LineNumberGrid!.Children.Add(lineNumberBlock);
+ }
+
+ LineNumberGrid!.BorderThickness = new Thickness(0, 0, 0.08 * lineHeight, 0);
+ LineNumberGrid.Width = lineNumberPadding.Left + minLineNumberTextRenderingWidth + lineNumberPadding.Right;
+ }
+
+ private void UpdateLineHighlighterAndIndicator()
+ {
+ if (!_loaded)
+ {
+ return;
+ }
+
+ if (!_showLineNumbers && !_highlightCurrentLine)
+ {
+ LineHighlighter!.Visibility = Visibility.Collapsed;
+ LineIndicator!.Visibility = Visibility.Collapsed;
+ return;
+ }
+
+ TextPointer? anchorPoint = RichTextBlock.SelectionStart;
+ if (anchorPoint is null)
+ {
+ anchorPoint = RichTextBlock.ContentStart!;
+ Assumes.NotNull(anchorPoint, nameof(anchorPoint));
+ }
+
+ Rect selectionRect = anchorPoint.GetCharacterRect(anchorPoint.LogicalDirection);
+
+ double singleLineHeight = GetSingleLineHeight();
+ Thickness thickness = new Thickness(0.08 * singleLineHeight);
+ double height = selectionRect.Height;
+ bool selectedMultipleLines = RichTextBlock.SelectedText.IndexOfAny(new[] { '\n', '\r' }) > -1;
+
+ // Just to make sure height is a positive number and not smaller than single line height
+ if (height < singleLineHeight)
+ {
+ height = singleLineHeight;
+ }
+
+ // Show line highlighter rect when it is enabled when selection is single line only
+ if (_highlightCurrentLine && !selectedMultipleLines)
+ {
+ LineHighlighter!.Height = height;
+ LineHighlighter.Margin = new Thickness(0, selectionRect.Top, 0, 0);
+ LineHighlighter.Width = Math.Clamp(RootGrid!.ActualWidth, 0, double.PositiveInfinity);
+
+ LineHighlighter.Visibility = Visibility.Visible;
+ }
+ else
+ {
+ LineHighlighter!.Visibility = Visibility.Collapsed;
+ }
+
+ // Show line indicator when line numbers are enabled and when selection is single line only
+ if (_showLineNumbers && !selectedMultipleLines)
+ {
+ LineIndicator!.Height = height;
+ LineIndicator.Margin = new Thickness(0, selectionRect.Top, 0, 0);
+ LineIndicator.BorderThickness = thickness;
+ LineIndicator.Width = 0.1 * singleLineHeight;
+
+ LineIndicator.Visibility = Visibility.Visible;
+ }
+ else
+ {
+ LineIndicator!.Visibility = Visibility.Collapsed;
+ }
+ }
+
+ private double GetSingleLineHeight()
+ {
+ Rect rect = RichTextBlock.ContentStart.GetCharacterRect(LogicalDirection.Forward);
+ return rect.Height <= 0 ? 1.35 * FontSize : rect.Height;
+ }
+
+ private void ResetRootGridClipping()
+ {
+ if (!_loaded || RootGrid is null)
+ {
+ return;
+ }
+
+ //RootGrid!.Clip = new RectangleGeometry
+ //{
+ // Rect = new Rect(
+ // 0,
+ // 0,
+ // RootGrid.ActualWidth,
+ // Math.Clamp(RootGrid.ActualHeight, .0f, double.PositiveInfinity))
+ //};
+ }
+
+ /// <summary>
+ /// Get minimum rendering width needed for displaying number text with certain length.
+ /// Take length of 3 as example, it is going to iterate thru all possible combinations like:
+ /// 111, 222, 333, 444 ... 999 to get minimum rendering length needed to display all of them (the largest width is the min here).
+ /// For mono font text, the width is always the same for same length but for non-mono font text, it depends.
+ /// Thus we need to calculate here to determine width needed for rendering integer number only text.
+ /// </summary>
+ /// <param name="fontFamily"></param>
+ /// <param name="fontSize"></param>
+ /// <param name="numberTextLength"></param>
+ /// <returns></returns>
+ private double CalculateMinimumRequisiteIntegerTextRenderingWidth(FontFamily fontFamily, double fontSize, int numberTextLength)
+ {
+ string? cacheKey = $"{fontFamily.Source}-{(int)fontSize}-{numberTextLength}";
+
+ if (_miniRequisiteIntegerTextRenderingWidthCache.ContainsKey(cacheKey))
+ {
+ return _miniRequisiteIntegerTextRenderingWidthCache[cacheKey];
+ }
+
+ double minRequisiteWidth = 0;
+
+ for (int i = 0; i < 10; i++)
+ {
+ string? str = new((char)('0' + i), numberTextLength);
+ double width = GetTextSize(fontFamily, fontSize, str).Width;
+ if (width > minRequisiteWidth)
+ {
+ minRequisiteWidth = width;
+ }
+ }
+
+ _miniRequisiteIntegerTextRenderingWidthCache[cacheKey] = minRequisiteWidth;
+ return minRequisiteWidth;
+ }
+
+ private void OnLoaded(object sender, RoutedEventArgs e)
+ {
+ _loaded = true;
+
+ ResetRootGridClipping();
+
+ UpdateLineHighlighterAndIndicator();
+ if (_showLineNumbers)
+ {
+ ShowLineNumbers();
+ }
+ }
+
+ private void OnSelectionChanged(object sender, RoutedEventArgs _)
+ {
+ UpdateLineHighlighterAndIndicator();
+ }
+
+ private void OnSizeChanged(object sender, SizeChangedEventArgs _)
+ {
+ UpdateLineHighlighterAndIndicator();
+ }
+
+ private void OnContentScrollViewerViewChanged(object sender, ScrollViewerViewChangedEventArgs _)
+ {
+ UpdateLineNumbersRendering();
+ }
+
+ private void OnContentScrollViewerSizeChanged(object sender, SizeChangedEventArgs _)
+ {
+ UpdateLineNumbersRendering();
+ }
+
+ private void OnPointerPressed(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
+ {
+ var point = RichTextBlock.GetPositionFromPoint(e.GetCurrentPoint(RichTextBlock).Position);
+ RichTextBlock.Select(point, point);
+ UpdateLineHighlighterAndIndicator();
+ }
+
+ private void SettingProvider_SettingChanged(object sender, SettingChangedEventArgs e)
+ {
+ ApplySettings();
+ }
+
+ private void OnRootGridSizeChanged(object sender, SizeChangedEventArgs _)
+ {
+ ResetRootGridClipping();
+ }
+
+ private static void OnSettingsProviderPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ ISettingsProvider? settingProvider = e.NewValue as ISettingsProvider;
+ if (settingProvider is not null)
+ {
+ var textEditorCore = (FormattedTextBlock)d;
+ settingProvider.SettingChanged += textEditorCore.SettingProvider_SettingChanged;
+ textEditorCore.ApplySettings();
+ }
+ }
+
+ private static Size GetTextSize(FontFamily font, double fontSize, string text)
+ {
+ var textBlock = new TextBlock
+ {
+ Text = text,
+ FontFamily = font,
+ FontSize = fontSize
+ };
+ textBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
+ return textBlock.DesiredSize;
+ }
+
+ private static int LineCount(string? text)
+ {
+ if (string.IsNullOrEmpty(text))
+ {
+ return 1;
+ }
+
+ int count = 1;
+ int len = text!.Length;
+ for (int i = 0; i != len; ++i)
+ {
+ switch (text[i])
+ {
+ case '\r':
+ ++count;
+ if (i + 1 != len && text[i + 1] == '\n')
+ {
+ ++i;
+ }
+ break;
+
+ case '\n':
+ // case '\v':
+ // case '\f':
+ // case '\u0085':
+ // case '\u2028':
+ // case '\u2029':
+ ++count;
+ break;
+ }
+ }
+
+ return count;
+ }
+
+ private static string DiffPaneModelToString(DiffPaneModel diffPaneModel, bool lineDiff)
+ {
+ var stringBuilder = new StringBuilder();
+
+ for (int i = 0; i < diffPaneModel.Lines.Count; i++)
+ {
+ stringBuilder.Append(diffPaneModel.Lines[i].Text);
+ if (lineDiff)
+ {
+ stringBuilder.Append("\r\n");
+ }
+ }
+
+ return stringBuilder.ToString();
+ }
+ }
+}
diff --git a/src/dev/impl/DevTools.Common/UI/Controls/FormattedTextBlock/IFormattedTextBlock.cs b/src/dev/impl/DevTools.Common/UI/Controls/FormattedTextBlock/IFormattedTextBlock.cs
new file mode 100644
index 000000000..178333942
--- /dev/null
+++ b/src/dev/impl/DevTools.Common/UI/Controls/FormattedTextBlock/IFormattedTextBlock.cs
@@ -0,0 +1,13 @@
+#nullable enable
+
+using ColorCode;
+
+namespace DevTools.Common.UI.Controls.FormattedTextBlock
+{
+ public interface IFormattedTextBlock
+ {
+ void SetText(string? text, ILanguage? language = null);
+
+ void SetInlineTextDiff(string? oldText, string? newText, bool lineDiff);
+ }
+}
diff --git a/src/dev/impl/DevTools.Common/UI/Controls/TextEditor/RtfBuilder.cs b/src/dev/impl/DevTools.Common/UI/Controls/TextEditor/RtfBuilder.cs
new file mode 100644
index 000000000..f6fd7c0af
--- /dev/null
+++ b/src/dev/impl/DevTools.Common/UI/Controls/TextEditor/RtfBuilder.cs
@@ -0,0 +1,270 @@
+#nullable enable
+
+using System.Collections.Generic;
+using System.Text;
+using Windows.UI;
+using Windows.UI.Xaml;
+
+namespace DevTools.Common.UI.Controls.TextEditor
+{
+ internal sealed class RtfBuilder
+ {
+ private Dictionary<Color, int> colorNbs;
+ private Dictionary<string, int> fontNbs;
+
+ private StringBuilder sbColorTbl;
+ private StringBuilder sbFontTbl;
+ private StringBuilder sbText;
+
+ private string defaultFontName;
+
+ public RtfBuilder(ElementTheme theme, string fontName)
+ {
+ colorNbs = new Dictionary<Color, int>();
+ fontNbs = new Dictionary<string, int>();
+
+ sbColorTbl = new StringBuilder();
+ sbFontTbl = new StringBuilder();
+ sbText = new StringBuilder();
+
+ defaultFontName = fontName;
+ }
+
+ public string DefaultFontName
+ {
+ get
+ {
+ return defaultFontName;
+ }
+
+ set
+ {
+ defaultFontName = value;
+ }
+ }
+
+ public void Append(string text, RtfFormat format, Color? color, Color? backgroundColor)
+ {
+ AppendIntern(text, format, color, backgroundColor, true, null, false);
+ }
+
+ public void Clear()
+ {
+ colorNbs.Clear();
+ fontNbs.Clear();
+
+ sbColorTbl.Clear();
+ sbFontTbl.Clear();
+
+ sbText.Clear();
+
+ AddFont(DefaultFontName);
+ }
+
+ public string GetRtf()
+ {
+ StringBuilder result = new StringBuilder();
+
+ //header
+ result.Append(@"{\rtf1\ansi\ansicpg1252\deff0\deflang1031");
+
+ //font table
+ result.Append(@"{\fonttbl");
+ //defaultFont
+ result.Append(FontToRtf(defaultFontName, 0));
+ //user fonts
+ if (fontNbs.Count > 0)
+ {
+ result.Append(sbFontTbl.ToString());
+ }
+ result.Append("}");
+
+ //color table
+ result.Append(@"{\colortbl;");
+ //user colors
+ if (colorNbs.Count > 0)
+ {
+ result.Append(sbColorTbl.ToString());
+ }
+ result.Append("}");
+
+ //text
+ result.Append(sbText.ToString());
+
+ //headerclose
+ result.Append("}");
+
+ return result.ToString();
+ }
+
+ public override string ToString()
+ {
+ return GetRtf();
+ }
+
+ private string EscapeText(string text)
+ {
+ if (string.IsNullOrEmpty(text))
+ {
+ return string.Empty;
+ }
+ else
+ {
+ text = text.Replace(@"\", @"\\");
+ text = text.Replace(@"{", @"\{");
+ text = text.Replace(@"}", @"\}");
+ text = text.Replace("\r\n", @"\par ");
+
+ return text;
+ }
+ }
+
+ private int AddColor(Color? color)
+ {
+ if (!color.HasValue)
+ {
+ //Default Font
+ return 0;
+ }
+ else
+ {
+ if (colorNbs.ContainsKey(color.Value))
+ {
+ // Font exists already in Fonttable
+ return colorNbs[color.Value];
+ }
+ else
+ {
+ //New Font
+ int nb = colorNbs.Count + 2;
+
+ colorNbs.Add(color.Value, nb);
+ sbColorTbl.AppendFormat(ColorToRtf(color.Value));
+
+ return nb;
+ }
+ }
+ }
+
+ private int AddFont(string font)
+ {
+ if (defaultFontName == font)
+ {
+ //Default Font
+ return 0;
+ }
+ else
+ {
+ if (fontNbs.ContainsKey(font))
+ {
+ //Font exists alread in font table
+ return fontNbs[font];
+ }
+ else
+ {
+ //new font
+ int fontNb = fontNbs.Count + 1;
+
+ sbFontTbl.Append(FontToRtf(font, fontNb));
+ fontNbs.Add(font, fontNb);
+
+ return fontNb;
+ }
+ }
+ }
+
+ private string ColorToRtf(Color color)
+ {
+ return string.Format(@"\red{0}\green{1}\blue{2};",
+ color.R, color.G, color.B);
+ }
+
+ private string FontToRtf(string font, int nb)
+ {
+ return string.Format(@"{{\f{1}\fnil\fcharset0 {0}}}", font, nb);
+ }
+
+ private void AppendIntern(string text, RtfFormat format, Color? color, Color? backgroundColor, bool useColor, string font, bool newLine)
+ {
+ //get color nb
+ int colorNb = 1;
+ if (useColor)
+ {
+ colorNb = AddColor(color);
+ }
+
+ int backgroundColorNb = 0;
+ if (useColor)
+ {
+ backgroundColorNb = AddColor(backgroundColor);
+ }
+
+ //get font
+ int fontNb = 0;
+ if (font != null)
+ {
+ fontNb = AddFont(font);
+ }
+
+ //set formats
+ if ((format & RtfFormat.Bold) == RtfFormat.Bold)
+ {
+ sbText.Append(@"\b");
+ }
+ if ((format & RtfFormat.Italic) == RtfFormat.Italic)
+ {
+ sbText.Append(@"\i");
+ }
+ if ((format & RtfFormat.Underline) == RtfFormat.Underline)
+ {
+ sbText.Append(@"\ul");
+ }
+ if ((format & RtfFormat.Strikeout) == RtfFormat.Strikeout)
+ {
+ sbText.Append(@"\strike");
+ }
+
+ //set color
+ sbText.AppendFormat(@"\cf{0}", colorNb);
+
+ //set background color
+ sbText.AppendFormat(@"\highlight{0}", backgroundColorNb);
+
+ //set font
+ sbText.AppendFormat(@"\f{0}", fontNb);
+
+ //add text
+ sbText.Append(EscapeText(text));
+
+ //restore to default color
+ sbText.Append(@"\cf1");
+
+ //restore to default font
+ sbText.Append(@"\f0");
+
+ //remove formats
+ if ((format & RtfFormat.Bold) == RtfFormat.Bold)
+ {
+ sbText.Append(@"\b0");
+ }
+ if ((format & RtfFormat.Italic) == RtfFormat.Italic)
+ {
+ sbText.Append(@"\i0");
+ }
+ if ((format & RtfFormat.Underline) == RtfFormat.Underline)
+ {
+ sbText.Append(@"\ul0");
+ }
+ if ((format & RtfFormat.Strikeout) == RtfFormat.Strikeout)
+ {
+ sbText.Append(@"\strike0");
+ }
+
+ //insert new line
+ if (newLine)
+ {
+ sbText.Append(@"\par ");
+ }
+ }
+ }
+}
diff --git a/src/dev/impl/DevTools.Common/UI/Controls/TextEditor/RtfFormat.cs b/src/dev/impl/DevTools.Common/UI/Controls/TextEditor/RtfFormat.cs
new file mode 100644
index 000000000..78d615a3b
--- /dev/null
+++ b/src/dev/impl/DevTools.Common/UI/Controls/TextEditor/RtfFormat.cs
@@ -0,0 +1,16 @@
+#nullable enable
+
+using System;
+
+namespace DevTools.Common.UI.Controls.TextEditor
+{
+ [Flags]
+ public enum RtfFormat
+ {
+ Normal = 0,
+ Bold = 1,
+ Italic = 2,
+ Underline = 4,
+ Strikeout = 8
+ }
+}
diff --git a/src/dev/impl/DevTools.Common/UI/Controls/TextEditor/TextEditor.cs b/src/dev/impl/DevTools.Common/UI/Controls/TextEditor/TextEditor.cs
index 256f4d731..c7345a08b 100644
--- a/src/dev/impl/DevTools.Common/UI/Controls/TextEditor/TextEditor.cs
+++ b/src/dev/impl/DevTools.Common/UI/Controls/TextEditor/TextEditor.cs
@@ -4,7 +4,9 @@ using DevTools.Common.UI.Extensions;
using DevTools.Core;
using DevTools.Core.Settings;
using DevTools.Core.Threading;
+using DiffPlex.DiffBuilder;
using Microsoft.Toolkit.Mvvm.Input;
+using Microsoft.Toolkit.Uwp.Helpers;
using System;
using System.Collections.Generic;
using System.Threading;
@@ -41,6 +43,7 @@ namespace DevTools.Common.UI.Controls.TextEditor
private const string RichEditBoxDefaultLineEnding = "\r\n";
+ private readonly InlineDiffBuilder _inlineDiffBuilder = new InlineDiffBuilder();
private readonly IList<TextBlock> _renderedLineNumberBlocks = new List<TextBlock>();
private readonly Dictionary<string, double> _miniRequisiteIntegerTextRenderingWidthCache = new();
private readonly SolidColorBrush _lineNumberDarkModeForegroundBrush = new("#99EEEEEE".ToColor());
@@ -59,6 +62,7 @@ namespace DevTools.Common.UI.Controls.TextEditor
private bool _showLineNumbers;
private bool _highlightCurrentLine;
private bool _loaded;
+ private bool _isTextPendingUpdate;
private bool _isDocumentLinesCachePendingUpdate = true;
private bool _isSyntaxColorizationPendingUpdate = true;
private bool _isSyntaxColorizationUpdateInProgress;
@@ -986,6 +990,13 @@ namespace DevTools.Common.UI.Controls.TextEditor
Document.GetText(TextGetOptions.UseCrlf, out var document);
_document = document;
+ if (!_isTextPendingUpdate)
+ {
+ _isTextPendingUpdate = true;
+ Text = document;
+ _isTextPendingUpdate = false;
+ }
+
_isDocumentLinesCachePendingUpdate = true;
_isSyntaxColorizationPendingUpdate = true;
}
@@ -1017,10 +1028,16 @@ namespace DevTools.Common.UI.Controls.TextEditor
string? text = e.NewValue as string;
var textEditorCore = (TextEditor)d;
- bool isReadOnly = textEditorCore.IsReadOnly;
- textEditorCore.IsReadOnly = false;
- textEditorCore.Document.SetText(TextSetOptions.None, text);
- textEditorCore.IsReadOnly = isReadOnly;
+
+ if (!textEditorCore._isTextPendingUpdate)
+ {
+ textEditorCore._isTextPendingUpdate = true;
+ bool isReadOnly = textEditorCore.IsReadOnly;
+ textEditorCore.IsReadOnly = false;
+ textEditorCore.Document.SetText(TextSetOptions.None, text ?? string.Empty);
+ textEditorCore.IsReadOnly = isReadOnly;
+ textEditorCore._isTextPendingUpdate = false;
+ }
}
private static Size GetTextSize(FontFamily font, double fontSize, string text)
diff --git a/src/dev/impl/DevTools.Common/UI/Controls/TextEditor/TextFormatter.cs b/src/dev/impl/DevTools.Common/UI/Controls/TextEditor/TextFormatter.cs
index cde14b80c..df3131e4a 100644
--- a/src/dev/impl/DevTools.Common/UI/Controls/TextEditor/TextFormatter.cs
+++ b/src/dev/impl/DevTools.Common/UI/Controls/TextEditor/TextFormatter.cs
@@ -6,13 +6,13 @@ using ColorCode.Parsing;
using ColorCode.Styling;
using DevTools.Common.UI.Extensions;
using DevTools.Core.Threading;
+using Microsoft.Toolkit.Uwp.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
-using Windows.UI;
using Windows.UI.Text;
using Windows.UI.Xaml;
diff --git a/src/dev/impl/DevTools.Common/UI/Converters/BooleanToGridLengthConverter.cs b/src/dev/impl/DevTools.Common/UI/Converters/BooleanToGridLengthConverter.cs
new file mode 100644
index 000000000..d36c0c3cf
--- /dev/null
+++ b/src/dev/impl/DevTools.Common/UI/Converters/BooleanToGridLengthConverter.cs
@@ -0,0 +1,40 @@
+#nullable enable
+
+using System;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Data;
+
+namespace DevTools.Common.UI.Converters
+{
+ /// <summary>
+ /// Convert a <see cref="bool"/> to a <see cref="GridLength"/> value.
+ /// </summary>
+ public sealed class BooleanToGridLengthConverter : IValueConverter
+ {
+ /// <summary>
+ /// Gets or sets the grid length to apply when the input is true.
+ /// </summary>
+ public GridLength GridLengthOnTrue { get; set; }
+
+ /// <summary>
+ /// Gets or sets the grid length to apply when the input is false.
+ /// </summary>
+ public GridLength GridLengthOnFalse { get; set; }
+
+ public object Convert(object value, Type targetType, object parameter, string language)
+ {
+ var valueBool = value as bool?;
+ if (valueBool == null)
+ {
+ return DependencyProperty.UnsetValue;
+ }
+
+ return valueBool.Value ? GridLengthOnTrue : GridLengthOnFalse;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, string language)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/src/dev/impl/DevTools.Common/UI/Converters/BooleanToScrollBarVisibilityConverter.cs b/src/dev/impl/DevTools.Common/UI/Converters/BooleanToScrollBarVisibilityConverter.cs
new file mode 100644
index 000000000..2025f00a2
--- /dev/null
+++ b/src/dev/impl/DevTools.Common/UI/Converters/BooleanToScrollBarVisibilityConverter.cs
@@ -0,0 +1,41 @@
+#nullable enable
+
+using System;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Data;
+
+namespace DevTools.Common.UI.Converters
+{
+ /// <summary>
+ /// Convert a <see cref="bool"/> to a <see cref="ScrollBarVisibility"/> value.
+ /// </summary>
+ public sealed class BooleanToScrollBarVisibilityConverter : IValueConverter
+ {
+ /// <summary>
+ /// Gets or sets the scroll bar visibility to apply when the input is true.
+ /// </summary>
+ public ScrollBarVisibility ScrollBarVisibilityOnTrue { get; set; }
+
+ /// <summary>
+ /// Gets or sets the scroll bar visibility to apply when the input is false.
+ /// </summary>
+ public ScrollBarVisibility ScrollBarVisibilityOnFalse { get; set; }
+
+ public object Convert(object value, Type targetType, object parameter, string language)
+ {
+ var valueBool = value as bool?;
+ if (valueBool == null)
+ {
+ return DependencyProperty.UnsetValue;
+ }
+
+ return valueBool.Value ? ScrollBarVisibilityOnTrue : ScrollBarVisibilityOnFalse;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, string language)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/src/dev/impl/DevTools.Common/UI/Converters/BooleanToScrollModeConverter.cs b/src/dev/impl/DevTools.Common/UI/Converters/BooleanToScrollModeConverter.cs
new file mode 100644
index 000000000..66be77ebc
--- /dev/null
+++ b/src/dev/impl/DevTools.Common/UI/Converters/BooleanToScrollModeConverter.cs
@@ -0,0 +1,41 @@
+#nullable enable
+
+using System;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Data;
+
+namespace DevTools.Common.UI.Converters
+{
+ /// <summary>
+ /// Convert a <see cref="bool"/> to a <see cref="ScrollMode"/> value.
+ /// </summary>
+ public sealed class BooleanToScrollModeConverter : IValueConverter
+ {
+ /// <summary>
+ /// Gets or sets the scroll mode to apply when the input is true.
+ /// </summary>
+ public ScrollMode ScrollModeOnTrue { get; set; }
+
+ /// <summary>
+ /// Gets or sets the scroll mode to apply when the input is false.
+ /// </summary>
+ public ScrollMode ScrollModeOnFalse { get; set; }
+
+ public object Convert(object value, Type targetType, object parameter, string language)
+ {
+ var valueBool = value as bool?;
+ if (valueBool == null)
+ {
+ return DependencyProperty.UnsetValue;
+ }
+
+ return valueBool.Value ? ScrollModeOnTrue : ScrollModeOnFalse;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, string language)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/src/dev/impl/DevTools.Common/UI/Extensions/ColorHelper.cs b/src/dev/impl/DevTools.Common/UI/Extensions/ColorHelper.cs
deleted file mode 100644
index 09a1ba725..000000000
--- a/src/dev/impl/DevTools.Common/UI/Extensions/ColorHelper.cs
+++ /dev/null
@@ -1,103 +0,0 @@
-#nullable enable
-
-using DevTools.Core;
-using System;
-using System.Reflection;
-using Windows.UI;
-
-namespace DevTools.Common.UI.Extensions
-{
- internal static class ColorHelper
- {
- /// <summary>
- /// Creates a <see cref="Windows.UI.Color"/> from a XAML color <see cref="string"/>. Any format used in XAML should work.
- /// </summary>
- /// <param name="colorString">The XAML color string.</param>
- /// <returns>The created <see cref="Windows.UI.Color"/>.</returns>
- public static Color ToColor(this string colorString)
- {
- Arguments.NotNullOrEmpty(colorString, nameof(colorString));
-
- if (colorString[0] == '#')
- {
- switch (colorString.Length)
- {
- case 9:
- {
- uint num4 = Convert.ToUInt32(colorString.Substring(1), 16);
- byte a = (byte)(num4 >> 24);
- byte r2 = (byte)((num4 >> 16) & 0xFF);
- byte g2 = (byte)((num4 >> 8) & 0xFF);
- byte b9 = (byte)(num4 & 0xFF);
- return Color.FromArgb(a, r2, g2, b9);
- }
- case 7:
- {
- uint num3 = Convert.ToUInt32(colorString.Substring(1), 16);
- byte r = (byte)((num3 >> 16) & 0xFF);
- byte g = (byte)((num3 >> 8) & 0xFF);
- byte b8 = (byte)(num3 & 0xFF);
- return Color.FromArgb(byte.MaxValue, r, g, b8);
- }
- case 5:
- {
- ushort num2 = Convert.ToUInt16(colorString.Substring(1), 16);
- byte b4 = (byte)(num2 >> 12);
- byte b5 = (byte)((num2 >> 8) & 0xF);
- byte b6 = (byte)((num2 >> 4) & 0xF);
- byte b7 = (byte)(num2 & 0xF);
- b4 = (byte)((b4 << 4) | b4);
- b5 = (byte)((b5 << 4) | b5);
- b6 = (byte)((b6 << 4) | b6);
- b7 = (byte)((b7 << 4) | b7);
- return Color.FromArgb(b4, b5, b6, b7);
- }
- case 4:
- {
- ushort num = Convert.ToUInt16(colorString.Substring(1), 16);
- byte b = (byte)((num >> 8) & 0xF);
- byte b2 = (byte)((num >> 4) & 0xF);
- byte b3 = (byte)(num & 0xF);
- b = (byte)((b << 4) | b);
- b2 = (byte)((b2 << 4) | b2);
- b3 = (byte)((b3 << 4) | b3);
- return Color.FromArgb(byte.MaxValue, b, b2, b3);
- }
- default:
- throw new FormatException($"The {colorString} string passed in the colorString argument is not a recognized Color format.");
- }
- }
-
- if (colorString.Length > 3 && colorString[0] == 's' && colorString[1] == 'c' && colorString[2] == '#')
- {
- string[] array = colorString.Split(',');
- if (array.Length == 4)
- {
- double num5 = double.Parse(array[0].Substring(3));
- double num6 = double.Parse(array[1]);
- double num7 = double.Parse(array[2]);
- double num8 = double.Parse(array[3]);
- return Color.FromArgb((byte)(num5 * 255.0), (byte)(num6 * 255.0), (byte)(num7 * 255.0), (byte)(num8 * 255.0));
- }
-
- if (array.Length == 3)
- {
- double num9 = double.Parse(array[0].Substring(3));
- double num10 = double.Parse(array[1]);
- double num11 = double.Parse(array[2]);
- return Color.FromArgb(byte.MaxValue, (byte)(num9 * 255.0), (byte)(num10 * 255.0), (byte)(num11 * 255.0));
- }
-
- throw new FormatException($"The {colorString} string passed in the colorString argument is not a recognized Color format (sc#[scA,]scR,scG,scB).");
- }
-
- PropertyInfo declaredProperty = typeof(Colors).GetTypeInfo().GetDeclaredProperty(colorString);
- if (declaredProperty != null)
- {
- return (Color)declaredProperty.GetValue(null);
- }
-
- throw new FormatException($"The {colorString} string passed in the colorString argument is not a recognized Color.");
- }
- }
-}
diff --git a/src/dev/impl/DevTools.Impl/Views/MainPage.xaml b/src/dev/impl/DevTools.Impl/Views/MainPage.xaml
index b0220072f..14cbed3e4 100644
--- a/src/dev/impl/DevTools.Impl/Views/MainPage.xaml
+++ b/src/dev/impl/DevTools.Impl/Views/MainPage.xaml
@@ -22,6 +22,8 @@
<converters:BooleanToVisibilityConverter x:Key="InvertedBooleanToVisibilityConverter" IsInverted="True"/>
<converters:InvertedBooleanConverter x:Key="InvertedBooleanConverter"/>
<converters:EnumToThicknessConverter x:Key="NavigationViewItemMarginConverter" ThicknessOnEnumDetected="0" ThicknessOnEnumNotDetected="12,0,12,0"/>
+ <converters:BooleanToScrollModeConverter x:Key="BooleanToScrollModeConverter" ScrollModeOnTrue="Disabled" ScrollModeOnFalse="Enabled"/>
+ <converters:BooleanToScrollBarVisibilityConverter x:Key="BooleanToScrollBarVisibilityConverter" ScrollBarVisibilityOnTrue="Disabled" ScrollBarVisibilityOnFalse="Auto"/>
<!--This top margin is the height of the custom TitleBar-->
<Thickness x:Key="NavigationViewContentMargin">0,48,0,0</Thickness>
@@ -219,8 +221,8 @@
Margin="12,0,0,0"
Padding="4,12,16,0"
HorizontalScrollMode="Disabled"
- VerticalScrollBarVisibility="Auto"
- VerticalScrollMode="Enabled">
+ VerticalScrollBarVisibility="{x:Bind ViewModel.SelectedMenuItem.Metadata.NotScrollable, Mode=OneWay, Converter={StaticResource BooleanToScrollBarVisibilityConverter}}"
+ VerticalScrollMode="{x:Bind ViewModel.SelectedMenuItem.Metadata.NotScrollable, Mode=OneWay, Converter={StaticResource BooleanToScrollModeConverter}}">
<Frame x:Name="contentFrame" />
</ScrollViewer>
</muxc:NavigationView>
diff --git a/src/dev/impl/DevTools.Impl/Views/Settings/SettingsToolPage.xaml b/src/dev/impl/DevTools.Impl/Views/Settings/SettingsToolPage.xaml
index 808c5ac8f..b31ccf245 100644
--- a/src/dev/impl/DevTools.Impl/Views/Settings/SettingsToolPage.xaml
+++ b/src/dev/impl/DevTools.Impl/Views/Settings/SettingsToolPage.xaml
@@ -27,7 +27,7 @@
<FontIcon Glyph="&#xF592;" />
</controls:ExpandableSettingControl.Icon>
<controls:ExpandableSettingControl.ExpandableContent>
- <StackPanel Spacing="4">
+ <StackPanel Spacing="4" Margin="42,0,6,0">
<RadioButton
Content="{x:Bind ViewModel.Strings.Light}"
IsChecked="{x:Bind ViewModel.Theme, Mode=TwoWay, ConverterParameter='Light', Converter={StaticResource EnumToBooleanConverter}}"/>
@@ -110,7 +110,7 @@
</controls:ExpandableSettingControl.Icon>
<controls:ExpandableSettingControl.ExpandableContent>
<!-- TODO -->
- <Grid>
+ <Grid Margin="42,0,6,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
diff --git a/src/dev/impl/DevTools.Providers.Impl/DevTools.Providers.Impl.csproj b/src/dev/impl/DevTools.Providers.Impl/DevTools.Providers.Impl.csproj
index efbfd5366..ec9c3b8f5 100644
--- a/src/dev/impl/DevTools.Providers.Impl/DevTools.Providers.Impl.csproj
+++ b/src/dev/impl/DevTools.Providers.Impl/DevTools.Providers.Impl.csproj
@@ -85,6 +85,11 @@
<DependentUpon>JsonFormatterToolPage.xaml</DependentUpon>
</Compile>
<Compile Include="Tools\JsonFormatter\JsonFormatterToolViewModel.cs" />
+ <Compile Include="Tools\TextDiff\TextDiffToolPage.xaml.cs">
+ <DependentUpon>TextDiffToolPage.xaml</DependentUpon>
+ </Compile>
+ <Compile Include="Tools\TextDiff\TextDiffToolProvider.cs" />
+ <Compile Include="Tools\TextDiff\TextDiffToolViewModel.cs" />
<Compile Include="Tools\ToolProviderBase.cs" />
</ItemGroup>
<ItemGroup>
@@ -116,6 +121,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
+ <Page Include="Tools\TextDiff\TextDiffToolPage.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
diff --git a/src/dev/impl/DevTools.Providers.Impl/ToolProviderFactory.cs b/src/dev/impl/DevTools.Providers.Impl/ToolProviderFactory.cs
index bc1c864cd..54bf784a4 100644
--- a/src/dev/impl/DevTools.Providers.Impl/ToolProviderFactory.cs
+++ b/src/dev/impl/DevTools.Providers.Impl/ToolProviderFactory.cs
@@ -28,7 +28,7 @@ namespace DevTools.Providers.Impl
}
viewModel = provider.CreateTool();
- _toolProviderToViewModelCache[provider] = provider.CreateTool();
+ _toolProviderToViewModelCache[provider] = viewModel;
return viewModel;
}
diff --git a/src/dev/impl/DevTools.Providers.Impl/Tools/JsonFormatter/JsonFormatterToolViewModel.cs b/src/dev/impl/DevTools.Providers.Impl/Tools/JsonFormatter/JsonFormatterToolViewModel.cs
index deb1d8f18..6183062a1 100644
--- a/src/dev/impl/DevTools.Providers.Impl/Tools/JsonFormatter/JsonFormatterToolViewModel.cs
+++ b/src/dev/impl/DevTools.Providers.Impl/Tools/JsonFormatter/JsonFormatterToolViewModel.cs
@@ -8,7 +8,7 @@ using System.Composition;
namespace DevTools.Providers.Impl.Tools.JsonFormatter
{
[Export(typeof(JsonFormatterToolViewModel))]
- public class JsonFormatterToolViewModel : ObservableRecipient, IToolViewModel
+ public sealed class JsonFormatterToolViewModel : ObservableRecipient, IToolViewModel
{
public Type View { get; } = typeof(JsonFormatterToolPage);
diff --git a/src/dev/impl/DevTools.Providers.Impl/Tools/TextDiff/TextDiffToolPage.xaml b/src/dev/impl/DevTools.Providers.Impl/Tools/TextDiff/TextDiffToolPage.xaml
new file mode 100644
index 000000000..f054afd65
--- /dev/null
+++ b/src/dev/impl/DevTools.Providers.Impl/Tools/TextDiff/TextDiffToolPage.xaml
@@ -0,0 +1,97 @@
+<Page
+ x:Class="DevTools.Providers.Impl.Tools.TextDiff.TextDiffToolPage"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:local="using:DevTools.Providers.Impl.Tools.TextDiff"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:texteditor="using:DevTools.Common.UI.Controls.TextEditor"
+ xmlns:controls="using:DevTools.Common.UI.Controls"
+ xmlns:converters="using:DevTools.Common.UI.Converters"
+ xmlns:formattedtextblock="using:DevTools.Common.UI.Controls.FormattedTextBlock"
+ mc:Ignorable="d"
+ NavigationCacheMode="Required">
+ <Page.Resources>
+ <converters:BooleanToGridLengthConverter x:Key="BooleanToGridLengthConverter" GridLengthOnTrue="*" GridLengthOnFalse="Auto"/>
+ </Page.Resources>
+
+ <Grid Margin="0,0,0,16">
+ <Grid.ChildrenTransitions>
+ <TransitionCollection>
+ <EntranceThemeTransition IsStaggeringEnabled="True" FromVerticalOffset="50"/>
+ </TransitionCollection>
+ </Grid.ChildrenTransitions>
+
+ <Grid.RowDefinitions>
+ <RowDefinition Height="{x:Bind ExandableInput.IsExpanded, Mode=OneWay, Converter={StaticResource BooleanToGridLengthConverter}}"/>
+ <RowDefinition Height="Auto"/>
+ <RowDefinition Height="*"/>
+ </Grid.RowDefinitions>
+
+ <controls:ExpandableSettingControl
+ x:Name="ExandableInput"
+ Grid.Row="0"
+ VerticalAlignment="Stretch"
+ VerticalContentAlignment="Stretch"
+ IsExpanded="True"
+ Title="Inputs">
+ <controls:ExpandableSettingControl.ExpandableContent>
+ <Grid>
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="*"/>
+ <ColumnDefinition Width="*"/>
+ </Grid.ColumnDefinitions>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="Auto"/>
+ <RowDefinition Height="*"/>
+ </Grid.RowDefinitions>
+
+ <Grid
+ Grid.Column="0"
+ Grid.Row="0"
+ Margin="0,0,6,8">
+ <TextBlock
+ Style="{StaticResource SubTitleTextBlock}"
+ Text="Old text"/>
+ </Grid>
+
+ <Grid
+ Grid.Column="1"
+ Grid.Row="0"
+ Margin="6,0,0,8">
+ <TextBlock
+ Style="{StaticResource SubTitleTextBlock}"
+ Text="New text"/>
+ </Grid>
+
+ <texteditor:TextEditor
+ Grid.Column="0"
+ Grid.Row="1"
+ Margin="0,0,6,0"
+ SettingsProvider="{x:Bind ViewModel.SettingsProvider}"
+ Text="{x:Bind ViewModel.OldText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
+
+ <texteditor:TextEditor
+ Grid.Column="1"
+ Grid.Row="1"
+ Margin="6,0,0,0"
+ SettingsProvider="{x:Bind ViewModel.SettingsProvider}"
+ Text="{x:Bind ViewModel.NewText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
+ </Grid>
+ </controls:ExpandableSettingControl.ExpandableContent>
+ </controls:ExpandableSettingControl>
+
+ <Grid
+ Grid.Row="1"
+ Margin="0,0,0,8">
+ <TextBlock
+ Style="{StaticResource SubTitleTextBlock}"
+ Text="Difference"/>
+ </Grid>
+
+ <formattedtextblock:FormattedTextBlock
+ x:Name="OuputTextEditor"
+ Grid.Row="2"
+ SettingsProvider="{x:Bind ViewModel.SettingsProvider}"/>
+ </Grid>
+</Page>
diff --git a/src/dev/impl/DevTools.Providers.Impl/Tools/TextDiff/TextDiffToolPage.xaml.cs b/src/dev/impl/DevTools.Providers.Impl/Tools/TextDiff/TextDiffToolPage.xaml.cs
new file mode 100644
index 000000000..f0240bcda
--- /dev/null
+++ b/src/dev/impl/DevTools.Providers.Impl/Tools/TextDiff/TextDiffToolPage.xaml.cs
@@ -0,0 +1,46 @@
+#nullable enable
+
+using DevTools.Core.Navigation;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Navigation;
+
+namespace DevTools.Providers.Impl.Tools.TextDiff
+{
+ public sealed partial class TextDiffToolPage : Page
+ {
+ public static readonly DependencyProperty ViewModelProperty
+ = DependencyProperty.Register(
+ nameof(ViewModel),
+ typeof(TextDiffToolViewModel),
+ typeof(TextDiffToolPage),
+ new PropertyMetadata(null));
+
+ /// <summary>
+ /// Gets the page's view model.
+ /// </summary>
+ public TextDiffToolViewModel ViewModel
+ {
+ get => (TextDiffToolViewModel)GetValue(ViewModelProperty);
+ set => SetValue(ViewModelProperty, value);
+ }
+
+ public TextDiffToolPage()
+ {
+ InitializeComponent();
+ }
+
+ protected override void OnNavigatedTo(NavigationEventArgs e)
+ {
+ var parameters = (NavigationParameter)e.Parameter;
+
+ // Set the view model
+ ViewModel = (TextDiffToolViewModel)parameters.Parameter!;
+ DataContext = ViewModel;
+
+ ViewModel.FormattedTextBlock = OuputTextEditor;
+
+ base.OnNavigatedTo(e);
+ }
+ }
+}
diff --git a/src/dev/impl/DevTools.Providers.Impl/Tools/TextDiff/TextDiffToolProvider.cs b/src/dev/impl/DevTools.Providers.Impl/Tools/TextDiff/TextDiffToolProvider.cs
new file mode 100644
index 000000000..e7dbfbd27
--- /dev/null
+++ b/src/dev/impl/DevTools.Providers.Impl/Tools/TextDiff/TextDiffToolProvider.cs
@@ -0,0 +1,40 @@
+#nullable enable
+
+using DevTools.Common;
+using DevTools.Core.Injection;
+using DevTools.Core.Threading;
+using System.Composition;
+
+namespace DevTools.Providers.Impl.Tools.TextDiff
+{
+ [Export(typeof(IToolProvider))]
+ [Name("Text Diff")]
+ [ProtocolName("diff")]
+ [Order(0)]
+ [NotScrollable]
+ internal sealed class TextDiffToolProvider : ToolProviderBase, IToolProvider
+ {
+ public string DisplayName => LanguageManager.Instance.TextDiff.DisplayName;
+
+ public object IconSource => CreatePathIconFromPath(nameof(TextDiffToolProvider));
+
+ private readonly IMefProvider _mefProvider;
+
+ [ImportingConstructor]
+ public TextDiffToolProvider(IThread thread, IMefProvider mefProvider)
+ : base(thread)
+ {
+ _mefProvider = mefProvider;
+ }
+
+ public bool CanBeTreatedByTool(string data)
+ {
+ return false;
+ }
+
+ public IToolViewModel CreateTool()
+ {
+ return _mefProvider.Import<TextDiffToolViewModel>();
+ }
+ }
+}
diff --git a/src/dev/impl/DevTools.Providers.Impl/Tools/TextDiff/TextDiffToolViewModel.cs b/src/dev/impl/DevTools.Providers.Impl/Tools/TextDiff/TextDiffToolViewModel.cs
new file mode 100644
index 000000000..5dfec7d0b
--- /dev/null
+++ b/src/dev/impl/DevTools.Providers.Impl/Tools/TextDiff/TextDiffToolViewModel.cs
@@ -0,0 +1,87 @@
+#nullable enable
+
+using DevTools.Common.UI.Controls.FormattedTextBlock;
+using DevTools.Core;
+using DevTools.Core.Settings;
+using DevTools.Core.Threading;
+using Microsoft.Toolkit.Mvvm.ComponentModel;
+using System;
+using System.Collections.Generic;
+using System.Composition;
+using System.Threading.Tasks;
+
+namespace DevTools.Providers.Impl.Tools.TextDiff
+{
+ [Export(typeof(TextDiffToolViewModel))]
+ public sealed class TextDiffToolViewModel : ObservableRecipient, IToolViewModel
+ {
+ private readonly Queue<(string? oldText, string? newText)> _comparisonQueue = new();
+ private readonly IThread _thread;
+
+ private bool _comparisonInProgress;
+ private string? _oldText;
+ private string? _newText;
+
+ public Type View { get; } = typeof(TextDiffToolPage);
+
+ internal ISettingsProvider SettingsProvider { get; }
+
+ internal string? OldText
+ {
+ get => _oldText;
+ set
+ {
+ SetProperty(ref _oldText, value, broadcast: true);
+ QueueComparison();
+ FormattedTextBlock?.SetInlineTextDiff(value, NewText, lineDiff: false);
+ }
+ }
+
+ internal string? NewText
+ {
+ get => _newText;
+ set
+ {
+ SetProperty(ref _newText, value, broadcast: true);
+ QueueComparison();
+ FormattedTextBlock?.SetInlineTextDiff(OldText, value, lineDiff: false);
+ }
+ }
+
+ internal IFormattedTextBlock? FormattedTextBlock { private get; set; }
+
+ [ImportingConstructor]
+ public TextDiffToolViewModel(ISettingsProvider settingsProvider, IThread thread)
+ {
+ SettingsProvider = settingsProvider;
+ _thread = thread;
+ }
+
+ private void QueueComparison()
+ {
+ _comparisonQueue.Enqueue(new(OldText, NewText));
+ TreatComparisonQueueAsync().Forget();
+ }
+
+ private async Task TreatComparisonQueueAsync()
+ {
+ if (_comparisonInProgress)
+ {
+ return;
+ }
+
+ _comparisonInProgress = true;
+
+ Assumes.NotNull(FormattedTextBlock, nameof(FormattedTextBlock));
+
+ await TaskScheduler.Default;
+
+ while (_comparisonQueue.TryDequeue(out (string? oldText, string? newText) item))
+ {
+ // await TextEditor!.ShowTextDiffAsync(item.oldText, item.newText);
+ }
+
+ _comparisonInProgress = false;
+ }
+ }
+}