Fix unnecessary redraws with active selection

Could be cleaned up a bit if there was a wrapper for Option<Selection>
that contained this flag.

Also fixes a few compiler warnings.
This commit is contained in:
Joe Wilm 2017-06-16 12:56:55 -07:00 committed by Joe Wilm
parent 63bcb46011
commit 6b081dcc95
3 changed files with 14 additions and 16 deletions

View File

@ -36,6 +36,7 @@ pub struct ActionContext<'a, N: 'a> {
pub selection: &'a mut Option<Selection>,
pub size_info: &'a SizeInfo,
pub mouse: &'a mut Mouse,
pub selection_modified: bool,
}
impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> {
@ -69,9 +70,11 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> {
fn clear_selection(&mut self) {
*self.selection = None;
self.selection_modified = true;
}
fn update_selection(&mut self, point: Point, side: Side) {
self.selection_modified = true;
// Update selection if one exists
if let &mut Some(ref mut selection) = self.selection {
selection.update(point, side);
@ -84,14 +87,17 @@ 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;
}
fn semantic_selection(&mut self, point: Point) {
*self.selection = Some(Selection::semantic(point, self.terminal as &Term));
self.selection_modified = true;
}
fn line_selection(&mut self, point: Point) {
*self.selection = Some(Selection::lines(point));
self.selection_modified = true;
}
fn mouse_coords(&self) -> Option<Point> {
@ -256,16 +262,6 @@ impl<N: Notify> Processor<N> {
*hide_cursor = false;
processor.mouse_moved(x as u32, y as u32);
if !processor.ctx.selection.is_none() {
// TODO this should only be passed if the selection changes
// which happens when the point/side change *and* the mouse
// is still pressed.
//
// Right now, this causes lots of unnecessary redraws while
// selection is active.
processor.ctx.terminal.dirty = true;
}
},
glutin::Event::MouseWheel(scroll_delta, touch_phase) => {
*hide_cursor = false;
@ -335,6 +331,7 @@ impl<N: Notify> Processor<N> {
selection: &mut self.selection,
mouse: &mut self.mouse,
size_info: &self.size_info,
selection_modified: false,
};
processor = input::Processor {
@ -355,6 +352,10 @@ impl<N: Notify> Processor<N> {
if self.hide_cursor_when_typing {
window.set_cursor_visible(!self.hide_cursor);
}
if processor.ctx.selection_modified {
processor.ctx.terminal.dirty = true;
}
}
self.wait_for_event = !terminal.dirty;

View File

@ -18,13 +18,10 @@
//! finalized when the button is released. The selection should be cleared
//! when text is added/removed/scrolled on the screen. The selection should
//! also be cleared if the user clicks off of the selection.
use std::mem;
use std::cmp::min;
use std::cmp::max;
use std::cmp::{min, max};
use index::{Point, Column, RangeInclusive, Side, Linear, Line};
use grid::{Grid, ToRange};
use term::Cell;
use grid::ToRange;
/// Describes a region of a 2-dimensional area
///

View File

@ -24,7 +24,7 @@ use unicode_width::UnicodeWidthChar;
use ansi::{self, Color, NamedColor, Attr, Handler, CharsetIndex, StandardCharset, CursorStyle};
use grid::{BidirectionalIterator, Grid, ClearRegion, ToRange, Indexed};
use index::{self, Point, Column, Line, Linear, IndexRange, Contains, RangeInclusive, Side};
use index::{self, Point, Column, Line, Linear, IndexRange, Contains, RangeInclusive};
use selection::{self, Span, Selection};
use config::{Config, VisualBellAnimation};
use Rgb;