aboutsummaryrefslogtreecommitdiff
path: root/src/event.rs
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2018-03-05 09:57:34 -0800
committerJoe Wilm <joe@jwilm.com>2018-06-02 09:34:28 -0700
commit8ef062efd94975885776e61b6df936088b018da0 (patch)
tree34567e47784b1d2b0bc82fffac952a18ad4c6c1e /src/event.rs
parentef3c384540b31004a423ada778ed5c02d90e68c6 (diff)
downloadalacritty-8ef062efd94975885776e61b6df936088b018da0.tar.gz
alacritty-8ef062efd94975885776e61b6df936088b018da0.zip
Move selection into Grid
Supporting selections with scrollback has two major components: 1. Grid needs access to Selection so that it may update the scroll position as the terminal text changes. 2. Selection needs to be implemented in terms of buffer offsets -- NOT lines -- and be updated when Storage is rotated. This commit implements the first part.
Diffstat (limited to 'src/event.rs')
-rw-r--r--src/event.rs56
1 files changed, 23 insertions, 33 deletions
diff --git a/src/event.rs b/src/event.rs
index 3b1df006..d6348ba0 100644
--- a/src/event.rs
+++ b/src/event.rs
@@ -33,10 +33,8 @@ pub trait Notify {
pub struct ActionContext<'a, N: 'a> {
pub notifier: &'a mut N,
pub terminal: &'a mut Term,
- pub selection: &'a mut Option<Selection>,
pub size_info: &'a SizeInfo,
pub mouse: &'a mut Mouse,
- pub selection_modified: bool,
pub received_count: &'a mut usize,
pub suppress_chars: &'a mut bool,
pub last_modifiers: &'a mut ModifiersState,
@@ -64,30 +62,35 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> {
}
fn copy_selection(&self, buffer: ::copypasta::Buffer) {
- if let Some(ref selection) = *self.selection {
- if let Some(ref span) = selection.to_span(self.terminal) {
- let buf = self.terminal.string_from_selection(&span);
- if !buf.is_empty() {
+ self.terminal
+ .selection_to_string()
+ .map(|selected| {
+ if !selected.is_empty() {
Clipboard::new()
- .and_then(|mut clipboard| clipboard.store(buf, buffer))
+ .and_then(|mut clipboard| clipboard.store(selected, buffer))
.unwrap_or_else(|err| {
warn!("Error storing selection to clipboard. {}", Red(err));
});
}
- }
- }
+ });
}
fn clear_selection(&mut self) {
- *self.selection = None;
- self.selection_modified = true;
+ *self.terminal.selection_mut() = None;
+ self.terminal.dirty = true;
}
fn update_selection(&mut self, point: Point, side: Side) {
- self.selection_modified = true;
+
// Update selection if one exists
- if let Some(ref mut selection) = *self.selection {
+ let mut had_selection = false; // borrowck
+ if let Some(ref mut selection) = *self.terminal.selection_mut() {
selection.update(point, side);
+ had_selection = true;
+ }
+
+ if had_selection { // borrowck
+ self.terminal.dirty = true;
return;
}
@@ -96,18 +99,18 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> {
}
fn simple_selection(&mut self, point: Point, side: Side) {
- *self.selection = Some(Selection::simple(point, side));
- self.selection_modified = true;
+ *self.terminal.selection_mut() = Some(Selection::simple(point, side));
+ self.terminal.dirty = true;
}
fn semantic_selection(&mut self, point: Point) {
- *self.selection = Some(Selection::semantic(point, self.terminal));
- self.selection_modified = true;
+ *self.terminal.selection_mut() = Some(Selection::semantic(point, &*self.terminal));
+ self.terminal.dirty = true;
}
fn line_selection(&mut self, point: Point) {
- *self.selection = Some(Selection::lines(point));
- self.selection_modified = true;
+ *self.terminal.selection_mut() = Some(Selection::lines(point));
+ self.terminal.dirty = true;
}
fn mouse_coords(&self) -> Option<Point> {
@@ -200,7 +203,6 @@ pub struct Processor<N> {
resize_tx: mpsc::Sender<(u32, u32)>,
ref_test: bool,
size_info: SizeInfo,
- pub selection: Option<Selection>,
hide_cursor_when_typing: bool,
hide_cursor: bool,
received_count: usize,
@@ -215,7 +217,6 @@ pub struct Processor<N> {
impl<N> OnResize for Processor<N> {
fn on_resize(&mut self, size: &SizeInfo) {
self.size_info = size.to_owned();
- self.selection = None;
}
}
@@ -242,8 +243,7 @@ impl<N: Notify> Processor<N> {
resize_tx,
ref_test,
mouse: Default::default(),
- selection: None,
- size_info,
+ size_info: size_info,
hide_cursor_when_typing: config.hide_cursor_when_typing(),
hide_cursor: false,
received_count: 0,
@@ -321,10 +321,6 @@ impl<N: Notify> Processor<N> {
*hide_cursor = false;
processor.mouse_moved(x as u32, y as u32, modifiers);
-
- if !processor.ctx.selection.is_none() {
- processor.ctx.terminal.dirty = true;
- }
},
MouseWheel { delta, phase, modifiers, .. } => {
*hide_cursor = false;
@@ -400,10 +396,8 @@ impl<N: Notify> Processor<N> {
context = ActionContext {
terminal: &mut terminal,
notifier: &mut self.notifier,
- selection: &mut self.selection,
mouse: &mut self.mouse,
size_info: &self.size_info,
- selection_modified: false,
received_count: &mut self.received_count,
suppress_chars: &mut self.suppress_chars,
last_modifiers: &mut self.last_modifiers,
@@ -448,10 +442,6 @@ impl<N: Notify> Processor<N> {
}
window.is_focused = window_is_focused;
-
- if processor.ctx.selection_modified {
- processor.ctx.terminal.dirty = true;
- }
}
self.wait_for_event = !terminal.dirty;