cursor blink in entry/editor

This commit is contained in:
2026-01-17 15:26:13 +00:00
parent 88679dfae8
commit f4422d4af1
2 changed files with 37 additions and 17 deletions

View File

@@ -197,17 +197,14 @@ public class LinuxApplication : IDisposable
{ {
if (_focusedView != value) if (_focusedView != value)
{ {
if (_focusedView != null) var oldFocus = _focusedView;
{
_focusedView.IsFocused = false;
}
_focusedView = value; _focusedView = value;
if (_focusedView != null) // Call OnFocusLost on the old view (this sets IsFocused = false and invalidates)
{ oldFocus?.OnFocusLost();
_focusedView.IsFocused = true;
} // Call OnFocusGained on the new view (this sets IsFocused = true and invalidates)
_focusedView?.OnFocusGained();
} }
} }
} }
@@ -783,11 +780,15 @@ public class LinuxApplication : IDisposable
private void UpdateAnimations() private void UpdateAnimations()
{ {
// Update cursor blink for entry controls // Update cursor blink for text input controls
if (_focusedView is SkiaEntry entry) if (_focusedView is SkiaEntry entry)
{ {
entry.UpdateCursorBlink(); entry.UpdateCursorBlink();
} }
else if (_focusedView is SkiaEditor editor)
{
editor.UpdateCursorBlink();
}
} }
private void Render() private void Render()

View File

@@ -874,13 +874,6 @@ public class SkiaEditor : SkiaView, IInputContext
UpdateLines(); UpdateLines();
} }
// Handle cursor blinking
if (IsFocused && (DateTime.Now - _lastCursorBlink).TotalMilliseconds > 500)
{
_cursorVisible = !_cursorVisible;
_lastCursorBlink = DateTime.Now;
}
// Draw background // Draw background
var bgColor = EditorBackgroundColor != null ? ToSKColor(EditorBackgroundColor) : var bgColor = EditorBackgroundColor != null ? ToSKColor(EditorBackgroundColor) :
(IsEnabled ? SkiaTheme.BackgroundWhiteSK : SkiaTheme.Gray100SK); (IsEnabled ? SkiaTheme.BackgroundWhiteSK : SkiaTheme.Gray100SK);
@@ -1422,6 +1415,32 @@ public class SkiaEditor : SkiaView, IInputContext
Completed?.Invoke(this, EventArgs.Empty); Completed?.Invoke(this, EventArgs.Empty);
} }
/// <summary>
/// Resets the cursor blink timer (shows cursor immediately).
/// </summary>
private void ResetCursorBlink()
{
_lastCursorBlink = DateTime.Now;
_cursorVisible = true;
}
/// <summary>
/// Updates cursor blink animation. Called by the application's animation loop.
/// </summary>
public void UpdateCursorBlink()
{
if (!IsFocused) return;
var elapsed = (DateTime.Now - _lastCursorBlink).TotalMilliseconds;
var newVisible = ((int)(elapsed / 500) % 2) == 0;
if (newVisible != _cursorVisible)
{
_cursorVisible = newVisible;
Invalidate();
}
}
#region Selection and Clipboard #region Selection and Clipboard
public void SelectAll() public void SelectAll()