Merge branch 'master' of https://github.com/AvaloniaUI/AvaloniaEdit
This commit is contained in:
Коммит
0b8e2b68d8
|
@ -6,6 +6,7 @@ using Avalonia;
|
|||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Platform;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Media.Imaging;
|
||||
|
@ -53,6 +54,13 @@ namespace AvaloniaEdit.Demo
|
|||
_textEditor.TextArea.TextView.ElementGenerators.Add(_generator);
|
||||
|
||||
impl = PlatformManager.CreateWindow().CreatePopup();
|
||||
|
||||
this.AddHandler(PointerWheelChangedEvent, (o, i) =>
|
||||
{
|
||||
if (i.KeyModifiers != KeyModifiers.Control) return;
|
||||
if (i.Delta.Y > 0) _textEditor.FontSize++;
|
||||
else _textEditor.FontSize = _textEditor.FontSize > 1 ? _textEditor.FontSize - 1 : 1;
|
||||
}, RoutingStrategies.Bubble, true);
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
|
|
|
@ -88,6 +88,21 @@ namespace AvaloniaEdit.Editing
|
|||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnTextViewChanged(TextView oldTextView, TextView newTextView)
|
||||
{
|
||||
if (oldTextView != null)
|
||||
{
|
||||
oldTextView.VisualLinesChanged -= TextViewVisualLinesChanged;
|
||||
}
|
||||
base.OnTextViewChanged(oldTextView, newTextView);
|
||||
if (newTextView != null)
|
||||
{
|
||||
newTextView.VisualLinesChanged += TextViewVisualLinesChanged;
|
||||
}
|
||||
InvalidateVisual();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnDocumentChanged(TextDocument oldDocument, TextDocument newDocument)
|
||||
{
|
||||
|
@ -108,6 +123,12 @@ namespace AvaloniaEdit.Editing
|
|||
OnDocumentLineCountChanged();
|
||||
}
|
||||
|
||||
void TextViewVisualLinesChanged(object sender, EventArgs e)
|
||||
{
|
||||
InvalidateMeasure();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Maximum length of a line number, in characters
|
||||
/// </summary>
|
||||
|
|
|
@ -115,8 +115,6 @@ namespace AvaloniaEdit.Editing
|
|||
if (e.NameScope.Find("PART_CP") is ContentPresenter contentPresenter)
|
||||
{
|
||||
contentPresenter.Content = TextView;
|
||||
|
||||
SearchPanel.Install(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ namespace AvaloniaEdit.Search
|
|||
private TextDocument _currentDocument;
|
||||
private SearchResultBackgroundRenderer _renderer;
|
||||
private TextBox _searchTextBox;
|
||||
private TextEditor _textEditor { get; set; }
|
||||
|
||||
#region DependencyProperties
|
||||
/// <summary>
|
||||
|
@ -106,12 +107,22 @@ namespace AvaloniaEdit.Search
|
|||
}
|
||||
|
||||
public static readonly AvaloniaProperty<bool> IsReplaceModeProperty =
|
||||
AvaloniaProperty.Register<SearchPanel, bool>(nameof(IsReplaceMode));
|
||||
AvaloniaProperty.Register<SearchPanel, bool>(nameof(IsReplaceMode), validate: ValidateReplaceMode);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if replacemode is allowed
|
||||
/// </summary>
|
||||
/// <returns>False if editor is not null and readonly</returns>
|
||||
private static bool ValidateReplaceMode(SearchPanel panel, bool v1)
|
||||
{
|
||||
if (panel._textEditor == null || !v1) return v1;
|
||||
return !panel._textEditor.IsReadOnly;
|
||||
}
|
||||
|
||||
public bool IsReplaceMode
|
||||
{
|
||||
get => GetValue(IsReplaceModeProperty);
|
||||
set => SetValue(IsReplaceModeProperty, value);
|
||||
set => SetValue(IsReplaceModeProperty, _textEditor?.IsReadOnly ?? false ? false : value);
|
||||
}
|
||||
|
||||
public static readonly AvaloniaProperty<string> ReplacePatternProperty =
|
||||
|
@ -195,9 +206,10 @@ namespace AvaloniaEdit.Search
|
|||
/// <remarks>This is a convenience wrapper.</remarks>
|
||||
public static SearchPanel Install(TextEditor editor)
|
||||
{
|
||||
if (editor == null)
|
||||
throw new ArgumentNullException(nameof(editor));
|
||||
return Install(editor.TextArea);
|
||||
if (editor == null) throw new ArgumentNullException(nameof(editor));
|
||||
SearchPanel searchPanel = Install(editor.TextArea);
|
||||
searchPanel._textEditor = editor;
|
||||
return searchPanel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -205,8 +217,7 @@ namespace AvaloniaEdit.Search
|
|||
/// </summary>
|
||||
public static SearchPanel Install(TextArea textArea)
|
||||
{
|
||||
if (textArea == null)
|
||||
throw new ArgumentNullException(nameof(textArea));
|
||||
if (textArea == null) throw new ArgumentNullException(nameof(textArea));
|
||||
var panel = new SearchPanel();
|
||||
panel.AttachInternal(textArea);
|
||||
panel._handler = new SearchInputHandler(textArea, panel);
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
ObeyScreenEdges="True">
|
||||
<ContentPresenter Name="PART_MessageContent" />
|
||||
</Popup>
|
||||
<ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top"
|
||||
<ToggleButton Classes="ExpanderToggle" Name="Expander" VerticalAlignment="Top" IsVisible="{Binding !_textEditor.IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
IsChecked="{Binding IsReplaceMode, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
Grid.Column="0"
|
||||
Grid.Row="0"
|
||||
|
|
|
@ -34,6 +34,7 @@ using Avalonia.Input;
|
|||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Data;
|
||||
using AvaloniaEdit.Search;
|
||||
|
||||
namespace AvaloniaEdit
|
||||
{
|
||||
|
@ -268,6 +269,8 @@ namespace AvaloniaEdit
|
|||
base.OnTemplateApplied(e);
|
||||
ScrollViewer = (ScrollViewer)e.NameScope.Find("PART_ScrollViewer");
|
||||
ScrollViewer.Content = TextArea;
|
||||
|
||||
SearchPanel.Install(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Загрузка…
Ссылка в новой задаче