From 2c1e2aa8b030bcfff48fbf22315d1c029df41147 Mon Sep 17 00:00:00 2001 From: Daniil Pavliuchyk Date: Wed, 5 Jul 2023 20:13:53 +0300 Subject: [PATCH 1/2] Update to Avalonia 11 --- Directory.Build.props | 2 +- .../AvaloniaEdit.Demo.csproj | 2 +- .../AvaloniaEdit.TextMate.csproj | 2 +- src/AvaloniaEdit/Editing/TextArea.cs | 47 +++++-------------- .../AvaloniaEdit.Tests.csproj | 4 +- 5 files changed, 18 insertions(+), 39 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index c21a30ab..41ffd0bf 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,7 +2,7 @@ latest true - 11.0.0-rc1.1 + 11.0.0 1.0.55 beta diff --git a/src/AvaloniaEdit.Demo/AvaloniaEdit.Demo.csproj b/src/AvaloniaEdit.Demo/AvaloniaEdit.Demo.csproj index fe826f14..9edbb13d 100644 --- a/src/AvaloniaEdit.Demo/AvaloniaEdit.Demo.csproj +++ b/src/AvaloniaEdit.Demo/AvaloniaEdit.Demo.csproj @@ -33,7 +33,7 @@ - + diff --git a/src/AvaloniaEdit.TextMate/AvaloniaEdit.TextMate.csproj b/src/AvaloniaEdit.TextMate/AvaloniaEdit.TextMate.csproj index c3e002d0..9490a8a2 100644 --- a/src/AvaloniaEdit.TextMate/AvaloniaEdit.TextMate.csproj +++ b/src/AvaloniaEdit.TextMate/AvaloniaEdit.TextMate.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/AvaloniaEdit/Editing/TextArea.cs b/src/AvaloniaEdit/Editing/TextArea.cs index ade1cb34..b8dcb3d7 100644 --- a/src/AvaloniaEdit/Editing/TextArea.cs +++ b/src/AvaloniaEdit/Editing/TextArea.cs @@ -1134,9 +1134,8 @@ public void RaiseScrollInvalidated(EventArgs e) _logicalScrollable?.RaiseScrollInvalidated(e); } - private class TextAreaTextInputMethodClient : ITextInputMethodClient + private class TextAreaTextInputMethodClient : TextInputMethodClient { - private ITextEditable _textEditable; private TextArea _textArea; public TextAreaTextInputMethodClient() @@ -1144,11 +1143,7 @@ public TextAreaTextInputMethodClient() } - public event EventHandler CursorRectangleChanged; - public event EventHandler TextViewVisualChanged; - public event EventHandler SurroundingTextChanged; - - public Rect CursorRectangle + public override Rect CursorRectangle { get { @@ -1170,13 +1165,13 @@ public Rect CursorRectangle } } - public Visual TextViewVisual => _textArea; + public override Visual TextViewVisual => _textArea; - public bool SupportsPreedit => false; + public override bool SupportsPreedit => false; - public bool SupportsSurroundingText => true; + public override bool SupportsSurroundingText => true; - public TextInputMethodSurroundingText SurroundingText + public override string SurroundingText { get { @@ -1187,26 +1182,15 @@ public TextInputMethodSurroundingText SurroundingText var lineIndex = _textArea.Caret.Line; - var position = _textArea.Caret.Position; - var documentLine = _textArea.Document.GetLineByNumber(lineIndex); var text = _textArea.Document.GetText(documentLine.Offset, documentLine.Length); - return new TextInputMethodSurroundingText - { - AnchorOffset = 0, - CursorOffset = position.Column, - Text = text - }; + return text; } } - public ITextEditable TextEditable - { - get => _textEditable; - set => _textEditable = value; - } + public override TextSelection Selection { get; set; } public void SetTextArea(TextArea textArea) { @@ -1224,19 +1208,19 @@ public void SetTextArea(TextArea textArea) _textArea.SelectionChanged += TextArea_SelectionChanged; } - TextViewVisualChanged?.Invoke(this, EventArgs.Empty); + RaiseTextViewVisualChanged(); - CursorRectangleChanged?.Invoke(this, EventArgs.Empty); + RaiseCursorRectangleChanged(); } private void Caret_PositionChanged(object sender, EventArgs e) { - CursorRectangleChanged?.Invoke(this, e); + RaiseCursorRectangleChanged(); } private void TextArea_SelectionChanged(object sender, EventArgs e) { - SurroundingTextChanged?.Invoke(this, e); + RaiseSurroundingTextChanged(); } public void SelectInSurroundingText(int start, int end) @@ -1253,15 +1237,10 @@ public void SelectInSurroundingText(int start, int end) new TextViewPosition(selection.StartPosition.Line, end)); } - public void SetPreeditText(string text) + public override void SetPreeditText(string text) { } - - public void SetComposingRegion(TextRange? region) - { - //ToDo - } } } diff --git a/test/AvaloniaEdit.Tests/AvaloniaEdit.Tests.csproj b/test/AvaloniaEdit.Tests/AvaloniaEdit.Tests.csproj index c1902d7c..3893f397 100644 --- a/test/AvaloniaEdit.Tests/AvaloniaEdit.Tests.csproj +++ b/test/AvaloniaEdit.Tests/AvaloniaEdit.Tests.csproj @@ -6,8 +6,8 @@ - - + + From 9fce6f24eadfd23939774253e4c1997bed3e11ae Mon Sep 17 00:00:00 2001 From: Benedikt Stebner Date: Thu, 6 Jul 2023 10:20:57 +0200 Subject: [PATCH 2/2] Sync selection --- src/AvaloniaEdit/Editing/TextArea.cs | 52 ++++++++++++---------------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/src/AvaloniaEdit/Editing/TextArea.cs b/src/AvaloniaEdit/Editing/TextArea.cs index b8dcb3d7..101986b3 100644 --- a/src/AvaloniaEdit/Editing/TextArea.cs +++ b/src/AvaloniaEdit/Editing/TextArea.cs @@ -73,7 +73,7 @@ static TextArea() if (!ta.IsReadOnly) { e.Client = ta._imClient; - } + } }); } @@ -627,7 +627,7 @@ public IDisposable AllowCaretOutsideSelection() /// If the textview can be scrolled. /// /// The line to scroll to. - public void ScrollToLine (int line) + public void ScrollToLine(int line) { var viewPortLines = (int)(this as IScrollable).Viewport.Height; @@ -1146,8 +1146,8 @@ public TextAreaTextInputMethodClient() public override Rect CursorRectangle { get - { - if(_textArea == null) + { + if (_textArea == null) { return default; } @@ -1175,7 +1175,7 @@ public override string SurroundingText { get { - if(_textArea == null) + if (_textArea == null) { return default; } @@ -1190,56 +1190,50 @@ public override string SurroundingText } } - public override TextSelection Selection { get; set; } + public override TextSelection Selection + { + get => new TextSelection(_textArea.Caret.Position.Column, _textArea.Caret.Position.Column + _textArea.Selection.Length); + set + { + var selection = _textArea.Selection; + + _textArea.Selection = selection.StartSelectionOrSetEndpoint( + new TextViewPosition(selection.StartPosition.Line, value.Start), + new TextViewPosition(selection.StartPosition.Line, value.End)); + } + } public void SetTextArea(TextArea textArea) { - if(_textArea != null) + if (_textArea != null) { _textArea.Caret.PositionChanged -= Caret_PositionChanged; - _textArea.SelectionChanged -= TextArea_SelectionChanged; } _textArea = textArea; - if(_textArea != null) + if (_textArea != null) { _textArea.Caret.PositionChanged += Caret_PositionChanged; - _textArea.SelectionChanged += TextArea_SelectionChanged; } RaiseTextViewVisualChanged(); RaiseCursorRectangleChanged(); + + RaiseSurroundingTextChanged(); } private void Caret_PositionChanged(object sender, EventArgs e) { RaiseCursorRectangleChanged(); - } - - private void TextArea_SelectionChanged(object sender, EventArgs e) - { RaiseSurroundingTextChanged(); - } - - public void SelectInSurroundingText(int start, int end) - { - if(_textArea == null) - { - return; - } - - var selection = _textArea.Selection; - - _textArea.Selection = _textArea.Selection.StartSelectionOrSetEndpoint( - new TextViewPosition(selection.StartPosition.Line, start), - new TextViewPosition(selection.StartPosition.Line, end)); + RaiseSelectionChanged(); } public override void SetPreeditText(string text) { - + } } }