Merge pull request #715 from irihitech/ip_ime
Try to fix android ime crash
This commit is contained in:
3
Ursa.sln
3
Ursa.sln
@@ -42,8 +42,8 @@ EndProject
|
|||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GitHub Action", "GitHub Action", "{66123AC1-7C8C-4AA0-BBDB-5CC3E647A741}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GitHub Action", "GitHub Action", "{66123AC1-7C8C-4AA0-BBDB-5CC3E647A741}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
.github\workflows\deploy.yml = .github\workflows\deploy.yml
|
.github\workflows\deploy.yml = .github\workflows\deploy.yml
|
||||||
.github\workflows\pack.yml = .github\workflows\pack.yml
|
|
||||||
.github\workflows\pack-nightly.yml = .github\workflows\pack-nightly.yml
|
.github\workflows\pack-nightly.yml = .github\workflows\pack-nightly.yml
|
||||||
|
.github\workflows\pack.yml = .github\workflows\pack.yml
|
||||||
.github\workflows\publish.yml = .github\workflows\publish.yml
|
.github\workflows\publish.yml = .github\workflows\publish.yml
|
||||||
.github\workflows\release-tag.yml = .github\workflows\release-tag.yml
|
.github\workflows\release-tag.yml = .github\workflows\release-tag.yml
|
||||||
.github\workflows\test.yml = .github\workflows\test.yml
|
.github\workflows\test.yml = .github\workflows\test.yml
|
||||||
@@ -69,6 +69,7 @@ Global
|
|||||||
{53B5F277-3AEB-4661-ACAE-15CFFF2ED800}.Release|Any CPU.Build.0 = Release|Any CPU
|
{53B5F277-3AEB-4661-ACAE-15CFFF2ED800}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{3FC76CD9-CE5D-4804-A8D6-4E292EB296AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{3FC76CD9-CE5D-4804-A8D6-4E292EB296AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{3FC76CD9-CE5D-4804-A8D6-4E292EB296AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{3FC76CD9-CE5D-4804-A8D6-4E292EB296AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{3FC76CD9-CE5D-4804-A8D6-4E292EB296AA}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
|
||||||
{3FC76CD9-CE5D-4804-A8D6-4E292EB296AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{3FC76CD9-CE5D-4804-A8D6-4E292EB296AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{3FC76CD9-CE5D-4804-A8D6-4E292EB296AA}.Release|Any CPU.Build.0 = Release|Any CPU
|
{3FC76CD9-CE5D-4804-A8D6-4E292EB296AA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{B6BAB821-A9FE-44F3-B9CD-06E27FDB63F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{B6BAB821-A9FE-44F3-B9CD-06E27FDB63F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>1.11.1</Version>
|
<Version>1.11.1</Version>
|
||||||
<AvaloniaVersion>11.1.1</AvaloniaVersion>
|
<AvaloniaVersion>11.1.3</AvaloniaVersion>
|
||||||
<Authors>IRIHI Technology Co., Ltd.</Authors>
|
<Authors>IRIHI Technology Co., Ltd.</Authors>
|
||||||
<RepositoryUrl>https://github.com/irihitech/Ursa.Avalonia</RepositoryUrl>
|
<RepositoryUrl>https://github.com/irihitech/Ursa.Avalonia</RepositoryUrl>
|
||||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
|
|||||||
@@ -283,11 +283,13 @@ public class IPv4Box: TemplatedControl
|
|||||||
{
|
{
|
||||||
if (e.ClickCount == 1)
|
if (e.ClickCount == 1)
|
||||||
{
|
{
|
||||||
|
_imClient.ShowInputPanel();
|
||||||
_imClient.SetPresenter(presenter);
|
_imClient.SetPresenter(presenter);
|
||||||
presenter.ShowCaret();
|
presenter.ShowCaret();
|
||||||
_currentActivePresenter = presenter;
|
_currentActivePresenter = presenter;
|
||||||
var caretPosition = position.WithX(position.X - presenter.Bounds.X);
|
var caretPosition = position.WithX(position.X - presenter.Bounds.X);
|
||||||
presenter.MoveCaretToPoint(caretPosition);
|
presenter.MoveCaretToPoint(caretPosition);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (e.ClickCount == 2)
|
else if (e.ClickCount == 2)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls.Presenters;
|
using Avalonia.Controls.Presenters;
|
||||||
using Avalonia.Input.TextInput;
|
using Avalonia.Input.TextInput;
|
||||||
|
using Avalonia.Media.TextFormatting;
|
||||||
|
using Avalonia.VisualTree;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace Ursa.Controls;
|
namespace Ursa.Controls;
|
||||||
|
|
||||||
@@ -11,10 +14,95 @@ public class IPv4BoxInputMethodClient: TextInputMethodClient
|
|||||||
public override bool SupportsPreedit => false;
|
public override bool SupportsPreedit => false;
|
||||||
public override bool SupportsSurroundingText => true;
|
public override bool SupportsSurroundingText => true;
|
||||||
|
|
||||||
public override string SurroundingText { get; } = null!;
|
public override string SurroundingText
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_presenter is null)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
var lineIndex = _presenter.TextLayout.GetLineIndexFromCharacterIndex(_presenter.CaretIndex, false);
|
||||||
|
|
||||||
|
var textLine = _presenter.TextLayout.TextLines[lineIndex];
|
||||||
|
|
||||||
|
var lineText = GetTextLineText(textLine);
|
||||||
|
|
||||||
|
return lineText;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetTextLineText(TextLine textLine)
|
||||||
|
{
|
||||||
|
if (textLine.Length == 0)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
var builder = new StringBuilder();
|
||||||
|
|
||||||
|
foreach (var run in textLine.TextRuns)
|
||||||
|
{
|
||||||
|
if (run.Length > 0)
|
||||||
|
{
|
||||||
|
#if NET6_0_OR_GREATER
|
||||||
|
builder.Append(run.Text.Span);
|
||||||
|
#else
|
||||||
|
builder.Append(run.Text.Span.ToArray());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var lineText = builder.ToString();
|
||||||
|
|
||||||
|
return lineText;
|
||||||
|
}
|
||||||
|
|
||||||
public override Rect CursorRectangle { get; } = new();
|
public override Rect CursorRectangle { get; } = new();
|
||||||
public override TextSelection Selection { get; set; }
|
public override TextSelection Selection
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_presenter is null)
|
||||||
|
{
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
|
||||||
|
var lineIndex = _presenter.TextLayout.GetLineIndexFromCharacterIndex(_presenter.CaretIndex, false);
|
||||||
|
|
||||||
|
var textLine = _presenter.TextLayout.TextLines[lineIndex];
|
||||||
|
|
||||||
|
var lineStart = textLine.FirstTextSourceIndex;
|
||||||
|
|
||||||
|
var selectionStart = Math.Max(0, _presenter.SelectionStart - lineStart);
|
||||||
|
|
||||||
|
var selectionEnd = Math.Max(0, _presenter.SelectionEnd - lineStart);
|
||||||
|
|
||||||
|
return new TextSelection(selectionStart, selectionEnd);
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_presenter is null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var lineIndex = _presenter.TextLayout.GetLineIndexFromCharacterIndex(_presenter.CaretIndex, false);
|
||||||
|
|
||||||
|
var textLine = _presenter.TextLayout.TextLines[lineIndex];
|
||||||
|
|
||||||
|
var lineStart = textLine.FirstTextSourceIndex;
|
||||||
|
|
||||||
|
var selectionStart = lineStart + value.Start;
|
||||||
|
var selectionEnd = lineStart + value.End;
|
||||||
|
|
||||||
|
_presenter.SelectionStart = selectionStart;
|
||||||
|
_presenter.SelectionEnd = selectionEnd;
|
||||||
|
|
||||||
|
RaiseSelectionChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
public void SetPresenter(TextPresenter? presenter)
|
public void SetPresenter(TextPresenter? presenter)
|
||||||
{
|
{
|
||||||
_presenter = presenter;
|
_presenter = presenter;
|
||||||
|
|||||||
Reference in New Issue
Block a user