Skip to content

Commit

Permalink
Merge pull request #305 from AvaloniaUI/preview5
Browse files Browse the repository at this point in the history
Update to preview 5
  • Loading branch information
danipen authored Feb 6, 2023
2 parents e627ba4 + 8a83e8f commit 04a5abd
Show file tree
Hide file tree
Showing 28 changed files with 187 additions and 115 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AvaloniaVersion>11.0.0-preview2</AvaloniaVersion>
<AvaloniaVersion>11.0.0-preview5</AvaloniaVersion>
<TextMateSharpVersion>1.0.50</TextMateSharpVersion>
<NewtonsoftJsonVersion>13.0.1</NewtonsoftJsonVersion>
<VersionSuffix>beta</VersionSuffix>
Expand Down
5 changes: 3 additions & 2 deletions src/AvaloniaEdit.Demo/App.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cc="clr-namespace:AvaloniaEdit.CodeCompletion;assembly=AvaloniaEdit"
x:Class="AvaloniaEdit.Demo.App">
x:Class="AvaloniaEdit.Demo.App"
RequestedThemeVariant="Dark">
<Application.Styles>
<FluentTheme Mode="Dark" />
<FluentTheme />
<StyleInclude Source="avares://AvaloniaEdit/AvaloniaEdit.xaml" />

<!--Code completion-->
Expand Down
16 changes: 4 additions & 12 deletions src/AvaloniaEdit/AvaloniaEditCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using Avalonia;
using Avalonia.Input;
using Avalonia.Platform;
Expand Down Expand Up @@ -112,17 +113,10 @@ public static class ApplicationCommands
public static RoutedCommand Redo { get; } = new RoutedCommand(nameof(Redo), new KeyGesture(Key.Y, PlatformCommandKey));
public static RoutedCommand Find { get; } = new RoutedCommand(nameof(Find), new KeyGesture(Key.F, PlatformCommandKey));
public static RoutedCommand Replace { get; } = new RoutedCommand(nameof(Replace), GetReplaceKeyGesture());

private static OperatingSystemType GetOperatingSystemType()
{
return AvaloniaLocator.Current.GetService<IRuntimePlatform>().GetRuntimeInfo().OperatingSystem;
}

private static KeyModifiers GetPlatformCommandKey()
{
var os = GetOperatingSystemType();

if (os == OperatingSystemType.OSX)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return KeyModifiers.Meta;
}
Expand All @@ -132,9 +126,7 @@ private static KeyModifiers GetPlatformCommandKey()

private static KeyGesture GetReplaceKeyGesture()
{
var os = GetOperatingSystemType();

if (os == OperatingSystemType.OSX)
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return new KeyGesture(Key.F, KeyModifiers.Meta | KeyModifiers.Alt);
}
Expand Down
1 change: 1 addition & 0 deletions src/AvaloniaEdit/Editing/AbstractMargin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using AvaloniaEdit.Document;
using AvaloniaEdit.Rendering;
using Avalonia.Controls;
using AvaloniaEdit.Utils;

namespace AvaloniaEdit.Editing
{
Expand Down
4 changes: 2 additions & 2 deletions src/AvaloniaEdit/Editing/DottedLineMargin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static class DottedLineMargin
/// <summary>
/// Creates a vertical dotted line to separate the line numbers from the text view.
/// </summary>
public static IControl Create()
public static Control Create()
{
var line = new Line
{
Expand All @@ -55,7 +55,7 @@ public static IControl Create()
/// <summary>
/// Gets whether the specified UIElement is the result of a DottedLineMargin.Create call.
/// </summary>
public static bool IsDottedLineMargin(IControl element)
public static bool IsDottedLineMargin(Control element)
{
var l = element as Line;
return l != null && l.Tag == Tag;
Expand Down
16 changes: 8 additions & 8 deletions src/AvaloniaEdit/Editing/TextArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
}
}

internal void AddChild(IVisual visual)
internal void AddChild(Visual visual)
{
VisualChildren.Add(visual);
InvalidateArrange();
}

internal void RemoveChild(IVisual visual)
internal void RemoveChild(Visual visual)
{
VisualChildren.Remove(visual);
}
Expand Down Expand Up @@ -686,14 +686,14 @@ private void CaretPositionChanged(object sender, EventArgs e)
});
}

public static readonly DirectProperty<TextArea, ObservableCollection<IControl>> LeftMarginsProperty
= AvaloniaProperty.RegisterDirect<TextArea, ObservableCollection<IControl>>(nameof(LeftMargins),
public static readonly DirectProperty<TextArea, ObservableCollection<Control>> LeftMarginsProperty
= AvaloniaProperty.RegisterDirect<TextArea, ObservableCollection<Control>>(nameof(LeftMargins),
c => c.LeftMargins);

/// <summary>
/// Gets the collection of margins displayed to the left of the text view.
/// </summary>
public ObservableCollection<IControl> LeftMargins { get; } = new ObservableCollection<IControl>();
public ObservableCollection<Control> LeftMargins { get; } = new ObservableCollection<Control>();

private void LeftMargins_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
Expand Down Expand Up @@ -1122,10 +1122,10 @@ bool ILogicalScrollable.CanVerticallyScroll
}
}

public bool BringIntoView(IControl target, Rect targetRect) =>
public bool BringIntoView(Control target, Rect targetRect) =>
_logicalScrollable?.BringIntoView(target, targetRect) ?? default(bool);

IControl ILogicalScrollable.GetControlInDirection(NavigationDirection direction, IControl from)
Control ILogicalScrollable.GetControlInDirection(NavigationDirection direction, Control from)
=> _logicalScrollable?.GetControlInDirection(direction, from);

public void RaiseScrollInvalidated(EventArgs e)
Expand Down Expand Up @@ -1168,7 +1168,7 @@ public Rect CursorRectangle
}
}

public IVisual TextViewVisual => _textArea;
public Visual TextViewVisual => _textArea;

public bool SupportsPreedit => false;

Expand Down
2 changes: 1 addition & 1 deletion src/AvaloniaEdit/Rendering/FormattedTextElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public FormattedTextRun(FormattedTextElement element, TextRunProperties properti
/// </summary>
public FormattedTextElement Element { get; }

public override ReadOnlySlice<char> Text { get; }
public override ReadOnlyMemory<char> Text { get; }

/// <inheritdoc/>
public override TextRunProperties Properties { get; }
Expand Down
4 changes: 2 additions & 2 deletions src/AvaloniaEdit/Rendering/InlineObjectRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public InlineObjectRun(int length, TextRunProperties? properties, Control elemen
if (length <= 0)
throw new ArgumentOutOfRangeException(nameof(length), length, "Value must be positive");

TextSourceLength = length;
Length = length;
Properties = properties ?? throw new ArgumentNullException(nameof(properties));
Element = element ?? throw new ArgumentNullException(nameof(element));

Expand All @@ -95,7 +95,7 @@ public InlineObjectRun(int length, TextRunProperties? properties, Control elemen

public override TextRunProperties? Properties { get; }

public override int TextSourceLength { get; }
public override int Length { get; }

public override double Baseline
{
Expand Down
4 changes: 2 additions & 2 deletions src/AvaloniaEdit/Rendering/PointerHoverLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class PointerHoverLogic : IDisposable
private const double PointerHoverHeight = 2;
private static readonly TimeSpan PointerHoverTime = TimeSpan.FromMilliseconds(400);

private readonly IControl _target;
private readonly Control _target;

private DispatcherTimer _timer;
private Point _hoverStartPoint;
Expand All @@ -43,7 +43,7 @@ public class PointerHoverLogic : IDisposable
/// <summary>
/// Creates a new instance and attaches itself to the <paramref name="target" /> UIElement.
/// </summary>
public PointerHoverLogic(IControl target)
public PointerHoverLogic(Control target)
{
_target = target ?? throw new ArgumentNullException(nameof(target));
_target.PointerExited += OnPointerLeave;
Expand Down
2 changes: 1 addition & 1 deletion src/AvaloniaEdit/Rendering/SimpleTextSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public TextRun GetTextRun(int textSourceCharacterIndex)
{
if (textSourceCharacterIndex < _text.Length)
return new TextCharacters(
new ReadOnlySlice<char>(_text.AsMemory(), textSourceCharacterIndex,
_text.AsMemory().Slice(textSourceCharacterIndex,
_text.Length - textSourceCharacterIndex), _properties);

return new TextEndOfParagraph(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public override TextRun CreateTextRun(int startVisualColumn, ITextRunConstructio
if (startVisualColumn == VisualColumn)
return new TabGlyphRun(this, TextRunProperties);
else if (startVisualColumn == VisualColumn + 1)
return new TextCharacters(new ReadOnlySlice<char>("\t".AsMemory(), VisualColumn + 1, 1), TextRunProperties);
return new TextCharacters("\t".AsMemory(), TextRunProperties);
else
throw new ArgumentOutOfRangeException(nameof(startVisualColumn));
}
Expand Down
6 changes: 3 additions & 3 deletions src/AvaloniaEdit/Rendering/TextView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ protected override Size ArrangeOverride(Size finalSize)
Debug.WriteLine(distance);
}

offset += span.TextSourceLength;
offset += span.Length;
}
pos = new Point(pos.X, pos.Y + textLine.Height);
}
Expand Down Expand Up @@ -1950,7 +1950,7 @@ private static ImmutablePen CreateFrozenPen(IBrush brush)
return pen;
}

bool ILogicalScrollable.BringIntoView(IControl target, Rect rectangle)
bool ILogicalScrollable.BringIntoView(Control target, Rect rectangle)
{
if (rectangle.IsEmpty || target == null || target == this || !this.IsVisualAncestorOf(target))
{
Expand All @@ -1967,7 +1967,7 @@ bool ILogicalScrollable.BringIntoView(IControl target, Rect rectangle)
return true;
}

IControl ILogicalScrollable.GetControlInDirection(NavigationDirection direction, IControl from)
Control ILogicalScrollable.GetControlInDirection(NavigationDirection direction, Control from)
{
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/AvaloniaEdit/Rendering/VisualLineElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ internal void SetTextRunProperties(VisualLineElementTextRunProperties p)
/// Retrieves the text span immediately before the visual column.
/// </summary>
/// <remarks>This method is used for word-wrapping in bidirectional text.</remarks>
public virtual ReadOnlySlice<char> GetPrecedingText(int visualColumnLimit, ITextRunConstructionContext context)
public virtual ReadOnlyMemory<char> GetPrecedingText(int visualColumnLimit, ITextRunConstructionContext context)
{
return ReadOnlySlice<char>.Empty;
return ReadOnlyMemory<char>.Empty;
}

/// <summary>
Expand Down
7 changes: 6 additions & 1 deletion src/AvaloniaEdit/Rendering/VisualLineLinkText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ protected internal override void OnPointerPressed(PointerPressedEventArgs e)
if (!e.Handled && LinkIsClickable(e.KeyModifiers))
{
var eventArgs = new OpenUriRoutedEventArgs(NavigateUri) { RoutedEvent = OpenUriEvent };
e.Source.RaiseEvent(eventArgs);

if(e.Source is Interactive interactive)
{
interactive.RaiseEvent(eventArgs);
}

e.Handled = true;
}
}
Expand Down
13 changes: 3 additions & 10 deletions src/AvaloniaEdit/Rendering/VisualLineText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,7 @@ public override TextRun CreateTextRun(int startVisualColumn, ITextRunConstructio
offset,
DocumentLength - relativeOffset);

var bufferOffset = RelativeTextOffset;

if (bufferOffset + text.Count > text.Text.Length)
{
bufferOffset = 0;
}

var textSlice = new ReadOnlySlice<char>(text.Text.AsMemory(), text.Offset, text.Count, bufferOffset);
var textSlice = text.Text.AsMemory().Slice(text.Offset, text.Count);

return new TextCharacters(textSlice, TextRunProperties);
}
Expand All @@ -88,7 +81,7 @@ public override bool IsWhitespace(int visualColumn)
}

/// <inheritdoc/>
public override ReadOnlySlice<char> GetPrecedingText(int visualColumnLimit, ITextRunConstructionContext context)
public override ReadOnlyMemory<char> GetPrecedingText(int visualColumnLimit, ITextRunConstructionContext context)
{
if (context == null)
throw new ArgumentNullException(nameof(context));
Expand All @@ -97,7 +90,7 @@ public override ReadOnlySlice<char> GetPrecedingText(int visualColumnLimit, ITex

var text = context.GetText(context.VisualLine.FirstDocumentLine.Offset + RelativeTextOffset, relativeOffset);

return new ReadOnlySlice<char>(text.Text.AsMemory(), text.Offset, text.Count);
return text.Text.AsMemory().Slice(text.Offset, text.Count);
}

/// <inheritdoc/>
Expand Down
8 changes: 4 additions & 4 deletions src/AvaloniaEdit/Rendering/VisualLineTextSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public TextRun GetTextRun(int textSourceCharacterIndex)
TextRun run = element.CreateTextRun(textSourceCharacterIndex, this);
if (run == null)
throw new ArgumentNullException(element.GetType().Name + ".CreateTextRun");
if (run.TextSourceLength == 0)
if (run.Length == 0)
throw new ArgumentException("The returned TextRun must not have length 0.", element.GetType().Name + ".Length");
if (relativeOffset + run.TextSourceLength > element.VisualLength)
if (relativeOffset + run.Length > element.VisualLength)
throw new ArgumentException("The returned TextRun is too long.", element.GetType().Name + ".CreateTextRun");
if (run is InlineObjectRun inlineRun) {
inlineRun.VisualLine = VisualLine;
Expand Down Expand Up @@ -102,7 +102,7 @@ private TextRun CreateTextRunForNewLine()
return new FormattedTextRun(textElement, GlobalTextRunProperties);
}

public ReadOnlySlice<char> GetPrecedingText(int textSourceCharacterIndexLimit)
public ReadOnlyMemory<char> GetPrecedingText(int textSourceCharacterIndexLimit)
{
try {
foreach (VisualLineElement element in VisualLine.Elements) {
Expand All @@ -118,7 +118,7 @@ public ReadOnlySlice<char> GetPrecedingText(int textSourceCharacterIndexLimit)
}
}

return ReadOnlySlice<char>.Empty;
return ReadOnlyMemory<char>.Empty;
} catch (Exception ex) {
Debug.WriteLine(ex.ToString());
throw;
Expand Down
29 changes: 18 additions & 11 deletions src/AvaloniaEdit/RoutedCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,29 @@ public RoutedCommand(string name, KeyGesture keyGesture = null)

static RoutedCommand()
{
CanExecuteEvent.AddClassHandler<IRoutedCommandBindable>(CanExecuteEventHandler);
ExecutedEvent.AddClassHandler<IRoutedCommandBindable>(ExecutedEventHandler);
CanExecuteEvent.AddClassHandler<Interactive>(CanExecuteEventHandler);
ExecutedEvent.AddClassHandler<Interactive>(ExecutedEventHandler);
}

private static void CanExecuteEventHandler(IRoutedCommandBindable control, CanExecuteRoutedEventArgs args)
private static void CanExecuteEventHandler(Interactive control, CanExecuteRoutedEventArgs args)
{
var binding = control.CommandBindings.Where(c => c != null)
.FirstOrDefault(c => c.Command == args.Command && c.DoCanExecute(control, args));
args.CanExecute = binding != null;
if (control is IRoutedCommandBindable bindable)
{
var binding = bindable.CommandBindings.Where(c => c != null)
.FirstOrDefault(c => c.Command == args.Command && c.DoCanExecute(control, args));
args.CanExecute = binding != null;
}
}

private static void ExecutedEventHandler(IRoutedCommandBindable control, ExecutedRoutedEventArgs args)
private static void ExecutedEventHandler(Interactive control, ExecutedRoutedEventArgs args)
{
// ReSharper disable once UnusedVariable
var binding = control.CommandBindings.Where(c => c != null)
.FirstOrDefault(c => c.Command == args.Command && c.DoExecuted(control, args));
if (control is IRoutedCommandBindable bindable)
{
// ReSharper disable once UnusedVariable
var binding = bindable.CommandBindings.Where(c => c != null)
.FirstOrDefault(c => c.Command == args.Command && c.DoExecuted(control, args));

}
}

public static RoutedEvent<CanExecuteRoutedEventArgs> CanExecuteEvent { get; } = RoutedEvent.Register<CanExecuteRoutedEventArgs>(nameof(CanExecuteEvent), RoutingStrategies.Bubble, typeof(RoutedCommand));
Expand Down Expand Up @@ -79,7 +86,7 @@ event EventHandler ICommand.CanExecuteChanged
}
}

public interface IRoutedCommandBindable : IInteractive
public interface IRoutedCommandBindable
{
IList<RoutedCommandBinding> CommandBindings { get; }
}
Expand Down
1 change: 1 addition & 0 deletions src/AvaloniaEdit/Search/SearchPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using AvaloniaEdit.Document;
using AvaloniaEdit.Editing;
using AvaloniaEdit.Rendering;
using AvaloniaEdit.Utils;

namespace AvaloniaEdit.Search
{
Expand Down
Loading

0 comments on commit 04a5abd

Please sign in to comment.