From f4422d4af1627909bbc3aafe63b347446c6b8c1b Mon Sep 17 00:00:00 2001 From: logikonline Date: Sat, 17 Jan 2026 15:26:13 +0000 Subject: [PATCH] cursor blink in entry/editor --- LinuxApplication.cs | 21 +++++++++++---------- Views/SkiaEditor.cs | 33 ++++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/LinuxApplication.cs b/LinuxApplication.cs index d155db9..152caf2 100644 --- a/LinuxApplication.cs +++ b/LinuxApplication.cs @@ -197,17 +197,14 @@ public class LinuxApplication : IDisposable { if (_focusedView != value) { - if (_focusedView != null) - { - _focusedView.IsFocused = false; - } - + var oldFocus = _focusedView; _focusedView = value; - if (_focusedView != null) - { - _focusedView.IsFocused = true; - } + // Call OnFocusLost on the old view (this sets IsFocused = false and invalidates) + oldFocus?.OnFocusLost(); + + // 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() { - // Update cursor blink for entry controls + // Update cursor blink for text input controls if (_focusedView is SkiaEntry entry) { entry.UpdateCursorBlink(); } + else if (_focusedView is SkiaEditor editor) + { + editor.UpdateCursorBlink(); + } } private void Render() diff --git a/Views/SkiaEditor.cs b/Views/SkiaEditor.cs index f904849..b239bea 100644 --- a/Views/SkiaEditor.cs +++ b/Views/SkiaEditor.cs @@ -874,13 +874,6 @@ public class SkiaEditor : SkiaView, IInputContext UpdateLines(); } - // Handle cursor blinking - if (IsFocused && (DateTime.Now - _lastCursorBlink).TotalMilliseconds > 500) - { - _cursorVisible = !_cursorVisible; - _lastCursorBlink = DateTime.Now; - } - // Draw background var bgColor = EditorBackgroundColor != null ? ToSKColor(EditorBackgroundColor) : (IsEnabled ? SkiaTheme.BackgroundWhiteSK : SkiaTheme.Gray100SK); @@ -1422,6 +1415,32 @@ public class SkiaEditor : SkiaView, IInputContext Completed?.Invoke(this, EventArgs.Empty); } + /// + /// Resets the cursor blink timer (shows cursor immediately). + /// + private void ResetCursorBlink() + { + _lastCursorBlink = DateTime.Now; + _cursorVisible = true; + } + + /// + /// Updates cursor blink animation. Called by the application's animation loop. + /// + 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 public void SelectAll()