Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions example/config.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ keybinds {
normal {
// uncomment this and adjust key if using copy_on_select=false
// bind "Alt c" { Copy; }
// or you can bind smart copy action instead
// bind "Ctrl c" { SmartCopy; }
}
locked {
bind "Ctrl g" { SwitchToMode "Normal"; }
Expand Down Expand Up @@ -73,6 +75,8 @@ keybinds {
bind "u" { HalfPageScrollUp; }
// uncomment this and adjust key if using copy_on_select=false
// bind "Alt c" { Copy; }
// or you can bind smart copy action instead
// bind "Ctrl c" { SmartCopy; }
}
search {
bind "Ctrl s" { SwitchToMode "Normal"; }
Expand Down
4 changes: 4 additions & 0 deletions example/default.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ keybinds {
normal {
// uncomment this and adjust key if using copy_on_select=false
// bind "Alt c" { Copy; }
// or you can bind smart copy action instead
// bind "Ctrl c" { SmartCopy; }
}
locked {
bind "Ctrl g" { SwitchToMode "Normal"; }
Expand Down Expand Up @@ -83,6 +85,8 @@ keybinds {
bind "u" { HalfPageScrollUp; }
// uncomment this and adjust key if using copy_on_select=false
// bind "Alt c" { Copy; }
// or you can bind smart copy action instead
// bind "Ctrl c" { SmartCopy; }
}
search {
bind "Ctrl s" { SwitchToMode "Normal"; }
Expand Down
6 changes: 3 additions & 3 deletions zellij-server/src/panes/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,9 @@ impl Grid {
self.update_selected_lines(&old_selection, &self.selection.clone());
self.mark_for_rerender();
}
pub fn has_selection(&self) -> bool {
!self.selection.is_empty()
}
pub fn get_selected_text(&self) -> Option<String> {
if self.selection.is_empty() {
return None;
Expand Down Expand Up @@ -2441,9 +2444,6 @@ impl Grid {
pub fn update_arrow_fonts(&mut self, should_support_arrow_fonts: bool) {
self.arrow_fonts = should_support_arrow_fonts;
}
pub fn has_selection(&self) -> bool {
!self.selection.is_empty()
}
}

impl Perform for Grid {
Expand Down
8 changes: 8 additions & 0 deletions zellij-server/src/panes/plugin_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,14 @@ impl Pane for PluginPane {
self.supports_mouse_selection
}

fn has_selection(&self, client_id: ClientId) -> bool {
if let Some(grid) = self.grids.get(&client_id) {
grid.has_selection()
} else {
false
}
}

fn get_selected_text(&self, client_id: ClientId) -> Option<String> {
if let Some(grid) = self.grids.get(&client_id) {
grid.get_selected_text()
Expand Down
4 changes: 4 additions & 0 deletions zellij-server/src/panes/terminal_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,10 @@ impl Pane for TerminalPane {
self.grid.reset_selection();
}

fn has_selection(&self, _client_id: ClientId) -> bool {
self.grid.has_selection()
}

fn get_selected_text(&self, _client_id: ClientId) -> Option<String> {
self.grid.get_selected_text()
}
Expand Down
3 changes: 3 additions & 0 deletions zellij-server/src/plugins/zellij_exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ macro_rules! apply_action {
None,
$env.keybinds.clone(),
$env.default_mode.clone(),
None,
None,
None,
) {
log::error!("{}: {:?}", $error_message(), e);
}
Expand Down
24 changes: 22 additions & 2 deletions zellij-server/src/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::time::Duration;
use uuid::Uuid;
use zellij_utils::{
channels::SenderWithContext,
data::{Direction, Event, InputMode, PluginCapabilities, ResizeStrategy},
data::{Direction, Event, InputMode, KeyWithModifier, PluginCapabilities, ResizeStrategy},
errors::prelude::*,
input::{
actions::{Action, SearchDirection, SearchOption},
Expand Down Expand Up @@ -43,6 +43,10 @@ pub(crate) fn route_action(
mut seen_cli_pipes: Option<&mut HashSet<String>>,
client_keybinds: Keybinds,
default_mode: InputMode,
// If action is triggered by a key msg, these args will be populated
key_with_modifier: Option<KeyWithModifier>,
raw_bytes: Option<Vec<u8>>,
is_kitty_keyboard_protocol: Option<bool>,
) -> Result<bool> {
let mut should_break = false;
let err_context = || format!("failed to route action for client {client_id}");
Expand Down Expand Up @@ -568,6 +572,16 @@ pub(crate) fn route_action(
.send_to_screen(ScreenInstruction::Copy(client_id))
.with_context(err_context)?;
},
Action::SmartCopy => {
senders
.send_to_screen(ScreenInstruction::SmartCopy(
key_with_modifier,
raw_bytes,
is_kitty_keyboard_protocol,
client_id,
))
.with_context(err_context)?;
},
Action::Confirm => {
senders
.send_to_screen(ScreenInstruction::ConfirmPrompt(client_id))
Expand Down Expand Up @@ -978,7 +992,7 @@ pub(crate) fn route_thread_main(
.get_actions_for_key_in_mode_or_default_action(
&input_mode,
&key,
raw_bytes,
raw_bytes.clone(),
default_input_mode,
is_kitty_keyboard_protocol,
)
Expand All @@ -1001,6 +1015,9 @@ pub(crate) fn route_thread_main(
.default_mode
.unwrap_or(InputMode::Normal)
.clone(),
Some(key.clone()),
Some(raw_bytes.clone()),
Some(is_kitty_keyboard_protocol),
)? {
should_break = true;
}
Expand Down Expand Up @@ -1036,6 +1053,9 @@ pub(crate) fn route_thread_main(
.default_mode
.unwrap_or(InputMode::Normal)
.clone(),
None,
None,
None,
)? {
should_break = true;
}
Expand Down
53 changes: 53 additions & 0 deletions zellij-server/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ pub enum ScreenInstruction {
ChangeModeForAllClients(ModeInfo),
MouseEvent(MouseEvent, ClientId),
Copy(ClientId),
SmartCopy(
Option<KeyWithModifier>, // key_with_modifier
Option<Vec<u8>>, // raw_bytes
Option<bool>, // is_kitty_keyboard_protocol
ClientId,
),
AddClient(
ClientId,
bool, // is_web_client
Expand Down Expand Up @@ -540,6 +546,7 @@ impl From<&ScreenInstruction> for ScreenContext {
ScreenInstruction::ScrollDownAt(..) => ScreenContext::ScrollDownAt,
ScreenInstruction::MouseEvent(..) => ScreenContext::MouseEvent,
ScreenInstruction::Copy(..) => ScreenContext::Copy,
ScreenInstruction::SmartCopy(..) => ScreenContext::SmartCopy,
ScreenInstruction::ToggleTab(..) => ScreenContext::ToggleTab,
ScreenInstruction::AddClient(..) => ScreenContext::AddClient,
ScreenInstruction::RemoveClient(..) => ScreenContext::RemoveClient,
Expand Down Expand Up @@ -4399,6 +4406,52 @@ pub(crate) fn screen_thread_main(
.copy_selection(client_id), ?);
screen.render(None)?;
},
ScreenInstruction::SmartCopy(
key_with_modifier,
raw_bytes,
is_kitty_keyboard_protocol,
client_id,
) => {
let mut state_changed = false;
active_tab_and_connected_client_id!(
screen,
client_id,
|tab: &mut Tab, client_id: ClientId| -> Result<()> {
if tab.has_selection(client_id) {
tab.copy_selection(client_id)?;
tab.reset_selection(client_id);
} else if let (Some(raw_bytes), Some(is_kitty_keyboard_protocol)) =
(raw_bytes, is_kitty_keyboard_protocol)
{
// If there's no selection, pass through the key to pane
let write_result = match tab.is_sync_panes_active() {
true => tab.write_to_terminals_on_current_tab(
&key_with_modifier,
raw_bytes,
is_kitty_keyboard_protocol,
client_id,
),
false => tab.write_to_active_terminal(
&key_with_modifier,
raw_bytes,
is_kitty_keyboard_protocol,
client_id,
),
};
if let Ok(true) = write_result {
state_changed = true;
}
}
Ok(())
},
?
);
if state_changed {
screen.log_and_report_session_state()?;
}
screen.unblock_input()?;
screen.render(None)?;
},
ScreenInstruction::Exit => {
break;
},
Expand Down
11 changes: 11 additions & 0 deletions zellij-server/src/tab/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ pub trait Pane {
fn supports_mouse_selection(&self) -> bool {
true
}
fn has_selection(&self, _client_id: ClientId) -> bool {
false
}
fn get_selected_text(&self, _client_id: ClientId) -> Option<String> {
None
}
Expand Down Expand Up @@ -4530,6 +4533,14 @@ impl Tab {
}
Ok(())
}
pub fn reset_selection(&mut self, client_id: ClientId) {
self.get_active_pane_mut(client_id)
.map(|p| p.reset_selection(Some(client_id)));
}
pub fn has_selection(&self, client_id: ClientId) -> bool {
self.get_active_pane(client_id)
.map_or(false, |p| p.has_selection(client_id))
}
pub fn copy_selection(&self, client_id: ClientId) -> Result<()> {
let selected_text = self
.get_active_pane(client_id)
Expand Down
3 changes: 3 additions & 0 deletions zellij-server/src/unit/screen_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ fn send_cli_action_to_server(
None,
client_keybinds.clone(),
default_mode,
None,
None,
None,
)
.unwrap();
}
Expand Down
1 change: 1 addition & 0 deletions zellij-utils/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ pub enum ScreenContext {
MiddleMouseRelease,
MouseEvent,
Copy,
SmartCopy,
ToggleTab,
AddClient,
RemoveClient,
Expand Down
1 change: 1 addition & 0 deletions zellij-utils/src/input/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ pub enum Action {
// should_open_in_place, skip_cache, Option<PathBuf> is cwd
MouseEvent(MouseEvent),
Copy,
SmartCopy,
/// Confirm a prompt
Confirm,
/// Deny a prompt
Expand Down
2 changes: 2 additions & 0 deletions zellij-utils/src/kdl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ macro_rules! parse_kdl_action_arguments {
"UndoRenameTab" => Ok(Action::UndoRenameTab),
"Detach" => Ok(Action::Detach),
"Copy" => Ok(Action::Copy),
"SmartCopy" => Ok(Action::SmartCopy),
"Confirm" => Ok(Action::Confirm),
"Deny" => Ok(Action::Deny),
"ToggleMouseMode" => Ok(Action::ToggleMouseMode),
Expand Down Expand Up @@ -1403,6 +1404,7 @@ impl TryFrom<(&KdlNode, &Options)> for Action {
},
"Detach" => parse_kdl_action_arguments!(action_name, action_arguments, kdl_action),
"Copy" => parse_kdl_action_arguments!(action_name, action_arguments, kdl_action),
"SmartCopy" => parse_kdl_action_arguments!(action_name, action_arguments, kdl_action),
"Clear" => parse_kdl_action_arguments!(action_name, action_arguments, kdl_action),
"Confirm" => parse_kdl_action_arguments!(action_name, action_arguments, kdl_action),
"Deny" => parse_kdl_action_arguments!(action_name, action_arguments, kdl_action),
Expand Down
1 change: 1 addition & 0 deletions zellij-utils/src/plugin_api/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,7 @@ impl TryFrom<Action> for ProtobufAction {
| Action::NewInPlacePluginPane(..)
| Action::Deny
| Action::Copy
| Action::SmartCopy
| Action::DumpLayout
| Action::CliPipe { .. }
| Action::ListClients
Expand Down