|
|
@@ -41,6 +41,24 @@ private:
|
|
|
static constexpr std::chrono::milliseconds BLINK_INTERVAL = std::chrono::milliseconds(500);
|
|
|
static constexpr std::chrono::milliseconds BLINK_STATIONARY_THRESHOLD = std::chrono::milliseconds(1000); // 1 second
|
|
|
|
|
|
+ // Viewport bounds calculation (avoids code duplication)
|
|
|
+ struct ViewportBounds {
|
|
|
+ int content_width;
|
|
|
+ int content_height;
|
|
|
+ int line_number_width;
|
|
|
+ int minibuffer_lines;
|
|
|
+ };
|
|
|
+
|
|
|
+ ViewportBounds calculate_viewport_bounds() const {
|
|
|
+ ViewportBounds bounds;
|
|
|
+ bounds.minibuffer_lines = 1; // Always reserve 1 line for minibuffer/message
|
|
|
+ bounds.content_height = height_ - bounds.minibuffer_lines;
|
|
|
+ bool show_line_numbers = core_->config().get<bool>("show_line_numbers", true);
|
|
|
+ bounds.line_number_width = show_line_numbers ? core_->config().get<int>("line_number_width", 6) : 0;
|
|
|
+ bounds.content_width = width_ - bounds.line_number_width;
|
|
|
+ return bounds;
|
|
|
+ }
|
|
|
+
|
|
|
// Private helper method declarations
|
|
|
std::string resolve_key(int ch);
|
|
|
bool handle_input(int ch);
|
|
|
@@ -49,7 +67,7 @@ private:
|
|
|
void render_window(std::shared_ptr<Window> window, int x, int y, int width, int height);
|
|
|
void render_window_modeline(std::shared_ptr<Window> window, int x, int y, int width, bool is_active);
|
|
|
void render_message_line();
|
|
|
-
|
|
|
+
|
|
|
int get_attributes_for_face(const std::string& face_name);
|
|
|
|
|
|
// Hardware cursor position tracking
|
|
|
@@ -82,13 +100,9 @@ void TuiEditor::init() {
|
|
|
core_->theme_manager().active_theme()->initialize_ncurses_colors();
|
|
|
}
|
|
|
|
|
|
- // Set initial viewport size (leave room for minibuffer/message line)
|
|
|
- int minibuffer_lines = 1; // Always reserve 1 line for minibuffer/message
|
|
|
- int content_height = height_ - minibuffer_lines;
|
|
|
- bool show_line_numbers = core_->config().get<bool>("show_line_numbers", true);
|
|
|
- int line_number_width = show_line_numbers ? core_->config().get<int>("line_number_width", 6) : 0;
|
|
|
- int content_width = width_ - line_number_width;
|
|
|
- core_->set_viewport_size(content_width, content_height);
|
|
|
+ // Set initial viewport size
|
|
|
+ auto bounds = calculate_viewport_bounds();
|
|
|
+ core_->set_viewport_size(bounds.content_width, bounds.content_height);
|
|
|
|
|
|
spdlog::debug("ncurses editor initialized: {}x{}", width_, height_);
|
|
|
}
|
|
|
@@ -108,14 +122,10 @@ void TuiEditor::run() {
|
|
|
if (new_height != height_ || new_width != width_) {
|
|
|
height_ = new_height;
|
|
|
width_ = new_width;
|
|
|
- int minibuffer_lines = 1; // Always reserve 1 line for minibuffer/message
|
|
|
- int content_height = height_ - minibuffer_lines;
|
|
|
- bool show_line_numbers = core_->config().get<bool>("show_line_numbers", true);
|
|
|
- int line_number_width = show_line_numbers ? core_->config().get<int>("line_number_width", 6) : 0;
|
|
|
- int content_width = width_ - line_number_width;
|
|
|
- core_->set_viewport_size(content_width, content_height);
|
|
|
+ auto bounds = calculate_viewport_bounds();
|
|
|
+ core_->set_viewport_size(bounds.content_width, bounds.content_height);
|
|
|
spdlog::debug("Screen resized to: {}x{}", width_, height_);
|
|
|
- spdlog::debug("Content area: {}x{}", content_width, content_height);
|
|
|
+ spdlog::debug("Content area: {}x{}", bounds.content_width, bounds.content_height);
|
|
|
// Force cursor to be visible after resize, as it implies movement.
|
|
|
last_cursor_move_time_ = std::chrono::steady_clock::now();
|
|
|
cursor_visible_ = true;
|
|
|
@@ -330,16 +340,11 @@ void TuiEditor::render() {
|
|
|
}
|
|
|
clear();
|
|
|
|
|
|
- // Calculate content area (leave room for message line and potentially a completion line)
|
|
|
- int minibuffer_lines = 1; // Always reserve 1 line for minibuffer/message
|
|
|
- // if (core_->minibuffer_manager().is_active() && !core_->minibuffer_manager().get_completion_candidates().empty()) {
|
|
|
- // minibuffer_lines++; // Reserve an extra line for completions
|
|
|
- // }
|
|
|
- int content_height = height_ - minibuffer_lines;
|
|
|
- int content_width = width_;
|
|
|
-
|
|
|
+ // Calculate content area
|
|
|
+ auto bounds = calculate_viewport_bounds();
|
|
|
+
|
|
|
// Render the layout tree recursively (now includes per-window modelines)
|
|
|
- render_layout_node(core_->root_layout(), 0, 0, content_width, content_height);
|
|
|
+ render_layout_node(core_->root_layout(), 0, 0, width_, bounds.content_height);
|
|
|
|
|
|
// Global message/command line (last line)
|
|
|
render_message_line();
|