|
|
@@ -145,6 +145,7 @@ public:
|
|
|
|
|
|
private:
|
|
|
EditorCore* core_;
|
|
|
+ std::shared_ptr<Window> cached_active_window_; // Cached to prevent focus jumping during redraws
|
|
|
|
|
|
void apply_face_attributes(Pango::AttrList& attr_list, const FaceAttributes& face, int start_index, int end_index) {
|
|
|
if (start_index >= end_index) return;
|
|
|
@@ -483,13 +484,16 @@ protected:
|
|
|
if (content_widget_) {
|
|
|
window_->unset_child();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// Clear the drawing area reference since we're rebuilding
|
|
|
drawing_area_ = nullptr;
|
|
|
-
|
|
|
+
|
|
|
// Clear render cache to prevent stale window pointers
|
|
|
render_cache_.clear();
|
|
|
|
|
|
+ // Initialize cached active window to prevent focus jumping
|
|
|
+ cached_active_window_ = core_->active_window();
|
|
|
+
|
|
|
// Create new layout based on the tree
|
|
|
content_widget_ = create_widget_for_layout_node(root_layout);
|
|
|
if (content_widget_) {
|
|
|
@@ -525,6 +529,7 @@ protected:
|
|
|
if (auto window = weak_window_key.lock()) {
|
|
|
if (core_) {
|
|
|
core_->set_active_window(window);
|
|
|
+ cached_active_window_ = window; // Cache for rendering to prevent focus jumping
|
|
|
}
|
|
|
}
|
|
|
return on_key_pressed(keyval, keycode, state);
|
|
|
@@ -540,6 +545,7 @@ protected:
|
|
|
// 1. Activate Window
|
|
|
if (core_ && core_->active_window() != window) {
|
|
|
core_->set_active_window(window);
|
|
|
+ cached_active_window_ = window; // Cache for rendering to prevent focus jumping
|
|
|
}
|
|
|
// IMPORTANT: Grab keyboard focus for this widget
|
|
|
drawing_area->grab_focus();
|
|
|
@@ -615,6 +621,7 @@ protected:
|
|
|
// Activate window if not already
|
|
|
if (core_ && core_->active_window() != window) {
|
|
|
core_->set_active_window(window);
|
|
|
+ cached_active_window_ = window; // Cache for rendering to prevent focus jumping
|
|
|
}
|
|
|
drawing_area->grab_focus(); // Ensure focus for context
|
|
|
|
|
|
@@ -796,9 +803,10 @@ protected:
|
|
|
|
|
|
int visible_lines = static_cast<int>(content_height_px / line_height_);
|
|
|
int visible_cols = static_cast<int>(content_width_px / char_width_);
|
|
|
-
|
|
|
- // Reserve space for modeline (all windows) and minibuffer (main window only)
|
|
|
- bool is_main_window = (window == core_->active_window());
|
|
|
+
|
|
|
+ // Reserve space for modeline (all windows) and minibuffer (main window only)
|
|
|
+ // Use cached active window to prevent focus jumping during async redraws
|
|
|
+ bool is_main_window = (window == cached_active_window_);
|
|
|
int editor_lines = is_main_window ? std::max(0, visible_lines - 2) : std::max(0, visible_lines - 1);
|
|
|
window->set_viewport_size(visible_cols, editor_lines);
|
|
|
|
|
|
@@ -889,9 +897,10 @@ protected:
|
|
|
|
|
|
cr->set_source_rgb(fg.r / 255.0, fg.g / 255.0, fg.b / 255.0);
|
|
|
layout->show_in_cairo_context(cr);
|
|
|
-
|
|
|
+
|
|
|
// Render Cursor
|
|
|
- bool should_show_cursor = (window == core_->active_window()) && cursor_visible_;
|
|
|
+ // Use cached active window to prevent focus jumping during async redraws
|
|
|
+ bool should_show_cursor = (window == cached_active_window_) && cursor_visible_;
|
|
|
if (should_show_cursor && buffer_line_idx == cursor.line) {
|
|
|
int cursor_idx = static_cast<int>(cursor.column) - horizontal_offset;
|
|
|
|
|
|
@@ -956,11 +965,12 @@ protected:
|
|
|
|
|
|
|
|
|
// Render modeline for a specific window
|
|
|
- void render_modeline_for_window(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height,
|
|
|
+ void render_modeline_for_window(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height,
|
|
|
const Glib::RefPtr<Pango::Layout>& layout, std::shared_ptr<Window> window) {
|
|
|
if (!core_ || !window) return;
|
|
|
-
|
|
|
- bool is_active = (window == core_->active_window());
|
|
|
+
|
|
|
+ // Use cached active window to prevent focus jumping during async redraws
|
|
|
+ bool is_active = (window == cached_active_window_);
|
|
|
|
|
|
// Calculate modeline position (second line from bottom)
|
|
|
double modeline_y = height - (2 * line_height_) - PADDING_BOTTOM;
|