Skip to content

Commit

Permalink
Improve text selection with multiple panes
Browse files Browse the repository at this point in the history
- Constrain mouse hold and release events to currently active pane
- Fix calculation of columns with side by side panes
  • Loading branch information
tlinford committed Jun 2, 2021
1 parent 17700e4 commit 649567a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
17 changes: 8 additions & 9 deletions zellij-server/src/panes/terminal_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,25 @@ impl Pane for TerminalPane {
debug_log_to_file(format!("getting text from selection: {:?}", self.selection))
.expect("could not write to log file");

let (start, end) = if self.selection.start <= self.selection.end {
let (mut start, mut end) = if self.selection.start <= self.selection.end {
(self.selection.start, self.selection.end)
} else {
(self.selection.end, self.selection.start)
};

start.column.0 -= self.x();
end.column.0 -= self.x();

for l in start.line.0..=end.line.0 {
let mut line_selection = String::new();

// on the first line of the selection, use the selection start column
// otherwise, start at the beginning of the line
let start_column = if l == self.selection.start.line.0 {
self.selection.start.column.0
} else {
0
};
let start_column = if l == start.line.0 { start.column.0 } else { 0 };

// same thing on the last line, but with the selection end column
let end_column = if l == self.selection.end.line.0 {
self.selection.end.column.0
let end_column = if l == end.line.0 {
end.column.0
} else {
self.position_and_size.columns
};
Expand All @@ -82,7 +81,7 @@ impl Pane for TerminalPane {
continue;
}

let line = &self.grid.as_character_lines()[l - self.position_and_size.y];
let line = &self.grid.as_character_lines()[l - self.y()];

let mut terminal_col = 0;
for terminal_character in line {
Expand Down
2 changes: 1 addition & 1 deletion zellij-server/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::os::unix::io::RawFd;
use std::str;
use std::sync::{Arc, RwLock};

use zellij_utils::{input::mouse::Position, logging::debug_log_to_file, zellij_tile};
use zellij_utils::{input::mouse::Position, zellij_tile};

use crate::{
panes::PaneId,
Expand Down
6 changes: 3 additions & 3 deletions zellij-server/src/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2340,9 +2340,9 @@ impl Tab {
}

pub fn copy_selection(&self) {
let s = self.get_active_pane().and_then(|p| p.get_selected_text());
if let Some(s) = s {
let output = format!("\u{1b}]52;c;{}\u{1b}\\", base64::encode(s));
let selected_text = self.get_active_pane().and_then(|p| p.get_selected_text());
if let Some(selected_text) = selected_text {
let output = format!("\u{1b}]52;c;{}\u{1b}\\", base64::encode(selected_text));
self.senders
.send_to_server(ServerInstruction::Render(Some(output)))
.unwrap();
Expand Down

0 comments on commit 649567a

Please sign in to comment.