cursor blink in entry/editor
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/// <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
|
||||
|
||||
public void SelectAll()
|
||||
|
||||
Reference in New Issue
Block a user