aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Duerr <chrisduerr@users.noreply.github.com>2018-09-26 18:42:41 +0000
committerGitHub <noreply@github.com>2018-09-26 18:42:41 +0000
commit593d7718d0d3e1e2071021d34178856079ac8bf7 (patch)
tree414b5eda0eb9a5ca881eb6274c9995a473ba9554
parent94b9345a26370fc02fa092016e59511a330f4cb4 (diff)
downloadalacritty-593d7718d0d3e1e2071021d34178856079ac8bf7.tar.gz
alacritty-593d7718d0d3e1e2071021d34178856079ac8bf7.zip
Fix selection of empty lines
When selecting multiple lines in Alacritty, there was an issue with empty lines not being copied. This behavior has been chanaged so empty lines should be correctly copied now. When copying content which ends with an empty line, Alacritty would copy an additional empty line. This has been resolved by only adding empty lines when the empty line was not in the last selected line.
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/term/mod.rs52
-rw-r--r--src/tty.rs9
3 files changed, 41 insertions, 21 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7b233ee2..756bc5e8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Clear screen properly before rendering of content to prevent various graphical glitches
- Fix build failure on 32-bit systems
- Windows started as unfocused now show the hollow cursor if the setting is enabled
+- Empty lines in selections are now properly copied to the clipboard
### Deprecated
diff --git a/src/term/mod.rs b/src/term/mod.rs
index eefc432e..af464320 100644
--- a/src/term/mod.rs
+++ b/src/term/mod.rs
@@ -941,16 +941,11 @@ impl Term {
use std::ops::Range;
trait Append : PushChar {
- fn append(&mut self, grid: &Grid<Cell>, line: usize, cols: Range<Column>) -> Option<Range<Column>>;
+ fn append(&mut self, grid: &Grid<Cell>, line: usize, cols: Range<Column>);
}
impl Append for String {
- fn append(
- &mut self,
- grid: &Grid<Cell>,
- mut line: usize,
- cols: Range<Column>
- ) -> Option<Range<Column>> {
+ fn append(&mut self, grid: &Grid<Cell>, mut line: usize, cols: Range<Column>) {
// Select until last line still within the buffer
line = min(line, grid.len() - 1);
@@ -958,23 +953,18 @@ impl Term {
let line_length = grid_line.line_length();
let line_end = min(line_length, cols.end + 1);
- if cols.start >= line_end {
- None
- } else {
+ if line_end.0 == 0 && cols.end >= grid.num_cols() - 1 {
+ self.push('\n');
+ } else if cols.start < line_end {
for cell in &grid_line[cols.start..line_end] {
if !cell.flags.contains(cell::Flags::WIDE_CHAR_SPACER) {
self.push(cell.c);
}
}
- let range = Some(cols.start..line_end);
if cols.end >= grid.num_cols() - 1 {
- if let Some(ref range) = range {
- self.maybe_newline(grid, line, range.end);
- }
+ self.maybe_newline(grid, line, line_end);
}
-
- range
}
}
}
@@ -2006,7 +1996,7 @@ mod tests {
use term::cell;
use grid::{Grid, Scroll};
- use index::{Point, Line, Column};
+ use index::{Point, Line, Column, Side};
use ansi::{self, Handler, CharsetIndex, StandardCharset};
use selection::Selection;
use std::mem;
@@ -2082,6 +2072,34 @@ mod tests {
assert_eq!(term.selection_to_string(), Some(String::from("\"aa\"a\n")));
}
+ #[test]
+ fn selecting_empty_line() {
+ let size = SizeInfo {
+ width: 21.0,
+ height: 51.0,
+ cell_width: 3.0,
+ cell_height: 3.0,
+ padding_x: 0.0,
+ padding_y: 0.0,
+ };
+ let mut term = Term::new(&Default::default(), size);
+ let mut grid: Grid<Cell> = Grid::new(Line(3), Column(3), 0, Cell::default());
+ for l in 0..3 {
+ if l != 1 {
+ for c in 0..3 {
+ grid[Line(l)][Column(c)].c = 'a';
+ }
+ }
+ }
+
+ mem::swap(&mut term.grid, &mut grid);
+
+ let mut selection = Selection::simple(Point { line: 2, col: Column(0) }, Side::Left);
+ selection.update(Point { line: 0, col: Column(2) }, Side::Right);
+ *term.selection_mut() = Some(selection);
+ assert_eq!(term.selection_to_string(), Some("aaa\n\naaa\n".into()));
+ }
+
/// Check that the grid can be serialized back and forth losslessly
///
/// This test is in the term module as opposed to the grid since we want to
diff --git a/src/tty.rs b/src/tty.rs
index b9d00fa5..b4a8e316 100644
--- a/src/tty.rs
+++ b/src/tty.rs
@@ -216,10 +216,11 @@ pub fn new<T: ToWinsize>(config: &Config, options: &Options, size: &T, window_id
// TERM; default to 'alacritty' if it is available, otherwise
// default to 'xterm-256color'. May be overridden by user's config
// below.
- let mut term = "alacritty";
- if let Err(_) = Database::from_name("alacritty") {
- term = "xterm-256color";
- }
+ let term = if Database::from_name("alacritty").is_ok() {
+ "alacritty"
+ } else {
+ "xterm-256color"
+ };
builder.env("TERM", term);
builder.env("COLORTERM", "truecolor"); // advertise 24-bit support