From 51d245b3ad61ec0088141951743650c8c7df392f Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Sun, 23 Jul 2017 19:59:17 +0100 Subject: [PATCH 1/9] netstandard1.3 to support new avalonia. --- src/AvaloniaEdit/AvaloniaEdit.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AvaloniaEdit/AvaloniaEdit.csproj b/src/AvaloniaEdit/AvaloniaEdit.csproj index 83f47170..9bcfd3d7 100644 --- a/src/AvaloniaEdit/AvaloniaEdit.csproj +++ b/src/AvaloniaEdit/AvaloniaEdit.csproj @@ -1,7 +1,7 @@  - netstandard1.1 + netstandard1.3 @@ -37,7 +37,7 @@ - + \ No newline at end of file From 9346ecf6e1a6b792ff599b448e003429fe2df80f Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Sun, 23 Jul 2017 20:41:25 +0100 Subject: [PATCH 2/9] update type converters. --- src/AvaloniaEdit/Document/TextLocation.cs | 13 ++--- .../HighlightingDefinitionTypeConverter.cs | 50 +++++++++---------- .../Highlighting/IHighlightingDefinition.cs | 2 +- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/AvaloniaEdit/Document/TextLocation.cs b/src/AvaloniaEdit/Document/TextLocation.cs index 12d34461..28ce4f50 100644 --- a/src/AvaloniaEdit/Document/TextLocation.cs +++ b/src/AvaloniaEdit/Document/TextLocation.cs @@ -18,7 +18,8 @@ using System; using System.Globalization; -using OmniXaml.TypeConversion; +using System.ComponentModel; +using Portable.Xaml.ComponentModel; namespace AvaloniaEdit.Document { @@ -167,22 +168,22 @@ public int CompareTo(TextLocation other) /// /// Converts strings of the form '0+[;,]0+' to a . /// - public class TextLocationConverter : ITypeConverter + public class TextLocationConverter : TypeConverter { /// - public bool CanConvertFrom(IValueContext context, Type sourceType) + public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { return sourceType == typeof(string); } /// - public bool CanConvertTo(IValueContext context, Type destinationType) + public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { return destinationType == typeof(TextLocation); } /// - public object ConvertFrom(IValueContext context, CultureInfo culture, object value) + public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { var s = value as string; var parts = s?.Split(';', ','); @@ -194,7 +195,7 @@ public object ConvertFrom(IValueContext context, CultureInfo culture, object val } /// - public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType) + public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value is TextLocation loc && destinationType == typeof(string)) { diff --git a/src/AvaloniaEdit/Highlighting/HighlightingDefinitionTypeConverter.cs b/src/AvaloniaEdit/Highlighting/HighlightingDefinitionTypeConverter.cs index 3c9a9471..8a91ce09 100644 --- a/src/AvaloniaEdit/Highlighting/HighlightingDefinitionTypeConverter.cs +++ b/src/AvaloniaEdit/Highlighting/HighlightingDefinitionTypeConverter.cs @@ -17,8 +17,8 @@ // DEALINGS IN THE SOFTWARE. using System; +using System.ComponentModel; using System.Globalization; -using OmniXaml.TypeConversion; namespace AvaloniaEdit.Highlighting { @@ -26,33 +26,33 @@ namespace AvaloniaEdit.Highlighting /// Converts between strings and by treating the string as the definition name /// and calling HighlightingManager.Instance.GetDefinition(name). /// - public sealed class HighlightingDefinitionTypeConverter : ITypeConverter + public sealed class HighlightingDefinitionTypeConverter : TypeConverter { - /// - public bool CanConvertFrom(IValueContext context, Type sourceType) - { - return sourceType == typeof(string); - } - - /// - public object ConvertFrom(IValueContext context, CultureInfo culture, object value) - { - string definitionName = value as string; - return definitionName != null ? HighlightingManager.Instance.GetDefinition(definitionName) : null; - } - - /// - public bool CanConvertTo(IValueContext context, Type destinationType) - { - return destinationType == typeof(string); - } - - /// - public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType) - { + /// + public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) + { + return sourceType == typeof(string); + } + + /// + public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + { + string definitionName = value as string; + return definitionName != null ? HighlightingManager.Instance.GetDefinition(definitionName) : null; + } + + /// + public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) + { + return destinationType == typeof(string); + } + + /// + public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) + { if (value is IHighlightingDefinition definition && destinationType == typeof(string)) return definition.Name; return null; - } + } } } diff --git a/src/AvaloniaEdit/Highlighting/IHighlightingDefinition.cs b/src/AvaloniaEdit/Highlighting/IHighlightingDefinition.cs index 6dd0f017..576000f1 100644 --- a/src/AvaloniaEdit/Highlighting/IHighlightingDefinition.cs +++ b/src/AvaloniaEdit/Highlighting/IHighlightingDefinition.cs @@ -17,7 +17,7 @@ // DEALINGS IN THE SOFTWARE. using System.Collections.Generic; -using OmniXaml.TypeConversion; +using System.ComponentModel; namespace AvaloniaEdit.Highlighting { From 296500ef58e7edca0947f4e06eb958edb9e69cb1 Mon Sep 17 00:00:00 2001 From: James Walmsley Date: Sun, 23 Jul 2017 22:08:31 +0200 Subject: [PATCH 3/9] fix paste from external app on linux. --- .../Editing/EditingCommandHandler.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/AvaloniaEdit/Editing/EditingCommandHandler.cs b/src/AvaloniaEdit/Editing/EditingCommandHandler.cs index b9ee0953..5c0549aa 100644 --- a/src/AvaloniaEdit/Editing/EditingCommandHandler.cs +++ b/src/AvaloniaEdit/Editing/EditingCommandHandler.cs @@ -24,6 +24,7 @@ using AvaloniaEdit.Document; using Avalonia.Input; using AvaloniaEdit.Utils; +using System.Threading.Tasks; namespace AvaloniaEdit.Editing { @@ -469,26 +470,26 @@ private static void CanPaste(object target, CanExecuteRoutedEventArgs args) var textArea = GetTextArea(target); if (textArea?.Document != null) { - args.CanExecute = textArea.ReadOnlySectionProvider.CanInsert(textArea.Caret.Offset) - && !string.IsNullOrEmpty(Application.Current.Clipboard.GetTextAsync() - .GetAwaiter() - .GetResult()); + args.CanExecute = textArea.ReadOnlySectionProvider.CanInsert(textArea.Caret.Offset); args.Handled = true; } } - private static void OnPaste(object target, ExecutedRoutedEventArgs args) + private static async void OnPaste(object target, ExecutedRoutedEventArgs args) { var textArea = GetTextArea(target); if (textArea?.Document != null) { - string text; + textArea.Document.BeginUpdate(); + + string text = null; try { - text = Application.Current.Clipboard.GetTextAsync().GetAwaiter().GetResult(); + text = await Application.Current.Clipboard.GetTextAsync(); } catch (Exception) { + textArea.Document.EndUpdate(); return; } @@ -505,6 +506,8 @@ private static void OnPaste(object target, ExecutedRoutedEventArgs args) textArea.Caret.BringCaretToView(); args.Handled = true; + + textArea.Document.EndUpdate(); } } From b2e9d1642c6fae0b55efe5819ec1edd54e15dea2 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Wed, 26 Jul 2017 09:55:29 +0100 Subject: [PATCH 4/9] tidy project file. --- src/AvaloniaEdit/AvaloniaEdit.csproj | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/src/AvaloniaEdit/AvaloniaEdit.csproj b/src/AvaloniaEdit/AvaloniaEdit.csproj index 9bcfd3d7..9d952ef1 100644 --- a/src/AvaloniaEdit/AvaloniaEdit.csproj +++ b/src/AvaloniaEdit/AvaloniaEdit.csproj @@ -5,33 +5,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + From f9f8ae0dfeff1313ad46069b4f63dff89caa44fb Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Wed, 2 Aug 2017 14:25:22 +0100 Subject: [PATCH 5/9] invalidate margins on scroll. --- src/AvaloniaEdit/Editing/TextArea.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/AvaloniaEdit/Editing/TextArea.cs b/src/AvaloniaEdit/Editing/TextArea.cs index bb47e489..9bf5e0c9 100644 --- a/src/AvaloniaEdit/Editing/TextArea.cs +++ b/src/AvaloniaEdit/Editing/TextArea.cs @@ -1087,6 +1087,11 @@ Vector IScrollable.Offset TextView.SetScrollOffset(new Vector(value.X, value.Y * TextView.DefaultLineHeight)); _offset = value; + + foreach(var margin in LeftMargins) + { + margin.InvalidateVisual(); + } } } From 680ba4a6b02ef276334607d0ddc9fba69b0836b4 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Wed, 2 Aug 2017 14:55:31 +0100 Subject: [PATCH 6/9] remove invalidation of margins manually. --- src/AvaloniaEdit/Editing/TextArea.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/AvaloniaEdit/Editing/TextArea.cs b/src/AvaloniaEdit/Editing/TextArea.cs index 9bf5e0c9..bb47e489 100644 --- a/src/AvaloniaEdit/Editing/TextArea.cs +++ b/src/AvaloniaEdit/Editing/TextArea.cs @@ -1087,11 +1087,6 @@ Vector IScrollable.Offset TextView.SetScrollOffset(new Vector(value.X, value.Y * TextView.DefaultLineHeight)); _offset = value; - - foreach(var margin in LeftMargins) - { - margin.InvalidateVisual(); - } } } From e5158b1ab7da87e2136fc7569dedd026917ffd9b Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Wed, 2 Aug 2017 15:13:57 +0100 Subject: [PATCH 7/9] Abstract margin now implements the job of invalidating the visual when attached textviews visual lines change. --- src/AvaloniaEdit/Editing/AbstractMargin.cs | 50 ++++++++++++++++---- src/AvaloniaEdit/Editing/LineNumberMargin.cs | 27 ----------- src/AvaloniaEdit/Folding/FoldingMargin.cs | 17 +------ 3 files changed, 41 insertions(+), 53 deletions(-) diff --git a/src/AvaloniaEdit/Editing/AbstractMargin.cs b/src/AvaloniaEdit/Editing/AbstractMargin.cs index b530fc82..92dfc716 100644 --- a/src/AvaloniaEdit/Editing/AbstractMargin.cs +++ b/src/AvaloniaEdit/Editing/AbstractMargin.cs @@ -34,16 +34,22 @@ namespace AvaloniaEdit.Editing /// public abstract class AbstractMargin : Control, ITextViewConnect { - static AbstractMargin() + private TextArea _textArea; + + public AbstractMargin() { - TextViewProperty.Changed.Subscribe(OnTextViewChanged); + this.GetObservableWithHistory(TextViewProperty).Subscribe(o => + { + _wasAutoAddedToTextView = false; + OnTextViewChanged(o.Item1, o.Item2); + }); } /// /// TextView property. /// public static readonly AvaloniaProperty TextViewProperty = - AvaloniaProperty.Register("TextView"); + AvaloniaProperty.Register(nameof(TextView)); /// /// Gets/sets the text view for which line numbers are displayed. @@ -55,13 +61,6 @@ public TextView TextView set => SetValue(TextViewProperty, value); } - private static void OnTextViewChanged(AvaloniaPropertyChangedEventArgs e) - { - var margin = (AbstractMargin)e.Sender; - margin._wasAutoAddedToTextView = false; - margin.OnTextViewChanged((TextView)e.OldValue, (TextView)e.NewValue); - } - // automatically set/unset TextView property using ITextViewConnect private bool _wasAutoAddedToTextView; @@ -110,6 +109,37 @@ protected virtual void OnTextViewChanged(TextView oldTextView, TextView newTextV } TextViewDocumentChanged(null, null); + + if (oldTextView != null) + { + oldTextView.VisualLinesChanged -= TextViewVisualLinesChanged; + } + + if (newTextView != null) + { + newTextView.VisualLinesChanged += TextViewVisualLinesChanged; + + // find the text area belonging to the new text view + _textArea = newTextView.GetService(typeof(TextArea)) as TextArea; + } + else + { + _textArea = null; + } + } + + /// + /// Called when the attached textviews visual lines change. + /// Default behavior is to Invalidate Margins Visual. + /// + protected virtual void OnTextViewVisualLinesChanged() + { + InvalidateVisual(); + } + + private void TextViewVisualLinesChanged(object sender, EventArgs e) + { + OnTextViewVisualLinesChanged(); } private void TextViewDocumentChanged(object sender, EventArgs e) diff --git a/src/AvaloniaEdit/Editing/LineNumberMargin.cs b/src/AvaloniaEdit/Editing/LineNumberMargin.cs index 54e692f5..df04bbaf 100644 --- a/src/AvaloniaEdit/Editing/LineNumberMargin.cs +++ b/src/AvaloniaEdit/Editing/LineNumberMargin.cs @@ -87,28 +87,6 @@ public override void Render(DrawingContext drawingContext) } } - /// - protected override void OnTextViewChanged(TextView oldTextView, TextView newTextView) - { - if (oldTextView != null) - { - oldTextView.VisualLinesChanged -= TextViewVisualLinesChanged; - } - base.OnTextViewChanged(oldTextView, newTextView); - if (newTextView != null) - { - newTextView.VisualLinesChanged += TextViewVisualLinesChanged; - - // find the text area belonging to the new text view - _textArea = newTextView.GetService(typeof(TextArea)) as TextArea; - } - else - { - _textArea = null; - } - InvalidateVisual(); - } - /// protected override void OnDocumentChanged(TextDocument oldDocument, TextDocument newDocument) { @@ -151,11 +129,6 @@ private void OnDocumentLineCountChanged() } } - private void TextViewVisualLinesChanged(object sender, EventArgs e) - { - InvalidateVisual(); - } - private AnchorSegment _selectionStart; private bool _selecting; diff --git a/src/AvaloniaEdit/Folding/FoldingMargin.cs b/src/AvaloniaEdit/Folding/FoldingMargin.cs index b15f7498..380ca84f 100644 --- a/src/AvaloniaEdit/Folding/FoldingMargin.cs +++ b/src/AvaloniaEdit/Folding/FoldingMargin.cs @@ -160,24 +160,9 @@ protected override Size ArrangeOverride(Size finalSize) return base.ArrangeOverride(finalSize); } - /// - protected override void OnTextViewChanged(TextView oldTextView, TextView newTextView) - { - if (oldTextView != null) - { - oldTextView.VisualLinesChanged -= TextViewVisualLinesChanged; - } - base.OnTextViewChanged(oldTextView, newTextView); - if (newTextView != null) - { - newTextView.VisualLinesChanged += TextViewVisualLinesChanged; - } - TextViewVisualLinesChanged(null, null); - } - private readonly List _markers = new List(); - private void TextViewVisualLinesChanged(object sender, EventArgs e) + protected override void OnTextViewVisualLinesChanged() { foreach (var m in _markers) { From 8d876ecb7458b6f04c3cce41aa0c9f8ead1563b0 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Sun, 6 Aug 2017 12:58:28 +0100 Subject: [PATCH 8/9] update avalonia. --- src/AvaloniaEdit/AvaloniaEdit.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AvaloniaEdit/AvaloniaEdit.csproj b/src/AvaloniaEdit/AvaloniaEdit.csproj index 9d952ef1..4e8edd77 100644 --- a/src/AvaloniaEdit/AvaloniaEdit.csproj +++ b/src/AvaloniaEdit/AvaloniaEdit.csproj @@ -11,7 +11,7 @@ - + \ No newline at end of file From c34fac2d7ac442da9a8de854e5eef90ff6dedcb0 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Mon, 14 Aug 2017 09:34:05 +0100 Subject: [PATCH 9/9] build script uses correct netstandard version. --- build.cake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cake b/build.cake index d161c82c..54d1e433 100644 --- a/build.cake +++ b/build.cake @@ -182,7 +182,7 @@ var nuspecNuGetBehaviors = new NuGetPackSettings() }, Files = new [] { - new NuSpecContent { Source = "src/AvaloniaEdit/bin/" + configuration + "/netstandard1.1/AvaloniaEdit.dll", Target = "lib/netstandard1.1" }, + new NuSpecContent { Source = "src/AvaloniaEdit/bin/" + configuration + "/netstandard1.3/AvaloniaEdit.dll", Target = "lib/netstandard1.3" }, }, BasePath = Directory("./"), OutputDirectory = nugetRoot