Skip to content

Commit

Permalink
Merge pull request #349 from AvaloniaUI/update-to-avalonia11
Browse files Browse the repository at this point in the history
Update to Avalonia 11
  • Loading branch information
Gillibald authored Jul 6, 2023
2 parents 870f53a + 9fce6f2 commit 0d7f316
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 64 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-rc1.1</AvaloniaVersion>
<AvaloniaVersion>11.0.0</AvaloniaVersion>
<TextMateSharpVersion>1.0.55</TextMateSharpVersion>
<VersionSuffix>beta</VersionSuffix>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/AvaloniaEdit.Demo/AvaloniaEdit.Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="$(AvaloniaVersion)"/>
<PackageReference Include="Avalonia.Themes.Fluent" Version="$(AvaloniaVersion)"/>
<ProjectReference Include="..\AvaloniaEdit\AvaloniaEdit.csproj" />
<ProjectReference Include="..\AvaloniaEdit.TextMate\AvaloniaEdit.TextMate.csproj" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/AvaloniaEdit.TextMate/AvaloniaEdit.TextMate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="TextMateSharp" Version="$(TextMateSharpVersion)" />
<PackageReference Include="TextMateSharp.Grammars" Version="$(TextMateSharpVersion)" />
</ItemGroup>
Expand Down
91 changes: 32 additions & 59 deletions src/AvaloniaEdit/Editing/TextArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static TextArea()
if (!ta.IsReadOnly)
{
e.Client = ta._imClient;
}
}
});
}

Expand Down Expand Up @@ -627,7 +627,7 @@ public IDisposable AllowCaretOutsideSelection()
/// If the textview can be scrolled.
/// </summary>
/// <param name="line">The line to scroll to.</param>
public void ScrollToLine (int line)
public void ScrollToLine(int line)
{
var viewPortLines = (int)(this as IScrollable).Viewport.Height;

Expand Down Expand Up @@ -1134,25 +1134,20 @@ public void RaiseScrollInvalidated(EventArgs e)
_logicalScrollable?.RaiseScrollInvalidated(e);
}

private class TextAreaTextInputMethodClient : ITextInputMethodClient
private class TextAreaTextInputMethodClient : TextInputMethodClient
{
private ITextEditable _textEditable;
private TextArea _textArea;

public TextAreaTextInputMethodClient()
{

}

public event EventHandler CursorRectangleChanged;
public event EventHandler TextViewVisualChanged;
public event EventHandler SurroundingTextChanged;

public Rect CursorRectangle
public override Rect CursorRectangle
{
get
{
if(_textArea == null)
{
if (_textArea == null)
{
return default;
}
Expand All @@ -1170,97 +1165,75 @@ 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
{
if(_textArea == null)
if (_textArea == null)
{
return default;
}

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
public override TextSelection Selection
{
get => _textEditable;
set => _textEditable = value;
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;
}

TextViewVisualChanged?.Invoke(this, EventArgs.Empty);
RaiseTextViewVisualChanged();

CursorRectangleChanged?.Invoke(this, EventArgs.Empty);
}

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)
private void Caret_PositionChanged(object sender, EventArgs e)
{
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));
RaiseCursorRectangleChanged();
RaiseSurroundingTextChanged();
RaiseSelectionChanged();
}

public void SetPreeditText(string text)
public override void SetPreeditText(string text)
{

}

public void SetComposingRegion(TextRange? region)
{
//ToDo
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/AvaloniaEdit.Tests/AvaloniaEdit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Themes.Simple" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Themes.Simple" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Headless.NUnit" Version="$(AvaloniaVersion)" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Moq" Version="4.18.4" />
Expand Down

0 comments on commit 0d7f316

Please sign in to comment.