cursor style is handled properly now

This commit is contained in:
filipriec
2025-08-29 12:32:33 +02:00
parent 72c2691a17
commit 833b918c5b

View File

@@ -29,6 +29,7 @@ use crate::pages::register::RegisterResult;
use crate::ui::handlers::context::DialogPurpose; use crate::ui::handlers::context::DialogPurpose;
use crate::utils::columns::filter_user_columns; use crate::utils::columns::filter_user_columns;
use canvas::keymap::KeyEventOutcome; use canvas::keymap::KeyEventOutcome;
use canvas::CursorManager;
use canvas::FormEditor; use canvas::FormEditor;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use crossterm::cursor::{SetCursorStyle, MoveTo}; use crossterm::cursor::{SetCursorStyle, MoveTo};
@@ -699,41 +700,26 @@ pub async fn run_ui() -> Result<()> {
match current_mode { match current_mode {
AppMode::General => { AppMode::General => {
if app_state.ui.focus_outside_canvas { if app_state.ui.focus_outside_canvas {
// General mode, focus outside canvas but canvas exists // Outside canvas → app decides
if let Some(editor) = &app_state.form_editor { terminal.set_cursor_style(SetCursorStyle::SteadyUnderScore)?;
// Get last known cursor position from canvas terminal.show_cursor()?;
let x = editor.cursor_position() as u16;
let y = editor.current_field() as u16;
// Force underscore cursor at that position
terminal.set_cursor_style(SetCursorStyle::SteadyUnderScore)?;
terminal.show_cursor()?;
// Move cursor to last known canvas position
terminal.set_cursor_position(x, y)?;
} else {
// No canvas at all → hide cursor
terminal.hide_cursor()?;
}
} else { } else {
// General mode, focus inside canvas → let canvas handle cursor // Inside canvas → let canvas handle it
// Do nothing here if let Some(editor) = &app_state.form_editor {
let _ = CursorManager::update_for_mode(editor.mode());
}
if let Page::Login(page) = &router.current {
let _ = CursorManager::update_for_mode(page.editor.mode());
}
if let Page::Register(page) = &router.current {
let _ = CursorManager::update_for_mode(page.editor.mode());
}
} }
} }
AppMode::Command => { AppMode::Command => {
// Command line overlay → always steady block // Command line overlay → app decides
terminal.set_cursor_style(SetCursorStyle::SteadyBlock)?; terminal.set_cursor_style(SetCursorStyle::SteadyBlock)?;
terminal terminal.show_cursor()?;
.show_cursor()
.context("Failed to show cursor in Command mode")?;
// Enforce ReadOnly on any active canvases while in command mode
if let Some(editor) = &mut app_state.form_editor {
editor.set_mode(canvas::AppMode::ReadOnly);
}
if let Page::Login(page) = &mut router.current {
page.editor.set_mode(canvas::AppMode::ReadOnly);
}
} }
} }