diff options
Diffstat (limited to 'src/event.rs')
-rw-r--r-- | src/event.rs | 56 |
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; |