Updated to latest Ropey.

This commit is contained in:
Nathan Vegdahl 2018-01-11 02:05:00 -08:00
parent 3f2dbf2c13
commit 16f2aab223
6 changed files with 60 additions and 69 deletions

36
Cargo.lock generated
View File

@ -2,8 +2,8 @@
name = "Led"
version = "0.0.2"
dependencies = [
"docopt 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ropey 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
"docopt 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)",
"ropey 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
"smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -22,21 +22,16 @@ dependencies = [
[[package]]
name = "docopt"
version = "0.8.1"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
"strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "lazy_static"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "lazy_static"
version = "1.0.0"
@ -44,7 +39,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.34"
version = "0.2.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -52,7 +47,7 @@ name = "memchr"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -62,7 +57,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "redox_syscall"
version = "0.1.33"
version = "0.1.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -70,7 +65,7 @@ name = "redox_termios"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"redox_syscall 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -92,7 +87,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "ropey"
version = "0.5.5"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -156,8 +151,8 @@ name = "termion"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -205,17 +200,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d6531d44de723825aa81398a6415283229725a00fa30713812ab9323faa82fc4"
"checksum docopt 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3b5b93718f8b3e5544fcc914c43de828ca6c6ace23e0332c6080a2977b49787a"
"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73"
"checksum docopt 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d8acd393692c503b168471874953a2531df0e9ab77d0b6bbc582395743300a4a"
"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d"
"checksum libc 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)" = "36fbc8a8929c632868295d0178dd8f63fc423fd7537ad0738372bd010b3ac9b0"
"checksum libc 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)" = "96264e9b293e95d25bfcbbf8a88ffd1aedc85b754eba8b7d78012f638ba220eb"
"checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d"
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
"checksum redox_syscall 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "07b8f011e3254d5a9b318fde596d409a0001c9ae4c6e7907520c2eaa4d988c99"
"checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum regex 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "744554e01ccbd98fff8c457c3b092cd67af62a555a43bfe97ae8a0451f7799fa"
"checksum regex-syntax 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8e931c58b93d86f080c734bfd2bce7dd0079ae2331235818133c8be7f422e20e"
"checksum ropey 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6eb4b74f76bc72338d8aebb193e9575398703552530e329dae718e38e4bf2ca0"
"checksum ropey 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "661796e716a1916c9fd80457ee204b05b47afa4c1f1ceec3c7fd40e59f0e31f1"
"checksum serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)" = "db99f3919e20faa51bb2996057f5031d8685019b5a06139b1ce761da671b8526"
"checksum serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)" = "f4ba7591cfe93755e89eeecdbcc668885624829b020050e6aec99c2a03bd3fd0"
"checksum serde_derive_internals 0.19.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6e03f1c9530c3fb0a0a5c9b826bdd9246a5921ae995d75f512ac917fc4dd55b5"

View File

@ -9,7 +9,7 @@ name = "led"
path = "src/main.rs"
[dependencies]
ropey = "0.5"
ropey = "0.6"
unicode-segmentation = "1.2"
unicode-width = "0.1"
serde = "1.*"

View File

@ -107,9 +107,9 @@ impl Buffer {
/// Remove the text before grapheme position 'pos' of length 'len'.
pub fn remove_text_before(&mut self, pos: usize, len: usize) {
if pos >= len {
let removed_text = self.text.slice(pos - len, pos).to_string();
let removed_text = self.text.slice((pos - len)..pos).to_string();
self.text.remove(pos - len, pos);
self.text.remove((pos - len)..pos);
// Push operation to the undo stack
self.undo_stack
@ -124,9 +124,9 @@ impl Buffer {
/// Remove the text after grapheme position 'pos' of length 'len'.
pub fn remove_text_after(&mut self, pos: usize, len: usize) {
let removed_text = self.text.slice(pos, pos + len).to_string();
let removed_text = self.text.slice(pos..(pos + len)).to_string();
self.text.remove(pos, pos + len);
self.text.remove(pos..(pos + len));
// Push operation to the undo stack
self.undo_stack.push(RemoveTextAfter(removed_text, pos));
@ -169,8 +169,8 @@ impl Buffer {
else {
// TODO: a more efficient implementation that directly
// manipulates the node tree.
let s = self.text.slice(pos_a, pos_b).to_string();
self.text.remove(pos_a, pos_b);
let s = self.text.slice(pos_a..pos_b).to_string();
self.text.remove(pos_a..pos_b);
self.text.insert(pos_to, &s);
}
}
@ -209,7 +209,7 @@ impl Buffer {
self.text.line_to_char(line_b) - 1
};
self.text.remove(a, b);
self.text.remove(a..b);
}
}
@ -224,7 +224,7 @@ impl Buffer {
match op {
InsertText(ref s, p) => {
let size = char_count(s);
self.text.remove(p, p + size);
self.text.remove(p..(p + size));
return Some(p);
}
@ -267,7 +267,7 @@ impl Buffer {
RemoveTextBefore(ref s, p) | RemoveTextAfter(ref s, p) => {
let size = char_count(s);
self.text.remove(p, p + size);
self.text.remove(p..(p + size));
return Some(p);
}
@ -333,7 +333,7 @@ impl Buffer {
pub fn get_grapheme<'a>(&'a self, index: usize) -> &'a str {
self.text
.slice(index, index + 1)
.slice(index..(index + 1))
.graphemes()
.nth(0)
.unwrap()
@ -345,7 +345,7 @@ impl Buffer {
/// Creates a String from the buffer text in grapheme range [pos_a, posb).
fn string_from_range(&self, pos_a: usize, pos_b: usize) -> String {
self.text.slice(pos_a, pos_b).to_string()
self.text.slice(pos_a..pos_b).to_string()
}
// ------------------------------------------------------------------------
@ -362,7 +362,7 @@ impl Buffer {
/// return None on next().
pub fn grapheme_iter_at_index<'a>(&'a self, index: usize) -> ropey::iter::Graphemes<'a> {
let len = self.text.len_chars();
self.text.slice(index, len).graphemes()
self.text.slice(index..len).graphemes()
}
pub fn line_iter<'a>(&'a self) -> ropey::iter::Lines<'a> {
@ -371,8 +371,7 @@ impl Buffer {
pub fn line_iter_at_index<'a>(&'a self, line_idx: usize) -> ropey::iter::Lines<'a> {
let start = self.text.line_to_char(line_idx);
let len = self.text.len_chars();
self.text.slice(start, len).lines()
self.text.slice(start..).lines()
}
}
@ -658,7 +657,7 @@ mod tests {
assert!(buf.char_count() == 29);
assert!(buf.line_count() == 6);
buf.text.remove(0, 3);
buf.text.remove(0..3);
let mut iter = buf.grapheme_iter();
@ -701,7 +700,7 @@ mod tests {
assert!(buf.char_count() == 29);
assert!(buf.line_count() == 6);
buf.text.remove(0, 12);
buf.text.remove(0..12);
let mut iter = buf.grapheme_iter();
@ -735,7 +734,7 @@ mod tests {
assert!(buf.char_count() == 29);
assert!(buf.line_count() == 6);
buf.text.remove(5, 17);
buf.text.remove(5..17);
let mut iter = buf.grapheme_iter();
@ -769,7 +768,7 @@ mod tests {
assert!(buf.char_count() == 29);
assert!(buf.line_count() == 6);
buf.text.remove(23, 29);
buf.text.remove(23..29);
let mut iter = buf.grapheme_iter();
@ -809,7 +808,7 @@ mod tests {
assert!(buf.char_count() == 29);
assert!(buf.line_count() == 6);
buf.text.remove(17, 29);
buf.text.remove(17..29);
let mut iter = buf.grapheme_iter();
@ -843,7 +842,7 @@ mod tests {
assert!(buf.char_count() == 12);
assert!(buf.line_count() == 2);
buf.text.remove(3, 12);
buf.text.remove(3..12);
let mut iter = buf.grapheme_iter();
@ -863,7 +862,7 @@ mod tests {
assert!(buf.char_count() == 15);
assert!(buf.line_count() == 3);
buf.text.remove(5, 15);
buf.text.remove(5..15);
let mut iter = buf.grapheme_iter();
@ -885,7 +884,7 @@ mod tests {
assert!(buf.char_count() == 12);
assert!(buf.line_count() == 2);
buf.text.remove(3, 11);
buf.text.remove(3..11);
let mut iter = buf.grapheme_iter();
@ -906,7 +905,7 @@ mod tests {
assert!(buf.char_count() == 12);
assert!(buf.line_count() == 2);
buf.text.remove(8, 12);
buf.text.remove(8..12);
let mut iter = buf.grapheme_iter();
@ -931,7 +930,7 @@ mod tests {
assert!(buf.char_count() == 11);
assert!(buf.line_count() == 4);
buf.text.remove(4, 11);
buf.text.remove(4..11);
let mut iter = buf.grapheme_iter();
@ -952,7 +951,7 @@ mod tests {
assert!(buf.char_count() == 10);
assert!(buf.line_count() == 1);
buf.text.remove(9, 10);
buf.text.remove(9..10);
let mut iter = buf.grapheme_iter();

View File

@ -100,13 +100,13 @@ impl<T: LineFormatter> Editor<T> {
for line in self.buffer.line_iter().take(100) {
// Get the line ending
let ending = if line.len_chars() == 1 {
let g = line.slice(line.len_chars() - 1, line.len_chars())
let g = line.slice((line.len_chars() - 1)..)
.graphemes()
.last()
.unwrap();
str_to_line_ending(g)
} else if line.len_chars() > 1 {
let g = line.slice(line.len_chars() - 2, line.len_chars())
let g = line.slice((line.len_chars() - 2)..)
.graphemes()
.last()
.unwrap();

View File

@ -53,7 +53,7 @@ pub trait LineFormatter {
// Get an iter into the right block
let a = line_block * LINE_BLOCK_LENGTH;
let b = min(line.len_chars(), (line_block + 1) * LINE_BLOCK_LENGTH);
let g_iter = line.slice(a, b).graphemes();
let g_iter = line.slice(a..b).graphemes();
return self.index_to_v2d(g_iter, col_i_adjusted).1;
}
@ -78,8 +78,8 @@ pub trait LineFormatter {
let mut line = buf.get_line(line_i);
let (mut y, x) = self.index_to_v2d(
line.slice(
line_block * LINE_BLOCK_LENGTH,
min(line.len_chars(), (line_block + 1) * LINE_BLOCK_LENGTH),
(line_block * LINE_BLOCK_LENGTH)
..min(line.len_chars(), (line_block + 1) * LINE_BLOCK_LENGTH),
).graphemes(),
col_i_adjusted,
);
@ -91,8 +91,8 @@ pub trait LineFormatter {
loop {
line = buf.get_line(line_i);
let (h, _) = self.dimensions(line.slice(
block_index * LINE_BLOCK_LENGTH,
min(line.len_chars(), (block_index + 1) * LINE_BLOCK_LENGTH),
(block_index * LINE_BLOCK_LENGTH)
..min(line.len_chars(), (block_index + 1) * LINE_BLOCK_LENGTH),
).graphemes());
if new_y >= 0 && new_y < h as isize {
@ -128,8 +128,8 @@ pub trait LineFormatter {
block_index -= 1;
}
let (h, _) = self.dimensions(line.slice(
block_index * LINE_BLOCK_LENGTH,
min(line.len_chars(), (block_index + 1) * LINE_BLOCK_LENGTH),
(block_index * LINE_BLOCK_LENGTH)
..min(line.len_chars(), (block_index + 1) * LINE_BLOCK_LENGTH),
).graphemes());
new_y += h as isize;
} else {
@ -141,8 +141,8 @@ pub trait LineFormatter {
// Next, convert the resulting coordinates back into buffer-wide
// coordinates.
let block_slice = line.slice(
block_index * LINE_BLOCK_LENGTH,
min(line.len_chars(), (block_index + 1) * LINE_BLOCK_LENGTH),
(block_index * LINE_BLOCK_LENGTH)
..min(line.len_chars(), (block_index + 1) * LINE_BLOCK_LENGTH),
);
let block_col_i = min(
self.v2d_to_index(block_slice.graphemes(), (y, x), rounding),
@ -173,11 +173,11 @@ pub trait LineFormatter {
// Calculate the horizontal position
let (v, _) = self.index_to_v2d(
line.slice(start_index, end_index).graphemes(),
line.slice(start_index..end_index).graphemes(),
col_i_adjusted,
);
let block_col_i = self.v2d_to_index(
line.slice(start_index, end_index).graphemes(),
line.slice(start_index..end_index).graphemes(),
(v, horizontal),
(RoundingBehavior::Floor, rounding),
);

View File

@ -369,8 +369,8 @@ impl TermUI {
let (vis_line_offset, _) = editor.formatter.index_to_v2d(
temp_line
.slice(
line_block_index * LINE_BLOCK_LENGTH,
min(
(line_block_index * LINE_BLOCK_LENGTH)
..min(
temp_line.len_chars(),
(line_block_index + 1) * LINE_BLOCK_LENGTH,
),
@ -413,8 +413,7 @@ impl TermUI {
let mut lines_traversed: usize = 0;
let line_len = line.len_chars();
let mut g_iter = editor.formatter.iter(line.slice(
line_block_index * LINE_BLOCK_LENGTH,
line_len,
(line_block_index * LINE_BLOCK_LENGTH)..line_len,
).graphemes());
loop {
@ -505,8 +504,7 @@ impl TermUI {
line_g_index = 0;
let line_len = line.len_chars();
g_iter = editor.formatter.iter(line.slice(
line_block_index * LINE_BLOCK_LENGTH,
line_len,
(line_block_index * LINE_BLOCK_LENGTH)..line_len,
).graphemes());
lines_traversed += 1;
}