diff --git a/src/app/linux_input.c b/src/app/linux_input.c index f2d195f4..6c3acaae 100644 --- a/src/app/linux_input.c +++ b/src/app/linux_input.c @@ -736,6 +736,16 @@ static void mouseButtonCallback(GLFWwindow* w, int button, int action, int mods) row -= g_grid_top_offset; if (row < 0) row = 0; + // Clamp to focused pane bounds when splits are active + if (g_split_active && g_pane_rect_rows > 0) { + int pr = g_pane_rect_row, pc = g_pane_rect_col; + int pe = pr + g_pane_rect_rows, pce = pc + g_pane_rect_cols; + if (row < pr) row = pr; + if (row >= pe) row = pe - 1; + if (col < pc) col = pc; + if (col >= pce) col = pce - 1; + } + // Ctrl+click opens hyperlink if (mods & GLFW_MOD_CONTROL) { int cols = g_cols, nrows = g_rows; @@ -982,6 +992,17 @@ static void cursorPosCallback(GLFWwindow* w, double mx, double my) { mouseToCell(mx, my, &col, &row); row -= g_grid_top_offset; if (row < 0) row = 0; + + // Clamp to focused pane bounds when splits are active + if (g_split_active && g_pane_rect_rows > 0) { + int pr = g_pane_rect_row, pc = g_pane_rect_col; + int pe = pr + g_pane_rect_rows, pce = pc + g_pane_rect_cols; + if (row < pr) row = pr; + if (row >= pe) row = pe - 1; + if (col < pc) col = pc; + if (col >= pce) col = pce - 1; + } + if (col == g_sel_end_col && row == g_sel_end_row) return; if (g_click_count >= 3) { diff --git a/src/app/linux_render_util.c b/src/app/linux_render_util.c index 9bce8844..50be1ce7 100644 --- a/src/app/linux_render_util.c +++ b/src/app/linux_render_util.c @@ -175,8 +175,8 @@ int emitString(Vertex* v, int i, GlyphCache* gc, int cellIsSelected(int row, int col) { if (!g_sel_active) return 0; - // In copy mode with splits, clip selection to focused pane rect - if (g_copy_mode && g_pane_rect_rows > 0) { + // With splits, clip selection to focused pane rect + if ((g_copy_mode || g_split_active) && g_pane_rect_rows > 0) { int pr = g_pane_rect_row, pc = g_pane_rect_col; if (row < pr || row >= pr + g_pane_rect_rows || col < pc || col >= pc + g_pane_rect_cols) return 0; } diff --git a/src/app/macos_input.m b/src/app/macos_input.m index a5916b5e..0f8f6833 100644 --- a/src/app/macos_input.m +++ b/src/app/macos_input.m @@ -372,6 +372,16 @@ - (void)mouseDown:(NSEvent *)event { row -= g_grid_top_offset; if (row < 0) row = 0; + // Clamp to focused pane bounds when splits are active + if (g_split_active && g_pane_rect_rows > 0) { + int pr = g_pane_rect_row, pc = g_pane_rect_col; + int pe = pr + g_pane_rect_rows, pce = pc + g_pane_rect_cols; + if (row < pr) row = pr; + if (row >= pe) row = pe - 1; + if (col < pc) col = pc; + if (col >= pce) col = pce - 1; + } + if (event.modifierFlags & NSEventModifierFlagCommand) { int cols = g_cols, rows_n = g_rows; if (g_cells && col >= 0 && col < cols && row >= 0 && row < rows_n) { @@ -664,6 +674,17 @@ - (void)mouseDragged:(NSEvent *)event { mouseCell0(event, self, &col, &row); row -= g_grid_top_offset; if (row < 0) row = 0; + + // Clamp to focused pane bounds when splits are active + if (g_split_active && g_pane_rect_rows > 0) { + int pr = g_pane_rect_row, pc = g_pane_rect_col; + int pe = pr + g_pane_rect_rows, pce = pc + g_pane_rect_cols; + if (row < pr) row = pr; + if (row >= pe) row = pe - 1; + if (col < pc) col = pc; + if (col >= pce) col = pce - 1; + } + if (col == g_sel_end_col && row == g_sel_end_row) return; if (_clickCount >= 3) { diff --git a/src/app/macos_renderer_draw.m b/src/app/macos_renderer_draw.m index a332bae3..4b8f6038 100644 --- a/src/app/macos_renderer_draw.m +++ b/src/app/macos_renderer_draw.m @@ -9,8 +9,8 @@ static BOOL cellIsSelected(int row, int col) { if (!g_sel_active) return NO; - // In copy mode with splits, clip selection to focused pane rect - if (g_copy_mode && g_pane_rect_rows > 0) { + // With splits, clip selection to focused pane rect + if ((g_copy_mode || g_split_active) && g_pane_rect_rows > 0) { int pr = g_pane_rect_row, pc = g_pane_rect_col; int pe = pr + g_pane_rect_rows, pce = pc + g_pane_rect_cols; if (row < pr || row >= pe || col < pc || col >= pce) return NO; diff --git a/src/app/ui/selection.zig b/src/app/ui/selection.zig index 239850c8..43060ecc 100644 --- a/src/app/ui/selection.zig +++ b/src/app/ui/selection.zig @@ -21,11 +21,18 @@ pub fn copySelection(is_block: bool) void { const total_lines = sb_count + grid_rows; if (total_lines <= 0) return; - // Read and normalize selection bounds (viewport-relative) + // Read and normalize selection bounds (viewport-relative). + // In split mode, coords are in global content-space — convert to pane-local. var sr: i32 = c.g_sel_start_row; var sc: i32 = c.g_sel_start_col; var er: i32 = c.g_sel_end_row; var ec: i32 = c.g_sel_end_col; + if (c.g_split_active != 0 and c.g_pane_rect_rows > 0) { + sr -= c.g_pane_rect_row; + er -= c.g_pane_rect_row; + sc -= c.g_pane_rect_col; + ec -= c.g_pane_rect_col; + } if (sr > er or (sr == er and sc > ec)) { const tr = sr; const tc = sc;