2025-12-19 09:30:16 +00:00
|
|
|
// Licensed to the .NET Foundation under one or more agreements.
|
|
|
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
|
|
|
|
2026-01-16 04:39:50 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Microsoft.Maui.Controls;
|
|
|
|
|
using Microsoft.Maui.Graphics;
|
2026-01-17 15:19:03 +00:00
|
|
|
using Microsoft.Maui.Platform.Linux;
|
2026-01-16 04:39:50 +00:00
|
|
|
using Microsoft.Maui.Platform.Linux.Rendering;
|
2026-01-17 02:23:05 +00:00
|
|
|
using Microsoft.Maui.Platform.Linux.Services;
|
2025-12-19 09:30:16 +00:00
|
|
|
using SkiaSharp;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.Maui.Platform;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-21 13:26:56 -05:00
|
|
|
/// Skia-rendered multiline text editor control with full XAML styling support.
|
2026-01-17 02:23:05 +00:00
|
|
|
/// Implements IInputContext for IME (Input Method Editor) support.
|
2025-12-19 09:30:16 +00:00
|
|
|
/// </summary>
|
2026-03-06 22:36:23 -05:00
|
|
|
public partial class SkiaEditor : SkiaView, IInputContext
|
2025-12-19 09:30:16 +00:00
|
|
|
{
|
2025-12-21 13:26:56 -05:00
|
|
|
#region BindableProperties
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for Text.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty TextProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(Text),
|
|
|
|
|
typeof(string),
|
|
|
|
|
typeof(SkiaEditor),
|
|
|
|
|
"",
|
Fix Views: SkiaEntry, SkiaEditor, SkiaShell, SkiaWebView
- SkiaEntry.cs: TextProperty BindingMode.OneWay (was TwoWay)
- SkiaEditor.cs: All BindingModes corrected (Text=OneWay, others=TwoWay)
- SkiaShell.cs: Added FlyoutTextColor, ContentBackgroundColor properties,
route registration system, query parameter support, OnScroll handler
- SkiaWebView.cs: Full rewrite with X11 embedding, GTK window positioning,
hardware acceleration settings, load-changed callbacks, position tracking
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 14:27:33 -05:00
|
|
|
BindingMode.OneWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaEditor)b).OnTextPropertyChanged((string)o, (string)n));
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for Placeholder.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty PlaceholderProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(Placeholder),
|
|
|
|
|
typeof(string),
|
|
|
|
|
typeof(SkiaEditor),
|
|
|
|
|
"",
|
Fix Views: SkiaEntry, SkiaEditor, SkiaShell, SkiaWebView
- SkiaEntry.cs: TextProperty BindingMode.OneWay (was TwoWay)
- SkiaEditor.cs: All BindingModes corrected (Text=OneWay, others=TwoWay)
- SkiaShell.cs: Added FlyoutTextColor, ContentBackgroundColor properties,
route registration system, query parameter support, OnScroll handler
- SkiaWebView.cs: Full rewrite with X11 embedding, GTK window positioning,
hardware acceleration settings, load-changed callbacks, position tracking
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 14:27:33 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaEditor)b).Invalidate());
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for TextColor.
|
2026-01-17 01:43:42 +00:00
|
|
|
/// Default is null to match MAUI Editor.TextColor (falls back to platform default).
|
2025-12-21 13:26:56 -05:00
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty TextColorProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(TextColor),
|
2026-01-16 04:39:50 +00:00
|
|
|
typeof(Color),
|
2025-12-21 13:26:56 -05:00
|
|
|
typeof(SkiaEditor),
|
2026-01-17 01:43:42 +00:00
|
|
|
null,
|
Fix Views: SkiaEntry, SkiaEditor, SkiaShell, SkiaWebView
- SkiaEntry.cs: TextProperty BindingMode.OneWay (was TwoWay)
- SkiaEditor.cs: All BindingModes corrected (Text=OneWay, others=TwoWay)
- SkiaShell.cs: Added FlyoutTextColor, ContentBackgroundColor properties,
route registration system, query parameter support, OnScroll handler
- SkiaWebView.cs: Full rewrite with X11 embedding, GTK window positioning,
hardware acceleration settings, load-changed callbacks, position tracking
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 14:27:33 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaEditor)b).Invalidate());
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for PlaceholderColor.
|
2026-01-17 01:43:42 +00:00
|
|
|
/// Default is null to match MAUI Editor.PlaceholderColor (falls back to platform default).
|
2025-12-21 13:26:56 -05:00
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty PlaceholderColorProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(PlaceholderColor),
|
2026-01-16 04:39:50 +00:00
|
|
|
typeof(Color),
|
2025-12-21 13:26:56 -05:00
|
|
|
typeof(SkiaEditor),
|
2026-01-17 01:43:42 +00:00
|
|
|
null,
|
Fix Views: SkiaEntry, SkiaEditor, SkiaShell, SkiaWebView
- SkiaEntry.cs: TextProperty BindingMode.OneWay (was TwoWay)
- SkiaEditor.cs: All BindingModes corrected (Text=OneWay, others=TwoWay)
- SkiaShell.cs: Added FlyoutTextColor, ContentBackgroundColor properties,
route registration system, query parameter support, OnScroll handler
- SkiaWebView.cs: Full rewrite with X11 embedding, GTK window positioning,
hardware acceleration settings, load-changed callbacks, position tracking
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 14:27:33 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaEditor)b).Invalidate());
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for BorderColor.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty BorderColorProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(BorderColor),
|
2026-01-16 04:39:50 +00:00
|
|
|
typeof(Color),
|
2025-12-21 13:26:56 -05:00
|
|
|
typeof(SkiaEditor),
|
2026-01-17 15:06:39 +00:00
|
|
|
Colors.Transparent,
|
Fix Views: SkiaEntry, SkiaEditor, SkiaShell, SkiaWebView
- SkiaEntry.cs: TextProperty BindingMode.OneWay (was TwoWay)
- SkiaEditor.cs: All BindingModes corrected (Text=OneWay, others=TwoWay)
- SkiaShell.cs: Added FlyoutTextColor, ContentBackgroundColor properties,
route registration system, query parameter support, OnScroll handler
- SkiaWebView.cs: Full rewrite with X11 embedding, GTK window positioning,
hardware acceleration settings, load-changed callbacks, position tracking
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 14:27:33 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaEditor)b).Invalidate());
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for SelectionColor.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty SelectionColorProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(SelectionColor),
|
2026-01-16 04:39:50 +00:00
|
|
|
typeof(Color),
|
2025-12-21 13:26:56 -05:00
|
|
|
typeof(SkiaEditor),
|
2026-01-16 04:39:50 +00:00
|
|
|
Color.FromRgba(0x21, 0x96, 0xF3, 0x60),
|
Fix Views: SkiaEntry, SkiaEditor, SkiaShell, SkiaWebView
- SkiaEntry.cs: TextProperty BindingMode.OneWay (was TwoWay)
- SkiaEditor.cs: All BindingModes corrected (Text=OneWay, others=TwoWay)
- SkiaShell.cs: Added FlyoutTextColor, ContentBackgroundColor properties,
route registration system, query parameter support, OnScroll handler
- SkiaWebView.cs: Full rewrite with X11 embedding, GTK window positioning,
hardware acceleration settings, load-changed callbacks, position tracking
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 14:27:33 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaEditor)b).Invalidate());
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for CursorColor.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty CursorColorProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(CursorColor),
|
2026-01-16 04:39:50 +00:00
|
|
|
typeof(Color),
|
2025-12-21 13:26:56 -05:00
|
|
|
typeof(SkiaEditor),
|
2026-01-16 04:39:50 +00:00
|
|
|
Color.FromRgb(0x21, 0x96, 0xF3),
|
Fix Views: SkiaEntry, SkiaEditor, SkiaShell, SkiaWebView
- SkiaEntry.cs: TextProperty BindingMode.OneWay (was TwoWay)
- SkiaEditor.cs: All BindingModes corrected (Text=OneWay, others=TwoWay)
- SkiaShell.cs: Added FlyoutTextColor, ContentBackgroundColor properties,
route registration system, query parameter support, OnScroll handler
- SkiaWebView.cs: Full rewrite with X11 embedding, GTK window positioning,
hardware acceleration settings, load-changed callbacks, position tracking
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 14:27:33 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaEditor)b).Invalidate());
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for FontFamily.
|
2026-01-17 01:43:42 +00:00
|
|
|
/// Default is empty string to match MAUI Editor.FontFamily (falls back to platform default).
|
2025-12-21 13:26:56 -05:00
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty FontFamilyProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(FontFamily),
|
|
|
|
|
typeof(string),
|
|
|
|
|
typeof(SkiaEditor),
|
2026-01-17 01:43:42 +00:00
|
|
|
string.Empty,
|
Fix Views: SkiaEntry, SkiaEditor, SkiaShell, SkiaWebView
- SkiaEntry.cs: TextProperty BindingMode.OneWay (was TwoWay)
- SkiaEditor.cs: All BindingModes corrected (Text=OneWay, others=TwoWay)
- SkiaShell.cs: Added FlyoutTextColor, ContentBackgroundColor properties,
route registration system, query parameter support, OnScroll handler
- SkiaWebView.cs: Full rewrite with X11 embedding, GTK window positioning,
hardware acceleration settings, load-changed callbacks, position tracking
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 14:27:33 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaEditor)b).InvalidateMeasure());
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for FontSize.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty FontSizeProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(FontSize),
|
2026-01-16 04:39:50 +00:00
|
|
|
typeof(double),
|
2025-12-21 13:26:56 -05:00
|
|
|
typeof(SkiaEditor),
|
2026-01-16 04:39:50 +00:00
|
|
|
14.0,
|
Fix Views: SkiaEntry, SkiaEditor, SkiaShell, SkiaWebView
- SkiaEntry.cs: TextProperty BindingMode.OneWay (was TwoWay)
- SkiaEditor.cs: All BindingModes corrected (Text=OneWay, others=TwoWay)
- SkiaShell.cs: Added FlyoutTextColor, ContentBackgroundColor properties,
route registration system, query parameter support, OnScroll handler
- SkiaWebView.cs: Full rewrite with X11 embedding, GTK window positioning,
hardware acceleration settings, load-changed callbacks, position tracking
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 14:27:33 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaEditor)b).InvalidateMeasure());
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for LineHeight.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty LineHeightProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(LineHeight),
|
2026-01-16 04:39:50 +00:00
|
|
|
typeof(double),
|
2025-12-21 13:26:56 -05:00
|
|
|
typeof(SkiaEditor),
|
2026-01-16 04:39:50 +00:00
|
|
|
1.4,
|
Fix Views: SkiaEntry, SkiaEditor, SkiaShell, SkiaWebView
- SkiaEntry.cs: TextProperty BindingMode.OneWay (was TwoWay)
- SkiaEditor.cs: All BindingModes corrected (Text=OneWay, others=TwoWay)
- SkiaShell.cs: Added FlyoutTextColor, ContentBackgroundColor properties,
route registration system, query parameter support, OnScroll handler
- SkiaWebView.cs: Full rewrite with X11 embedding, GTK window positioning,
hardware acceleration settings, load-changed callbacks, position tracking
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 14:27:33 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaEditor)b).InvalidateMeasure());
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for CornerRadius.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty CornerRadiusProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(CornerRadius),
|
2026-01-16 04:39:50 +00:00
|
|
|
typeof(double),
|
2025-12-21 13:26:56 -05:00
|
|
|
typeof(SkiaEditor),
|
2026-01-16 04:39:50 +00:00
|
|
|
4.0,
|
Fix Views: SkiaEntry, SkiaEditor, SkiaShell, SkiaWebView
- SkiaEntry.cs: TextProperty BindingMode.OneWay (was TwoWay)
- SkiaEditor.cs: All BindingModes corrected (Text=OneWay, others=TwoWay)
- SkiaShell.cs: Added FlyoutTextColor, ContentBackgroundColor properties,
route registration system, query parameter support, OnScroll handler
- SkiaWebView.cs: Full rewrite with X11 embedding, GTK window positioning,
hardware acceleration settings, load-changed callbacks, position tracking
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 14:27:33 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaEditor)b).Invalidate());
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for Padding.
|
|
|
|
|
/// </summary>
|
2026-01-16 04:39:50 +00:00
|
|
|
public static new readonly BindableProperty PaddingProperty =
|
2025-12-21 13:26:56 -05:00
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(Padding),
|
2026-01-16 04:39:50 +00:00
|
|
|
typeof(Thickness),
|
2025-12-21 13:26:56 -05:00
|
|
|
typeof(SkiaEditor),
|
2026-01-16 04:39:50 +00:00
|
|
|
new Thickness(12),
|
Fix Views: SkiaEntry, SkiaEditor, SkiaShell, SkiaWebView
- SkiaEntry.cs: TextProperty BindingMode.OneWay (was TwoWay)
- SkiaEditor.cs: All BindingModes corrected (Text=OneWay, others=TwoWay)
- SkiaShell.cs: Added FlyoutTextColor, ContentBackgroundColor properties,
route registration system, query parameter support, OnScroll handler
- SkiaWebView.cs: Full rewrite with X11 embedding, GTK window positioning,
hardware acceleration settings, load-changed callbacks, position tracking
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 14:27:33 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaEditor)b).InvalidateMeasure());
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for IsReadOnly.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty IsReadOnlyProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(IsReadOnly),
|
|
|
|
|
typeof(bool),
|
|
|
|
|
typeof(SkiaEditor),
|
|
|
|
|
false,
|
Fix Views: SkiaEntry, SkiaEditor, SkiaShell, SkiaWebView
- SkiaEntry.cs: TextProperty BindingMode.OneWay (was TwoWay)
- SkiaEditor.cs: All BindingModes corrected (Text=OneWay, others=TwoWay)
- SkiaShell.cs: Added FlyoutTextColor, ContentBackgroundColor properties,
route registration system, query parameter support, OnScroll handler
- SkiaWebView.cs: Full rewrite with X11 embedding, GTK window positioning,
hardware acceleration settings, load-changed callbacks, position tracking
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 14:27:33 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaEditor)b).Invalidate());
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for MaxLength.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty MaxLengthProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(MaxLength),
|
|
|
|
|
typeof(int),
|
|
|
|
|
typeof(SkiaEditor),
|
Fix Views: SkiaEntry, SkiaEditor, SkiaShell, SkiaWebView
- SkiaEntry.cs: TextProperty BindingMode.OneWay (was TwoWay)
- SkiaEditor.cs: All BindingModes corrected (Text=OneWay, others=TwoWay)
- SkiaShell.cs: Added FlyoutTextColor, ContentBackgroundColor properties,
route registration system, query parameter support, OnScroll handler
- SkiaWebView.cs: Full rewrite with X11 embedding, GTK window positioning,
hardware acceleration settings, load-changed callbacks, position tracking
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 14:27:33 -05:00
|
|
|
-1,
|
|
|
|
|
BindingMode.TwoWay);
|
2025-12-21 13:26:56 -05:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for AutoSize.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty AutoSizeProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(AutoSize),
|
|
|
|
|
typeof(bool),
|
|
|
|
|
typeof(SkiaEditor),
|
|
|
|
|
false,
|
Fix Views: SkiaEntry, SkiaEditor, SkiaShell, SkiaWebView
- SkiaEntry.cs: TextProperty BindingMode.OneWay (was TwoWay)
- SkiaEditor.cs: All BindingModes corrected (Text=OneWay, others=TwoWay)
- SkiaShell.cs: Added FlyoutTextColor, ContentBackgroundColor properties,
route registration system, query parameter support, OnScroll handler
- SkiaWebView.cs: Full rewrite with X11 embedding, GTK window positioning,
hardware acceleration settings, load-changed callbacks, position tracking
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 14:27:33 -05:00
|
|
|
BindingMode.TwoWay,
|
2025-12-21 13:26:56 -05:00
|
|
|
propertyChanged: (b, o, n) => ((SkiaEditor)b).InvalidateMeasure());
|
|
|
|
|
|
2026-01-16 04:39:50 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for FontAttributes.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty FontAttributesProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(FontAttributes),
|
|
|
|
|
typeof(FontAttributes),
|
|
|
|
|
typeof(SkiaEditor),
|
|
|
|
|
FontAttributes.None,
|
|
|
|
|
BindingMode.TwoWay,
|
|
|
|
|
propertyChanged: (b, o, n) => ((SkiaEditor)b).InvalidateMeasure());
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for CharacterSpacing.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty CharacterSpacingProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(CharacterSpacing),
|
|
|
|
|
typeof(double),
|
|
|
|
|
typeof(SkiaEditor),
|
|
|
|
|
0.0,
|
|
|
|
|
BindingMode.TwoWay,
|
|
|
|
|
propertyChanged: (b, o, n) => ((SkiaEditor)b).Invalidate());
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for IsTextPredictionEnabled.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty IsTextPredictionEnabledProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(IsTextPredictionEnabled),
|
|
|
|
|
typeof(bool),
|
|
|
|
|
typeof(SkiaEditor),
|
|
|
|
|
true);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for IsSpellCheckEnabled.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty IsSpellCheckEnabledProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(IsSpellCheckEnabled),
|
|
|
|
|
typeof(bool),
|
|
|
|
|
typeof(SkiaEditor),
|
|
|
|
|
true);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for SelectionLength.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty SelectionLengthProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(SelectionLength),
|
|
|
|
|
typeof(int),
|
|
|
|
|
typeof(SkiaEditor),
|
|
|
|
|
0,
|
|
|
|
|
BindingMode.TwoWay,
|
|
|
|
|
propertyChanged: (b, o, n) => ((SkiaEditor)b).Invalidate());
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for CursorPosition.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty CursorPositionProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(CursorPosition),
|
|
|
|
|
typeof(int),
|
|
|
|
|
typeof(SkiaEditor),
|
|
|
|
|
0,
|
|
|
|
|
BindingMode.TwoWay,
|
|
|
|
|
propertyChanged: (b, o, n) => ((SkiaEditor)b).OnCursorPositionPropertyChanged((int)n));
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for HorizontalTextAlignment.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty HorizontalTextAlignmentProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(HorizontalTextAlignment),
|
|
|
|
|
typeof(TextAlignment),
|
|
|
|
|
typeof(SkiaEditor),
|
|
|
|
|
TextAlignment.Start,
|
|
|
|
|
BindingMode.TwoWay,
|
|
|
|
|
propertyChanged: (b, o, n) => ((SkiaEditor)b).Invalidate());
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for VerticalTextAlignment.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty VerticalTextAlignmentProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(VerticalTextAlignment),
|
|
|
|
|
typeof(TextAlignment),
|
|
|
|
|
typeof(SkiaEditor),
|
|
|
|
|
TextAlignment.Start,
|
|
|
|
|
BindingMode.TwoWay,
|
|
|
|
|
propertyChanged: (b, o, n) => ((SkiaEditor)b).Invalidate());
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for background color exposed for MAUI binding.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static readonly BindableProperty EditorBackgroundColorProperty =
|
|
|
|
|
BindableProperty.Create(
|
|
|
|
|
nameof(EditorBackgroundColor),
|
|
|
|
|
typeof(Color),
|
|
|
|
|
typeof(SkiaEditor),
|
2026-01-17 15:06:39 +00:00
|
|
|
Colors.Transparent,
|
2026-01-16 04:39:50 +00:00
|
|
|
BindingMode.TwoWay,
|
|
|
|
|
propertyChanged: (b, o, n) => ((SkiaEditor)b).Invalidate());
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Color Conversion Helper
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Converts a MAUI Color to SkiaSharp SKColor.
|
|
|
|
|
/// </summary>
|
2026-03-06 22:36:23 -05:00
|
|
|
private static SKColor ToSKColor(Color? color) => TextRenderingHelper.ToSKColor(color, SKColors.Transparent);
|
2026-01-16 04:39:50 +00:00
|
|
|
|
2026-01-17 01:43:42 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the effective text color (platform default black if null).
|
|
|
|
|
/// </summary>
|
|
|
|
|
private SKColor GetEffectiveTextColor()
|
|
|
|
|
{
|
2026-01-17 03:36:37 +00:00
|
|
|
return TextColor != null ? ToSKColor(TextColor) : SkiaTheme.TextPrimarySK;
|
2026-01-17 01:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the effective placeholder color (platform default gray if null).
|
|
|
|
|
/// </summary>
|
|
|
|
|
private SKColor GetEffectivePlaceholderColor()
|
|
|
|
|
{
|
2026-01-17 03:36:37 +00:00
|
|
|
return PlaceholderColor != null ? ToSKColor(PlaceholderColor) : SkiaTheme.TextPlaceholderSK;
|
2026-01-17 01:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the effective font family (platform default "Sans" if empty).
|
|
|
|
|
/// </summary>
|
2026-03-06 22:36:23 -05:00
|
|
|
private string GetEffectiveFontFamily() => TextRenderingHelper.GetEffectiveFontFamily(FontFamily);
|
2026-01-17 01:43:42 +00:00
|
|
|
|
2026-01-17 02:23:05 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Determines if text should be rendered right-to-left based on FlowDirection.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private bool IsRightToLeft()
|
|
|
|
|
{
|
|
|
|
|
return FlowDirection == FlowDirection.RightToLeft;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the horizontal alignment accounting for FlowDirection.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private float GetEffectiveTextX(SKRect contentBounds, float textWidth)
|
|
|
|
|
{
|
|
|
|
|
bool isRtl = IsRightToLeft();
|
|
|
|
|
|
|
|
|
|
return HorizontalTextAlignment switch
|
|
|
|
|
{
|
|
|
|
|
TextAlignment.Start => isRtl ? contentBounds.Right - textWidth : contentBounds.Left,
|
|
|
|
|
TextAlignment.Center => contentBounds.MidX - textWidth / 2,
|
|
|
|
|
TextAlignment.End => isRtl ? contentBounds.Left : contentBounds.Right - textWidth,
|
|
|
|
|
_ => isRtl ? contentBounds.Right - textWidth : contentBounds.Left
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the text content.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Text
|
|
|
|
|
{
|
|
|
|
|
get => (string)GetValue(TextProperty);
|
|
|
|
|
set => SetValue(TextProperty, value);
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the placeholder text.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Placeholder
|
|
|
|
|
{
|
|
|
|
|
get => (string)GetValue(PlaceholderProperty);
|
|
|
|
|
set => SetValue(PlaceholderProperty, value);
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
/// <summary>
|
2026-01-17 01:43:42 +00:00
|
|
|
/// Gets or sets the text color. Null means platform default (black).
|
2025-12-21 13:26:56 -05:00
|
|
|
/// </summary>
|
2026-01-17 01:43:42 +00:00
|
|
|
public Color? TextColor
|
2025-12-19 09:30:16 +00:00
|
|
|
{
|
2026-01-17 01:43:42 +00:00
|
|
|
get => (Color?)GetValue(TextColorProperty);
|
2025-12-21 13:26:56 -05:00
|
|
|
set => SetValue(TextColorProperty, value);
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
/// <summary>
|
2026-01-17 01:43:42 +00:00
|
|
|
/// Gets or sets the placeholder color. Null means platform default (gray).
|
2025-12-21 13:26:56 -05:00
|
|
|
/// </summary>
|
2026-01-17 01:43:42 +00:00
|
|
|
public Color? PlaceholderColor
|
2025-12-21 13:26:56 -05:00
|
|
|
{
|
2026-01-17 01:43:42 +00:00
|
|
|
get => (Color?)GetValue(PlaceholderColorProperty);
|
2025-12-21 13:26:56 -05:00
|
|
|
set => SetValue(PlaceholderColorProperty, value);
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the border color.
|
|
|
|
|
/// </summary>
|
2026-01-16 04:39:50 +00:00
|
|
|
public Color BorderColor
|
2025-12-21 13:26:56 -05:00
|
|
|
{
|
2026-01-16 04:39:50 +00:00
|
|
|
get => (Color)GetValue(BorderColorProperty);
|
2025-12-21 13:26:56 -05:00
|
|
|
set => SetValue(BorderColorProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the selection color.
|
|
|
|
|
/// </summary>
|
2026-01-16 04:39:50 +00:00
|
|
|
public Color SelectionColor
|
2025-12-21 13:26:56 -05:00
|
|
|
{
|
2026-01-16 04:39:50 +00:00
|
|
|
get => (Color)GetValue(SelectionColorProperty);
|
2025-12-21 13:26:56 -05:00
|
|
|
set => SetValue(SelectionColorProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the cursor color.
|
|
|
|
|
/// </summary>
|
2026-01-16 04:39:50 +00:00
|
|
|
public Color CursorColor
|
2025-12-21 13:26:56 -05:00
|
|
|
{
|
2026-01-16 04:39:50 +00:00
|
|
|
get => (Color)GetValue(CursorColorProperty);
|
2025-12-21 13:26:56 -05:00
|
|
|
set => SetValue(CursorColorProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the font family.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string FontFamily
|
|
|
|
|
{
|
|
|
|
|
get => (string)GetValue(FontFamilyProperty);
|
|
|
|
|
set => SetValue(FontFamilyProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the font size.
|
|
|
|
|
/// </summary>
|
2026-01-16 04:39:50 +00:00
|
|
|
public double FontSize
|
2025-12-21 13:26:56 -05:00
|
|
|
{
|
2026-01-16 04:39:50 +00:00
|
|
|
get => (double)GetValue(FontSizeProperty);
|
2025-12-21 13:26:56 -05:00
|
|
|
set => SetValue(FontSizeProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the line height multiplier.
|
|
|
|
|
/// </summary>
|
2026-01-16 04:39:50 +00:00
|
|
|
public double LineHeight
|
2025-12-19 09:30:16 +00:00
|
|
|
{
|
2026-01-16 04:39:50 +00:00
|
|
|
get => (double)GetValue(LineHeightProperty);
|
2025-12-21 13:26:56 -05:00
|
|
|
set => SetValue(LineHeightProperty, value);
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the corner radius.
|
|
|
|
|
/// </summary>
|
2026-01-16 04:39:50 +00:00
|
|
|
public double CornerRadius
|
2025-12-21 13:26:56 -05:00
|
|
|
{
|
2026-01-16 04:39:50 +00:00
|
|
|
get => (double)GetValue(CornerRadiusProperty);
|
2025-12-21 13:26:56 -05:00
|
|
|
set => SetValue(CornerRadiusProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the padding.
|
|
|
|
|
/// </summary>
|
2026-01-16 04:39:50 +00:00
|
|
|
public new Thickness Padding
|
2025-12-21 13:26:56 -05:00
|
|
|
{
|
2026-01-16 04:39:50 +00:00
|
|
|
get => (Thickness)GetValue(PaddingProperty);
|
2025-12-21 13:26:56 -05:00
|
|
|
set => SetValue(PaddingProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets whether the editor is read-only.
|
|
|
|
|
/// </summary>
|
2025-12-19 09:30:16 +00:00
|
|
|
public bool IsReadOnly
|
|
|
|
|
{
|
2025-12-21 13:26:56 -05:00
|
|
|
get => (bool)GetValue(IsReadOnlyProperty);
|
|
|
|
|
set => SetValue(IsReadOnlyProperty, value);
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the maximum length. -1 for unlimited.
|
|
|
|
|
/// </summary>
|
2025-12-19 09:30:16 +00:00
|
|
|
public int MaxLength
|
|
|
|
|
{
|
2025-12-21 13:26:56 -05:00
|
|
|
get => (int)GetValue(MaxLengthProperty);
|
|
|
|
|
set => SetValue(MaxLengthProperty, value);
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets whether the editor auto-sizes to content.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool AutoSize
|
|
|
|
|
{
|
|
|
|
|
get => (bool)GetValue(AutoSizeProperty);
|
|
|
|
|
set => SetValue(AutoSizeProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-16 04:39:50 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the font attributes (Bold, Italic, etc.).
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FontAttributes FontAttributes
|
|
|
|
|
{
|
|
|
|
|
get => (FontAttributes)GetValue(FontAttributesProperty);
|
|
|
|
|
set => SetValue(FontAttributesProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the character spacing.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public double CharacterSpacing
|
|
|
|
|
{
|
|
|
|
|
get => (double)GetValue(CharacterSpacingProperty);
|
|
|
|
|
set => SetValue(CharacterSpacingProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets whether text prediction is enabled.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsTextPredictionEnabled
|
|
|
|
|
{
|
|
|
|
|
get => (bool)GetValue(IsTextPredictionEnabledProperty);
|
|
|
|
|
set => SetValue(IsTextPredictionEnabledProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets whether spell check is enabled.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsSpellCheckEnabled
|
|
|
|
|
{
|
|
|
|
|
get => (bool)GetValue(IsSpellCheckEnabledProperty);
|
|
|
|
|
set => SetValue(IsSpellCheckEnabledProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the cursor position.
|
|
|
|
|
/// </summary>
|
2025-12-19 09:30:16 +00:00
|
|
|
public int CursorPosition
|
|
|
|
|
{
|
|
|
|
|
get => _cursorPosition;
|
|
|
|
|
set
|
|
|
|
|
{
|
2026-01-16 04:39:50 +00:00
|
|
|
var newValue = Math.Clamp(value, 0, (Text ?? "").Length);
|
|
|
|
|
if (_cursorPosition != newValue)
|
|
|
|
|
{
|
|
|
|
|
_cursorPosition = newValue;
|
|
|
|
|
SetValue(CursorPositionProperty, newValue);
|
|
|
|
|
EnsureCursorVisible();
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the selection length.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int SelectionLength
|
|
|
|
|
{
|
|
|
|
|
get => _selectionLength;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_selectionLength != value)
|
|
|
|
|
{
|
|
|
|
|
_selectionLength = value;
|
|
|
|
|
SetValue(SelectionLengthProperty, value);
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-16 04:39:50 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the horizontal text alignment.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public TextAlignment HorizontalTextAlignment
|
|
|
|
|
{
|
|
|
|
|
get => (TextAlignment)GetValue(HorizontalTextAlignmentProperty);
|
|
|
|
|
set => SetValue(HorizontalTextAlignmentProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the vertical text alignment.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public TextAlignment VerticalTextAlignment
|
|
|
|
|
{
|
|
|
|
|
get => (TextAlignment)GetValue(VerticalTextAlignmentProperty);
|
|
|
|
|
set => SetValue(VerticalTextAlignmentProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the editor background color (MAUI-exposed property).
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Color EditorBackgroundColor
|
|
|
|
|
{
|
|
|
|
|
get => (Color)GetValue(EditorBackgroundColorProperty);
|
|
|
|
|
set => SetValue(EditorBackgroundColorProperty, value);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
#endregion
|
|
|
|
|
|
2026-01-16 04:39:50 +00:00
|
|
|
private void OnCursorPositionPropertyChanged(int newValue)
|
|
|
|
|
{
|
|
|
|
|
var clampedValue = Math.Clamp(newValue, 0, (Text ?? "").Length);
|
|
|
|
|
if (_cursorPosition != clampedValue)
|
|
|
|
|
{
|
|
|
|
|
_cursorPosition = clampedValue;
|
|
|
|
|
EnsureCursorVisible();
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
private int _cursorPosition;
|
|
|
|
|
private int _selectionStart = -1;
|
|
|
|
|
private int _selectionLength;
|
|
|
|
|
private float _scrollOffsetY;
|
|
|
|
|
private bool _cursorVisible = true;
|
|
|
|
|
private DateTime _lastCursorBlink = DateTime.Now;
|
|
|
|
|
private List<string> _lines = new() { "" };
|
|
|
|
|
private float _wrapWidth = 0; // Available width for word wrapping
|
|
|
|
|
private bool _isSelecting; // For mouse-based text selection
|
|
|
|
|
private DateTime _lastClickTime = DateTime.MinValue;
|
|
|
|
|
private float _lastClickX;
|
|
|
|
|
private float _lastClickY;
|
|
|
|
|
private const double DoubleClickThresholdMs = 400;
|
|
|
|
|
|
2026-01-17 02:23:05 +00:00
|
|
|
// IME (Input Method Editor) support
|
|
|
|
|
private string _preEditText = string.Empty;
|
|
|
|
|
private int _preEditCursorPosition;
|
|
|
|
|
private IInputMethodService? _inputMethodService;
|
|
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Event raised when text changes.
|
|
|
|
|
/// </summary>
|
2025-12-19 09:30:16 +00:00
|
|
|
public event EventHandler? TextChanged;
|
2025-12-21 13:26:56 -05:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Event raised when editing is completed.
|
|
|
|
|
/// </summary>
|
2025-12-19 09:30:16 +00:00
|
|
|
public event EventHandler? Completed;
|
|
|
|
|
|
|
|
|
|
public SkiaEditor()
|
|
|
|
|
{
|
|
|
|
|
IsFocusable = true;
|
2026-01-17 02:23:05 +00:00
|
|
|
// Get IME service from factory
|
|
|
|
|
_inputMethodService = InputMethodServiceFactory.Instance;
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-21 13:26:56 -05:00
|
|
|
private void OnTextPropertyChanged(string oldText, string newText)
|
|
|
|
|
{
|
|
|
|
|
var text = newText ?? "";
|
|
|
|
|
|
|
|
|
|
if (MaxLength > 0 && text.Length > MaxLength)
|
|
|
|
|
{
|
|
|
|
|
text = text.Substring(0, MaxLength);
|
|
|
|
|
SetValue(TextProperty, text);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateLines();
|
|
|
|
|
_cursorPosition = Math.Min(_cursorPosition, text.Length);
|
|
|
|
|
_scrollOffsetY = 0; // Reset scroll when text changes externally
|
|
|
|
|
_selectionLength = 0;
|
|
|
|
|
TextChanged?.Invoke(this, EventArgs.Empty);
|
|
|
|
|
Invalidate();
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|