Updated code to compile with Rust 1.0 alpha.
This commit is contained in:
parent
2785c3821b
commit
0fb338f05b
|
@ -5,12 +5,12 @@ use std::mem;
|
||||||
use std::str::Graphemes;
|
use std::str::Graphemes;
|
||||||
use string_utils::{grapheme_count, grapheme_pos_to_byte_pos, is_line_ending};
|
use string_utils::{grapheme_count, grapheme_pos_to_byte_pos, is_line_ending};
|
||||||
|
|
||||||
const TAB_WIDTH: uint = 4;
|
const TAB_WIDTH: usize = 4;
|
||||||
|
|
||||||
|
|
||||||
/// Returns the visual width of a grapheme given a starting
|
/// Returns the visual width of a grapheme given a starting
|
||||||
/// position on a line.
|
/// position on a line.
|
||||||
fn grapheme_vis_width_at_vis_pos(g: &str, pos: uint, tab_width: uint) -> uint {
|
fn grapheme_vis_width_at_vis_pos(g: &str, pos: usize, tab_width: usize) -> usize {
|
||||||
match g {
|
match g {
|
||||||
"\t" => {
|
"\t" => {
|
||||||
let ending_pos = ((pos / tab_width) + 1) * tab_width;
|
let ending_pos = ((pos / tab_width) + 1) * tab_width;
|
||||||
|
@ -138,7 +138,7 @@ impl Line {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check for line ending
|
// Check for line ending
|
||||||
let mut le_size: uint = 0;
|
let mut le_size: usize = 0;
|
||||||
let text_size = tl.text.len();
|
let text_size = tl.text.len();
|
||||||
if tl.text.len() >= 3 {
|
if tl.text.len() >= 3 {
|
||||||
match unsafe{mem::transmute::<&[u8], &str>(tl.text.slice_from(text_size-3))} {
|
match unsafe{mem::transmute::<&[u8], &str>(tl.text.slice_from(text_size-3))} {
|
||||||
|
@ -216,7 +216,7 @@ impl Line {
|
||||||
|
|
||||||
|
|
||||||
/// Returns the total number of unicode graphemes in the line
|
/// Returns the total number of unicode graphemes in the line
|
||||||
pub fn grapheme_count(&self) -> uint {
|
pub fn grapheme_count(&self) -> usize {
|
||||||
let mut count = grapheme_count(self.as_str());
|
let mut count = grapheme_count(self.as_str());
|
||||||
match self.ending {
|
match self.ending {
|
||||||
LineEnding::None => {},
|
LineEnding::None => {},
|
||||||
|
@ -228,13 +228,13 @@ impl Line {
|
||||||
|
|
||||||
/// Returns the total number of unicode graphemes in the line,
|
/// Returns the total number of unicode graphemes in the line,
|
||||||
/// not counting the line ending grapheme, if any.
|
/// not counting the line ending grapheme, if any.
|
||||||
pub fn grapheme_count_sans_line_ending(&self) -> uint {
|
pub fn grapheme_count_sans_line_ending(&self) -> usize {
|
||||||
grapheme_count(self.as_str())
|
grapheme_count(self.as_str())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Returns the visual cell width of the line
|
/// Returns the visual cell width of the line
|
||||||
pub fn vis_width(&self, tab_width: uint) -> uint {
|
pub fn vis_width(&self, tab_width: usize) -> usize {
|
||||||
let mut width = 0;
|
let mut width = 0;
|
||||||
|
|
||||||
for g in self.as_str().graphemes(true) {
|
for g in self.as_str().graphemes(true) {
|
||||||
|
@ -246,7 +246,7 @@ impl Line {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn grapheme_at_index<'a>(&'a self, index: uint) -> &'a str {
|
pub fn grapheme_at_index<'a>(&'a self, index: usize) -> &'a str {
|
||||||
let mut iter = self.grapheme_iter();
|
let mut iter = self.grapheme_iter();
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
|
|
||||||
|
@ -264,7 +264,7 @@ impl Line {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn grapheme_width_at_index(&self, index: uint, tab_width: uint) -> uint {
|
pub fn grapheme_width_at_index(&self, index: usize, tab_width: usize) -> usize {
|
||||||
let mut iter = self.grapheme_vis_iter(tab_width);
|
let mut iter = self.grapheme_vis_iter(tab_width);
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ impl Line {
|
||||||
|
|
||||||
|
|
||||||
/// Translates a grapheme index into a visual horizontal position
|
/// Translates a grapheme index into a visual horizontal position
|
||||||
pub fn grapheme_index_to_closest_vis_pos(&self, index: uint, tab_width: uint) -> uint {
|
pub fn grapheme_index_to_closest_vis_pos(&self, index: usize, tab_width: usize) -> usize {
|
||||||
let mut pos = 0;
|
let mut pos = 0;
|
||||||
let mut iter = self.as_str().graphemes(true);
|
let mut iter = self.as_str().graphemes(true);
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ impl Line {
|
||||||
|
|
||||||
|
|
||||||
/// Translates a visual horizontal position to the closest grapheme index
|
/// Translates a visual horizontal position to the closest grapheme index
|
||||||
pub fn vis_pos_to_closest_grapheme_index(&self, vis_pos: uint, tab_width: uint) -> uint {
|
pub fn vis_pos_to_closest_grapheme_index(&self, vis_pos: usize, tab_width: usize) -> usize {
|
||||||
let mut pos = 0;
|
let mut pos = 0;
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
let mut iter = self.as_str().graphemes(true);
|
let mut iter = self.as_str().graphemes(true);
|
||||||
|
@ -342,7 +342,7 @@ impl Line {
|
||||||
|
|
||||||
/// Inserts `text` at grapheme index `pos`.
|
/// Inserts `text` at grapheme index `pos`.
|
||||||
/// NOTE: panics if it encounters a line ending in the text.
|
/// NOTE: panics if it encounters a line ending in the text.
|
||||||
pub fn insert_text(&mut self, text: &str, pos: uint) {
|
pub fn insert_text(&mut self, text: &str, pos: usize) {
|
||||||
// Find insertion position in bytes
|
// Find insertion position in bytes
|
||||||
let byte_pos = grapheme_pos_to_byte_pos(self.as_str(), pos);
|
let byte_pos = grapheme_pos_to_byte_pos(self.as_str(), pos);
|
||||||
|
|
||||||
|
@ -398,7 +398,7 @@ impl Line {
|
||||||
|
|
||||||
|
|
||||||
/// Remove the text between grapheme positions 'pos_a' and 'pos_b'.
|
/// Remove the text between grapheme positions 'pos_a' and 'pos_b'.
|
||||||
pub fn remove_text(&mut self, pos_a: uint, pos_b: uint) {
|
pub fn remove_text(&mut self, pos_a: usize, pos_b: usize) {
|
||||||
// Bounds checks
|
// Bounds checks
|
||||||
if pos_a > pos_b {
|
if pos_a > pos_b {
|
||||||
panic!("Line::remove_text(): pos_a must be less than or equal to pos_b.");
|
panic!("Line::remove_text(): pos_a must be less than or equal to pos_b.");
|
||||||
|
@ -427,7 +427,7 @@ impl Line {
|
||||||
/// Insert a line break into the line, splitting it into two.
|
/// Insert a line break into the line, splitting it into two.
|
||||||
/// This line stays as the first part of the split. The second
|
/// This line stays as the first part of the split. The second
|
||||||
/// part is returned.
|
/// part is returned.
|
||||||
pub fn split(&mut self, ending: LineEnding, pos: uint) -> Line {
|
pub fn split(&mut self, ending: LineEnding, pos: usize) -> Line {
|
||||||
let mut other = Line::new();
|
let mut other = Line::new();
|
||||||
|
|
||||||
// Inserting at very beginning: special cased for efficiency
|
// Inserting at very beginning: special cased for efficiency
|
||||||
|
@ -466,7 +466,7 @@ impl Line {
|
||||||
|
|
||||||
|
|
||||||
/// Returns an iterator over the graphemes of the line
|
/// Returns an iterator over the graphemes of the line
|
||||||
pub fn grapheme_iter_at_index<'a>(&'a self, index: uint) -> LineGraphemeIter<'a> {
|
pub fn grapheme_iter_at_index<'a>(&'a self, index: usize) -> LineGraphemeIter<'a> {
|
||||||
let temp: &str = unsafe{mem::transmute(self.text.as_slice())};
|
let temp: &str = unsafe{mem::transmute(self.text.as_slice())};
|
||||||
|
|
||||||
let mut iter = LineGraphemeIter {
|
let mut iter = LineGraphemeIter {
|
||||||
|
@ -484,7 +484,7 @@ impl Line {
|
||||||
|
|
||||||
|
|
||||||
/// Returns an iterator over the graphemes of the line
|
/// Returns an iterator over the graphemes of the line
|
||||||
pub fn grapheme_vis_iter<'a>(&'a self, tab_width: uint) -> LineGraphemeVisIter<'a> {
|
pub fn grapheme_vis_iter<'a>(&'a self, tab_width: usize) -> LineGraphemeVisIter<'a> {
|
||||||
LineGraphemeVisIter {
|
LineGraphemeVisIter {
|
||||||
graphemes: self.grapheme_iter(),
|
graphemes: self.grapheme_iter(),
|
||||||
vis_pos: 0,
|
vis_pos: 0,
|
||||||
|
@ -563,7 +563,7 @@ pub fn str_to_line_ending(g: &str) -> LineEnding {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn line_ending_to_str(ending: LineEnding) -> &'static str {
|
pub fn line_ending_to_str(ending: LineEnding) -> &'static str {
|
||||||
LINE_ENDINGS[ending as uint]
|
LINE_ENDINGS[ending as usize]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An array of string literals corresponding to the possible
|
/// An array of string literals corresponding to the possible
|
||||||
|
@ -588,7 +588,7 @@ pub struct LineGraphemeIter<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> LineGraphemeIter<'a> {
|
impl<'a> LineGraphemeIter<'a> {
|
||||||
pub fn skip_graphemes(&mut self, n: uint) {
|
pub fn skip_graphemes(&mut self, n: usize) {
|
||||||
for _ in range(0, n) {
|
for _ in range(0, n) {
|
||||||
if let None = self.next() {
|
if let None = self.next() {
|
||||||
break;
|
break;
|
||||||
|
@ -616,7 +616,7 @@ impl<'a> Iterator for LineGraphemeIter<'a> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return Some(LINE_ENDINGS[self.ending as uint]);
|
return Some(LINE_ENDINGS[self.ending as usize]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -632,12 +632,12 @@ impl<'a> Iterator for LineGraphemeIter<'a> {
|
||||||
/// visual width.
|
/// visual width.
|
||||||
pub struct LineGraphemeVisIter<'a> {
|
pub struct LineGraphemeVisIter<'a> {
|
||||||
graphemes: LineGraphemeIter<'a>,
|
graphemes: LineGraphemeIter<'a>,
|
||||||
vis_pos: uint,
|
vis_pos: usize,
|
||||||
tab_width: uint,
|
tab_width: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> LineGraphemeVisIter<'a> {
|
impl<'a> LineGraphemeVisIter<'a> {
|
||||||
pub fn skip_graphemes(&mut self, n: uint) {
|
pub fn skip_graphemes(&mut self, n: usize) {
|
||||||
for _ in range(0, n) {
|
for _ in range(0, n) {
|
||||||
if let None = self.next() {
|
if let None = self.next() {
|
||||||
break;
|
break;
|
||||||
|
@ -647,7 +647,7 @@ impl<'a> LineGraphemeVisIter<'a> {
|
||||||
|
|
||||||
// Skips at least n visual positions, and returns the number of excess
|
// Skips at least n visual positions, and returns the number of excess
|
||||||
// skipped visual positions beyond n.
|
// skipped visual positions beyond n.
|
||||||
pub fn skip_vis_positions(&mut self, n: uint) -> uint {
|
pub fn skip_vis_positions(&mut self, n: usize) -> usize {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while i < n {
|
while i < n {
|
||||||
if let Some((_, _, width)) = self.next() {
|
if let Some((_, _, width)) = self.next() {
|
||||||
|
@ -668,9 +668,9 @@ impl<'a> LineGraphemeVisIter<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Iterator for LineGraphemeVisIter<'a> {
|
impl<'a> Iterator for LineGraphemeVisIter<'a> {
|
||||||
type Item = (&'a str, uint, uint);
|
type Item = (&'a str, usize, usize);
|
||||||
|
|
||||||
fn next(&mut self) -> Option<(&'a str, uint, uint)> {
|
fn next(&mut self) -> Option<(&'a str, usize, usize)> {
|
||||||
if let Some(g) = self.graphemes.next() {
|
if let Some(g) = self.graphemes.next() {
|
||||||
let pos = self.vis_pos;
|
let pos = self.vis_pos;
|
||||||
let width = grapheme_vis_width_at_vis_pos(g, self.vis_pos, self.tab_width);
|
let width = grapheme_vis_width_at_vis_pos(g, self.vis_pos, self.tab_width);
|
||||||
|
|
|
@ -30,17 +30,17 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn len(&self) -> uint {
|
pub fn len(&self) -> usize {
|
||||||
self.text.grapheme_count
|
self.text.grapheme_count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn line_count(&self) -> uint {
|
pub fn line_count(&self) -> usize {
|
||||||
self.text.line_count
|
self.text.line_count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn get_grapheme<'a>(&'a self, index: uint) -> &'a str {
|
pub fn get_grapheme<'a>(&'a self, index: usize) -> &'a str {
|
||||||
if index >= self.len() {
|
if index >= self.len() {
|
||||||
panic!("Buffer::get_grapheme(): index past last grapheme.");
|
panic!("Buffer::get_grapheme(): index past last grapheme.");
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn get_grapheme_width(&self, index: uint, tab_width: uint) -> uint {
|
pub fn get_grapheme_width(&self, index: usize, tab_width: usize) -> usize {
|
||||||
if index >= self.len() {
|
if index >= self.len() {
|
||||||
panic!("Buffer::get_grapheme_width(): index past last grapheme.");
|
panic!("Buffer::get_grapheme_width(): index past last grapheme.");
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn get_line<'a>(&'a self, index: uint) -> &'a Line {
|
pub fn get_line<'a>(&'a self, index: usize) -> &'a Line {
|
||||||
if index >= self.line_count() {
|
if index >= self.line_count() {
|
||||||
panic!("get_line(): index out of bounds.");
|
panic!("get_line(): index out of bounds.");
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ impl Buffer {
|
||||||
|
|
||||||
|
|
||||||
/// Removes the lines in line indices [line_a, line_b).
|
/// Removes the lines in line indices [line_a, line_b).
|
||||||
pub fn remove_lines(&mut self, line_a: uint, line_b: uint) {
|
pub fn remove_lines(&mut self, line_a: usize, line_b: usize) {
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
if line_a == line_b {
|
if line_a == line_b {
|
||||||
return;
|
return;
|
||||||
|
@ -107,12 +107,12 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn pos_2d_to_closest_1d(&self, pos: (uint, uint)) -> uint {
|
pub fn pos_2d_to_closest_1d(&self, pos: (usize, usize)) -> usize {
|
||||||
return self.text.pos_2d_to_closest_1d_recursive(pos);
|
return self.text.pos_2d_to_closest_1d_recursive(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn pos_vis_2d_to_closest_1d(&self, pos: (uint, uint), tab_width: uint) -> uint {
|
pub fn pos_vis_2d_to_closest_1d(&self, pos: (usize, usize), tab_width: usize) -> usize {
|
||||||
if pos.0 >= self.line_count() {
|
if pos.0 >= self.line_count() {
|
||||||
return self.len();
|
return self.len();
|
||||||
}
|
}
|
||||||
|
@ -124,12 +124,12 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn pos_1d_to_closest_2d(&self, pos: uint) -> (uint, uint) {
|
pub fn pos_1d_to_closest_2d(&self, pos: usize) -> (usize, usize) {
|
||||||
return self.text.pos_1d_to_closest_2d_recursive(pos);
|
return self.text.pos_1d_to_closest_2d_recursive(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn pos_1d_to_closest_vis_2d(&self, pos: uint, tab_width: uint) -> (uint, uint) {
|
pub fn pos_1d_to_closest_vis_2d(&self, pos: usize, tab_width: usize) -> (usize, usize) {
|
||||||
let (v, h) = self.text.pos_1d_to_closest_2d_recursive(pos);
|
let (v, h) = self.text.pos_1d_to_closest_2d_recursive(pos);
|
||||||
let vis_h = self.get_line(v).grapheme_index_to_closest_vis_pos(h, tab_width);
|
let vis_h = self.get_line(v).grapheme_index_to_closest_vis_pos(h, tab_width);
|
||||||
return (v, vis_h);
|
return (v, vis_h);
|
||||||
|
@ -137,13 +137,13 @@ impl Buffer {
|
||||||
|
|
||||||
|
|
||||||
/// Insert 'text' at grapheme position 'pos'.
|
/// Insert 'text' at grapheme position 'pos'.
|
||||||
pub fn insert_text(&mut self, text: &str, pos: uint) {
|
pub fn insert_text(&mut self, text: &str, pos: usize) {
|
||||||
self.text.insert_text(text, pos);
|
self.text.insert_text(text, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Remove the text between grapheme positions 'pos_a' and 'pos_b'.
|
/// Remove the text between grapheme positions 'pos_a' and 'pos_b'.
|
||||||
pub fn remove_text(&mut self, pos_a: uint, pos_b: uint) {
|
pub fn remove_text(&mut self, pos_a: usize, pos_b: usize) {
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
if pos_a == pos_b {
|
if pos_a == pos_b {
|
||||||
return;
|
return;
|
||||||
|
@ -182,7 +182,7 @@ impl Buffer {
|
||||||
/// Creates an iterator starting at the specified grapheme index.
|
/// Creates an iterator starting at the specified grapheme index.
|
||||||
/// If the index is past the end of the text, then the iterator will
|
/// If the index is past the end of the text, then the iterator will
|
||||||
/// return None on next().
|
/// return None on next().
|
||||||
pub fn grapheme_iter_at_index<'a>(&'a self, index: uint) -> BufferGraphemeIter<'a> {
|
pub fn grapheme_iter_at_index<'a>(&'a self, index: usize) -> BufferGraphemeIter<'a> {
|
||||||
BufferGraphemeIter {
|
BufferGraphemeIter {
|
||||||
gi: self.text.grapheme_iter_at_index(index)
|
gi: self.text.grapheme_iter_at_index(index)
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn line_iter_at_index<'a>(&'a self, index: uint) -> BufferLineIter<'a> {
|
pub fn line_iter_at_index<'a>(&'a self, index: usize) -> BufferLineIter<'a> {
|
||||||
BufferLineIter {
|
BufferLineIter {
|
||||||
li: self.text.line_iter_at_index(index)
|
li: self.text.line_iter_at_index(index)
|
||||||
}
|
}
|
||||||
|
@ -230,12 +230,12 @@ impl<'a> BufferGraphemeIter<'a> {
|
||||||
// Skips the iterator n graphemes ahead.
|
// Skips the iterator n graphemes ahead.
|
||||||
// If it runs out of graphemes before reaching the desired skip count,
|
// If it runs out of graphemes before reaching the desired skip count,
|
||||||
// returns false. Otherwise returns true.
|
// returns false. Otherwise returns true.
|
||||||
pub fn skip_graphemes(&mut self, n: uint) -> bool {
|
pub fn skip_graphemes(&mut self, n: usize) -> bool {
|
||||||
self.gi.skip_graphemes(n)
|
self.gi.skip_graphemes(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn skip_non_newline_graphemes(&mut self, n: uint) -> bool {
|
pub fn skip_non_newline_graphemes(&mut self, n: usize) -> bool {
|
||||||
let mut i: uint = 0;
|
let mut i: usize = 0;
|
||||||
|
|
||||||
for g in self.gi {
|
for g in self.gi {
|
||||||
if is_line_ending(g) {
|
if is_line_ending(g) {
|
||||||
|
|
|
@ -11,10 +11,10 @@ pub enum BufferNodeData {
|
||||||
|
|
||||||
pub struct BufferNode {
|
pub struct BufferNode {
|
||||||
pub data: BufferNodeData,
|
pub data: BufferNodeData,
|
||||||
pub tree_height: uint,
|
pub tree_height: usize,
|
||||||
|
|
||||||
pub grapheme_count: uint,
|
pub grapheme_count: usize,
|
||||||
pub line_count: uint,
|
pub line_count: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BufferNode {
|
impl BufferNode {
|
||||||
|
@ -129,10 +129,10 @@ impl BufferNode {
|
||||||
/// Rebalances the tree under the node
|
/// Rebalances the tree under the node
|
||||||
fn rebalance(&mut self) {
|
fn rebalance(&mut self) {
|
||||||
loop {
|
loop {
|
||||||
let mut rot: int;
|
let mut rot: isize;
|
||||||
|
|
||||||
if let BufferNodeData::Branch(ref mut left, ref mut right) = self.data {
|
if let BufferNodeData::Branch(ref mut left, ref mut right) = self.data {
|
||||||
let height_diff = (left.tree_height as int) - (right.tree_height as int);
|
let height_diff = (left.tree_height as isize) - (right.tree_height as isize);
|
||||||
|
|
||||||
// Left side higher than right side
|
// Left side higher than right side
|
||||||
if height_diff > 1 {
|
if height_diff > 1 {
|
||||||
|
@ -184,7 +184,7 @@ impl BufferNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn get_grapheme_recursive<'a>(&'a self, index: uint) -> &'a str {
|
pub fn get_grapheme_recursive<'a>(&'a self, index: usize) -> &'a str {
|
||||||
match self.data {
|
match self.data {
|
||||||
BufferNodeData::Leaf(ref line) => {
|
BufferNodeData::Leaf(ref line) => {
|
||||||
return line.grapheme_at_index(index);
|
return line.grapheme_at_index(index);
|
||||||
|
@ -202,7 +202,7 @@ impl BufferNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn get_grapheme_width_recursive(&self, index: uint, tab_width: uint) -> uint {
|
pub fn get_grapheme_width_recursive(&self, index: usize, tab_width: usize) -> usize {
|
||||||
match self.data {
|
match self.data {
|
||||||
BufferNodeData::Leaf(ref line) => {
|
BufferNodeData::Leaf(ref line) => {
|
||||||
return line.grapheme_width_at_index(index, tab_width);
|
return line.grapheme_width_at_index(index, tab_width);
|
||||||
|
@ -220,7 +220,7 @@ impl BufferNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn get_line_recursive<'a>(&'a self, index: uint) -> &'a Line {
|
pub fn get_line_recursive<'a>(&'a self, index: usize) -> &'a Line {
|
||||||
match self.data {
|
match self.data {
|
||||||
BufferNodeData::Leaf(ref line) => {
|
BufferNodeData::Leaf(ref line) => {
|
||||||
if index != 0 {
|
if index != 0 {
|
||||||
|
@ -241,7 +241,7 @@ impl BufferNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn pos_2d_to_closest_1d_recursive(&self, pos: (uint, uint)) -> uint {
|
pub fn pos_2d_to_closest_1d_recursive(&self, pos: (usize, usize)) -> usize {
|
||||||
match self.data {
|
match self.data {
|
||||||
BufferNodeData::Leaf(ref line) => {
|
BufferNodeData::Leaf(ref line) => {
|
||||||
if pos.0 != 0 {
|
if pos.0 != 0 {
|
||||||
|
@ -273,7 +273,7 @@ impl BufferNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn pos_1d_to_closest_2d_recursive(&self, pos: uint) -> (uint, uint) {
|
pub fn pos_1d_to_closest_2d_recursive(&self, pos: usize) -> (usize, usize) {
|
||||||
match self.data {
|
match self.data {
|
||||||
BufferNodeData::Leaf(_) => {
|
BufferNodeData::Leaf(_) => {
|
||||||
return (0, min(pos, self.grapheme_count));
|
return (0, min(pos, self.grapheme_count));
|
||||||
|
@ -293,14 +293,14 @@ impl BufferNode {
|
||||||
|
|
||||||
|
|
||||||
/// Insert 'text' at grapheme position 'pos'.
|
/// Insert 'text' at grapheme position 'pos'.
|
||||||
pub fn insert_text(&mut self, text: &str, pos: uint) {
|
pub fn insert_text(&mut self, text: &str, pos: usize) {
|
||||||
// Byte indices
|
// Byte indices
|
||||||
let mut b1: uint = 0;
|
let mut b1: usize = 0;
|
||||||
let mut b2: uint = 0;
|
let mut b2: usize = 0;
|
||||||
|
|
||||||
// Grapheme indices
|
// Grapheme indices
|
||||||
let mut g1: uint = 0;
|
let mut g1: usize = 0;
|
||||||
let mut g2: uint = 0;
|
let mut g2: usize = 0;
|
||||||
|
|
||||||
// Iterate through graphemes
|
// Iterate through graphemes
|
||||||
for grapheme in text.grapheme_indices(true) {
|
for grapheme in text.grapheme_indices(true) {
|
||||||
|
@ -332,7 +332,7 @@ impl BufferNode {
|
||||||
|
|
||||||
/// Inserts the given text string at the given grapheme position.
|
/// Inserts the given text string at the given grapheme position.
|
||||||
/// Note: this assumes the given text has no newline graphemes.
|
/// Note: this assumes the given text has no newline graphemes.
|
||||||
pub fn insert_text_recursive(&mut self, text: &str, pos: uint) {
|
pub fn insert_text_recursive(&mut self, text: &str, pos: usize) {
|
||||||
match self.data {
|
match self.data {
|
||||||
// Find node for text to be inserted into
|
// Find node for text to be inserted into
|
||||||
BufferNodeData::Branch(ref mut left, ref mut right) => {
|
BufferNodeData::Branch(ref mut left, ref mut right) => {
|
||||||
|
@ -356,7 +356,7 @@ impl BufferNode {
|
||||||
|
|
||||||
|
|
||||||
/// Inserts a line break at the given grapheme position
|
/// Inserts a line break at the given grapheme position
|
||||||
pub fn insert_line_break_recursive(&mut self, ending: LineEnding, pos: uint) {
|
pub fn insert_line_break_recursive(&mut self, ending: LineEnding, pos: usize) {
|
||||||
if ending == LineEnding::None {
|
if ending == LineEnding::None {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -387,8 +387,8 @@ impl BufferNode {
|
||||||
if do_split {
|
if do_split {
|
||||||
// Insert line break
|
// Insert line break
|
||||||
let new_line = old_line.split(ending, pos);
|
let new_line = old_line.split(ending, pos);
|
||||||
let new_node_a = box BufferNode::new_from_line(old_line);
|
let new_node_a = Box::new(BufferNode::new_from_line(old_line));
|
||||||
let new_node_b = box BufferNode::new_from_line(new_line);
|
let new_node_b = Box::new(BufferNode::new_from_line(new_line));
|
||||||
|
|
||||||
self.data = BufferNodeData::Branch(new_node_a, new_node_b);
|
self.data = BufferNodeData::Branch(new_node_a, new_node_b);
|
||||||
|
|
||||||
|
@ -404,12 +404,12 @@ impl BufferNode {
|
||||||
/// Removes text between grapheme positions pos_a and pos_b.
|
/// Removes text between grapheme positions pos_a and pos_b.
|
||||||
/// Returns true if a dangling left side remains from the removal.
|
/// Returns true if a dangling left side remains from the removal.
|
||||||
/// Returns false otherwise.
|
/// Returns false otherwise.
|
||||||
pub fn remove_text_recursive(&mut self, pos_a: uint, pos_b: uint, is_last: bool) -> bool {
|
pub fn remove_text_recursive(&mut self, pos_a: usize, pos_b: usize, is_last: bool) -> bool {
|
||||||
let mut temp_node = BufferNode::new();
|
let mut temp_node = BufferNode::new();
|
||||||
let mut total_side_removal = false;
|
let mut total_side_removal = false;
|
||||||
let mut dangling_line = false;
|
let mut dangling_line = false;
|
||||||
let mut do_merge_fix = false;
|
let mut do_merge_fix = false;
|
||||||
let mut merge_line_number: uint = 0;
|
let mut merge_line_number: usize = 0;
|
||||||
|
|
||||||
match self.data {
|
match self.data {
|
||||||
BufferNodeData::Branch(ref mut left, ref mut right) => {
|
BufferNodeData::Branch(ref mut left, ref mut right) => {
|
||||||
|
@ -509,8 +509,8 @@ impl BufferNode {
|
||||||
mem::swap(this_line, &mut other_line);
|
mem::swap(this_line, &mut other_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_node_a = box BufferNode::new_from_line(other_line);
|
let new_node_a = Box::new(BufferNode::new_from_line(other_line));
|
||||||
let new_node_b = box BufferNode::new_from_line(line);
|
let new_node_b = Box::new(BufferNode::new_from_line(line));
|
||||||
self.data = BufferNodeData::Branch(new_node_a, new_node_b);
|
self.data = BufferNodeData::Branch(new_node_a, new_node_b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -520,7 +520,7 @@ impl BufferNode {
|
||||||
|
|
||||||
|
|
||||||
/// Removes lines in line number range [line_a, line_b)
|
/// Removes lines in line number range [line_a, line_b)
|
||||||
pub fn remove_lines_recursive(&mut self, line_a: uint, line_b: uint) {
|
pub fn remove_lines_recursive(&mut self, line_a: usize, line_b: usize) {
|
||||||
let mut remove_left = false;
|
let mut remove_left = false;
|
||||||
let mut remove_right = false;
|
let mut remove_right = false;
|
||||||
let mut temp_node = BufferNode::new();
|
let mut temp_node = BufferNode::new();
|
||||||
|
@ -573,7 +573,7 @@ impl BufferNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn merge_line_with_next_recursive(&mut self, line_number: uint, fetched_line: Option<&Line>) {
|
pub fn merge_line_with_next_recursive(&mut self, line_number: usize, fetched_line: Option<&Line>) {
|
||||||
match fetched_line {
|
match fetched_line {
|
||||||
None => {
|
None => {
|
||||||
let line: Option<Line> = self.pull_out_line_recursive(line_number + 1);
|
let line: Option<Line> = self.pull_out_line_recursive(line_number + 1);
|
||||||
|
@ -607,7 +607,7 @@ impl BufferNode {
|
||||||
|
|
||||||
|
|
||||||
/// Removes a single line out of the text and returns it.
|
/// Removes a single line out of the text and returns it.
|
||||||
pub fn pull_out_line_recursive(&mut self, line_number: uint) -> Option<Line> {
|
pub fn pull_out_line_recursive(&mut self, line_number: usize) -> Option<Line> {
|
||||||
let mut pulled_line = Line::new();
|
let mut pulled_line = Line::new();
|
||||||
let mut temp_node = BufferNode::new();
|
let mut temp_node = BufferNode::new();
|
||||||
let mut side_removal = false;
|
let mut side_removal = false;
|
||||||
|
@ -702,7 +702,7 @@ impl BufferNode {
|
||||||
|
|
||||||
|
|
||||||
/// Creates an iterator at the given grapheme index
|
/// Creates an iterator at the given grapheme index
|
||||||
pub fn grapheme_iter_at_index<'a>(&'a self, index: uint) -> BufferNodeGraphemeIter<'a> {
|
pub fn grapheme_iter_at_index<'a>(&'a self, index: usize) -> BufferNodeGraphemeIter<'a> {
|
||||||
let mut node_stack: Vec<&'a BufferNode> = Vec::new();
|
let mut node_stack: Vec<&'a BufferNode> = Vec::new();
|
||||||
let mut cur_node = self;
|
let mut cur_node = self;
|
||||||
let mut grapheme_i = index;
|
let mut grapheme_i = index;
|
||||||
|
@ -763,7 +763,7 @@ impl BufferNode {
|
||||||
|
|
||||||
|
|
||||||
/// Creates a line iterator starting at the given line index
|
/// Creates a line iterator starting at the given line index
|
||||||
pub fn line_iter_at_index<'a>(&'a self, index: uint) -> BufferNodeLineIter<'a> {
|
pub fn line_iter_at_index<'a>(&'a self, index: usize) -> BufferNodeLineIter<'a> {
|
||||||
let mut node_stack: Vec<&'a BufferNode> = Vec::new();
|
let mut node_stack: Vec<&'a BufferNode> = Vec::new();
|
||||||
let mut cur_node = self;
|
let mut cur_node = self;
|
||||||
let mut line_i = index;
|
let mut line_i = index;
|
||||||
|
@ -841,7 +841,7 @@ impl<'a> BufferNodeGraphemeIter<'a> {
|
||||||
// Skips the iterator n graphemes ahead.
|
// Skips the iterator n graphemes ahead.
|
||||||
// If it runs out of graphemes before reaching the desired skip count,
|
// If it runs out of graphemes before reaching the desired skip count,
|
||||||
// returns false. Otherwise returns true.
|
// returns false. Otherwise returns true.
|
||||||
pub fn skip_graphemes(&mut self, n: uint) -> bool {
|
pub fn skip_graphemes(&mut self, n: usize) -> bool {
|
||||||
// TODO: more efficient implementation
|
// TODO: more efficient implementation
|
||||||
for _ in range(0, n) {
|
for _ in range(0, n) {
|
||||||
if let Option::None = self.next() {
|
if let Option::None = self.next() {
|
||||||
|
|
|
@ -14,8 +14,8 @@ use string_utils::grapheme_count;
|
||||||
/// `vis_start` is the visual 2d horizontal position of the cursor. This
|
/// `vis_start` is the visual 2d horizontal position of the cursor. This
|
||||||
/// doesn't affect editing operations at all, but is used for cursor movement.
|
/// doesn't affect editing operations at all, but is used for cursor movement.
|
||||||
pub struct Cursor {
|
pub struct Cursor {
|
||||||
pub range: (uint, uint), // start, end
|
pub range: (usize, usize), // start, end
|
||||||
pub vis_start: uint, // start
|
pub vis_start: usize, // start
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cursor {
|
impl Cursor {
|
||||||
|
@ -26,7 +26,7 @@ impl Cursor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_vis_start(&mut self, buf: &Buffer, tab_width: uint) {
|
pub fn update_vis_start(&mut self, buf: &Buffer, tab_width: usize) {
|
||||||
let (v, h) = buf.pos_1d_to_closest_2d(self.range.0);
|
let (v, h) = buf.pos_1d_to_closest_2d(self.range.0);
|
||||||
self.vis_start = buf.get_line(v).grapheme_index_to_closest_vis_pos(h, tab_width);
|
self.vis_start = buf.get_line(v).grapheme_index_to_closest_vis_pos(h, tab_width);
|
||||||
}
|
}
|
||||||
|
@ -37,12 +37,12 @@ pub struct Editor {
|
||||||
pub buffer: Buffer,
|
pub buffer: Buffer,
|
||||||
pub file_path: Path,
|
pub file_path: Path,
|
||||||
pub soft_tabs: bool,
|
pub soft_tabs: bool,
|
||||||
pub tab_width: uint,
|
pub tab_width: usize,
|
||||||
pub dirty: bool,
|
pub dirty: bool,
|
||||||
|
|
||||||
// The dimensions and position of the editor's view within the buffer
|
// The dimensions and position of the editor's view within the buffer
|
||||||
pub view_dim: (uint, uint), // (height, width)
|
pub view_dim: (usize, usize), // (height, width)
|
||||||
pub view_pos: (uint, uint), // (line, col)
|
pub view_pos: (usize, usize), // (line, col)
|
||||||
|
|
||||||
// The editing cursor position
|
// The editing cursor position
|
||||||
pub cursor: Cursor,
|
pub cursor: Cursor,
|
||||||
|
@ -91,14 +91,14 @@ impl Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn auto_detect_indentation_style(&mut self) {
|
pub fn auto_detect_indentation_style(&mut self) {
|
||||||
let mut tab_blocks: uint = 0;
|
let mut tab_blocks: usize = 0;
|
||||||
let mut space_blocks: uint = 0;
|
let mut space_blocks: usize = 0;
|
||||||
let mut space_histogram: [uint; 9] = [0, 0, 0, 0, 0, 0, 0, 0, 0];
|
let mut space_histogram: [usize; 9] = [0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||||
|
|
||||||
let mut last_indent = (false, 0u); // (was_tabs, indent_count)
|
let mut last_indent = (false, 0us); // (was_tabs, indent_count)
|
||||||
|
|
||||||
// Collect statistics
|
// Collect statistics
|
||||||
let mut line_i: uint = 0;
|
let mut line_i: usize = 0;
|
||||||
for line in self.buffer.line_iter() {
|
for line in self.buffer.line_iter() {
|
||||||
let mut g_iter = line.grapheme_iter();
|
let mut g_iter = line.grapheme_iter();
|
||||||
match g_iter.next() {
|
match g_iter.next() {
|
||||||
|
@ -184,7 +184,7 @@ impl Editor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_dim(&mut self, h: uint, w: uint) {
|
pub fn update_dim(&mut self, h: usize, w: usize) {
|
||||||
self.view_dim = (h, w);
|
self.view_dim = (h, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,13 +257,13 @@ impl Editor {
|
||||||
self.remove_text_behind_cursor(1);
|
self.remove_text_behind_cursor(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_text_at_grapheme(&mut self, text: &str, pos: uint) {
|
pub fn insert_text_at_grapheme(&mut self, text: &str, pos: usize) {
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
let buf_len = self.buffer.len();
|
let buf_len = self.buffer.len();
|
||||||
self.buffer.insert_text(text, if pos < buf_len {pos} else {buf_len});
|
self.buffer.insert_text(text, if pos < buf_len {pos} else {buf_len});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_text_behind_cursor(&mut self, grapheme_count: uint) {
|
pub fn remove_text_behind_cursor(&mut self, grapheme_count: usize) {
|
||||||
let pos_b = self.cursor.range.0;
|
let pos_b = self.cursor.range.0;
|
||||||
let pos_a = if pos_b >= grapheme_count {pos_b - grapheme_count} else {0};
|
let pos_a = if pos_b >= grapheme_count {pos_b - grapheme_count} else {0};
|
||||||
let tot_g = pos_b - pos_a;
|
let tot_g = pos_b - pos_a;
|
||||||
|
@ -281,7 +281,7 @@ impl Editor {
|
||||||
self.move_view_to_cursor();
|
self.move_view_to_cursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_text_in_front_of_cursor(&mut self, grapheme_count: uint) {
|
pub fn remove_text_in_front_of_cursor(&mut self, grapheme_count: usize) {
|
||||||
let pos_a = self.cursor.range.1;
|
let pos_a = self.cursor.range.1;
|
||||||
let pos_b = if (pos_a + grapheme_count) <= self.buffer.len() {pos_a + grapheme_count} else {self.buffer.len()};
|
let pos_b = if (pos_a + grapheme_count) <= self.buffer.len() {pos_a + grapheme_count} else {self.buffer.len()};
|
||||||
|
|
||||||
|
@ -328,7 +328,7 @@ impl Editor {
|
||||||
self.move_view_to_cursor();
|
self.move_view_to_cursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cursor_left(&mut self, n: uint) {
|
pub fn cursor_left(&mut self, n: usize) {
|
||||||
if self.cursor.range.0 >= n {
|
if self.cursor.range.0 >= n {
|
||||||
self.cursor.range.0 -= n;
|
self.cursor.range.0 -= n;
|
||||||
}
|
}
|
||||||
|
@ -343,7 +343,7 @@ impl Editor {
|
||||||
self.move_view_to_cursor();
|
self.move_view_to_cursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cursor_right(&mut self, n: uint) {
|
pub fn cursor_right(&mut self, n: usize) {
|
||||||
if self.cursor.range.1 <= (self.buffer.len() - n) {
|
if self.cursor.range.1 <= (self.buffer.len() - n) {
|
||||||
self.cursor.range.1 += n;
|
self.cursor.range.1 += n;
|
||||||
}
|
}
|
||||||
|
@ -358,7 +358,7 @@ impl Editor {
|
||||||
self.move_view_to_cursor();
|
self.move_view_to_cursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cursor_up(&mut self, n: uint) {
|
pub fn cursor_up(&mut self, n: usize) {
|
||||||
let (v, _) = self.buffer.pos_1d_to_closest_vis_2d(self.cursor.range.0, self.tab_width);
|
let (v, _) = self.buffer.pos_1d_to_closest_vis_2d(self.cursor.range.0, self.tab_width);
|
||||||
|
|
||||||
if v >= n {
|
if v >= n {
|
||||||
|
@ -373,7 +373,7 @@ impl Editor {
|
||||||
self.move_view_to_cursor();
|
self.move_view_to_cursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cursor_down(&mut self, n: uint) {
|
pub fn cursor_down(&mut self, n: usize) {
|
||||||
let (v, _) = self.buffer.pos_1d_to_closest_vis_2d(self.cursor.range.0, self.tab_width);
|
let (v, _) = self.buffer.pos_1d_to_closest_vis_2d(self.cursor.range.0, self.tab_width);
|
||||||
|
|
||||||
if v < (self.buffer.line_count() - n) {
|
if v < (self.buffer.line_count() - n) {
|
||||||
|
@ -433,7 +433,7 @@ impl Editor {
|
||||||
self.move_view_to_cursor();
|
self.move_view_to_cursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn jump_to_line(&mut self, n: uint) {
|
pub fn jump_to_line(&mut self, n: usize) {
|
||||||
let pos = self.buffer.pos_2d_to_closest_1d((n, 0));
|
let pos = self.buffer.pos_2d_to_closest_1d((n, 0));
|
||||||
let (v, _) = self.buffer.pos_1d_to_closest_vis_2d(pos, self.tab_width);
|
let (v, _) = self.buffer.pos_1d_to_closest_vis_2d(pos, self.tab_width);
|
||||||
self.cursor.range.0 = self.buffer.pos_vis_2d_to_closest_1d((v, self.cursor.vis_start), self.tab_width);
|
self.cursor.range.0 = self.buffer.pos_vis_2d_to_closest_1d((v, self.cursor.vis_start), self.tab_width);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![feature(old_orphan_check)] // Temporary, get rid of this once the new orphan check works well
|
#![feature(old_orphan_check)] // Temporary, get rid of this once the new orphan check works well
|
||||||
#![feature(associated_types)]
|
#![allow(unstable)]
|
||||||
|
|
||||||
extern crate rustbox;
|
extern crate rustbox;
|
||||||
extern crate docopt;
|
extern crate docopt;
|
||||||
|
|
|
@ -16,7 +16,7 @@ pub fn is_line_ending(text: &str) -> bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn newline_count(text: &str) -> uint {
|
pub fn newline_count(text: &str) -> usize {
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
for c in text.chars() {
|
for c in text.chars() {
|
||||||
if c == '\n' {
|
if c == '\n' {
|
||||||
|
@ -26,7 +26,7 @@ pub fn newline_count(text: &str) -> uint {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn char_count(text: &str) -> uint {
|
pub fn char_count(text: &str) -> usize {
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
for _ in text.chars() {
|
for _ in text.chars() {
|
||||||
count += 1;
|
count += 1;
|
||||||
|
@ -34,7 +34,7 @@ pub fn char_count(text: &str) -> uint {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn grapheme_count(text: &str) -> uint {
|
pub fn grapheme_count(text: &str) -> usize {
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
for _ in text.graphemes(true) {
|
for _ in text.graphemes(true) {
|
||||||
count += 1;
|
count += 1;
|
||||||
|
@ -42,7 +42,7 @@ pub fn grapheme_count(text: &str) -> uint {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn char_and_newline_count(text: &str) -> (uint, uint) {
|
pub fn char_and_newline_count(text: &str) -> (usize, usize) {
|
||||||
let mut char_count = 0;
|
let mut char_count = 0;
|
||||||
let mut newline_count = 0;
|
let mut newline_count = 0;
|
||||||
|
|
||||||
|
@ -56,8 +56,8 @@ pub fn char_and_newline_count(text: &str) -> (uint, uint) {
|
||||||
return (char_count, newline_count);
|
return (char_count, newline_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn char_pos_to_byte_pos(text: &str, pos: uint) -> uint {
|
pub fn char_pos_to_byte_pos(text: &str, pos: usize) -> usize {
|
||||||
let mut i: uint = 0;
|
let mut i: usize = 0;
|
||||||
|
|
||||||
for (offset, _) in text.char_indices() {
|
for (offset, _) in text.char_indices() {
|
||||||
if i == pos {
|
if i == pos {
|
||||||
|
@ -73,8 +73,8 @@ pub fn char_pos_to_byte_pos(text: &str, pos: uint) -> uint {
|
||||||
panic!("char_pos_to_byte_pos(): char position off the end of the string.");
|
panic!("char_pos_to_byte_pos(): char position off the end of the string.");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn grapheme_pos_to_byte_pos(text: &str, pos: uint) -> uint {
|
pub fn grapheme_pos_to_byte_pos(text: &str, pos: usize) -> usize {
|
||||||
let mut i: uint = 0;
|
let mut i: usize = 0;
|
||||||
|
|
||||||
for (offset, _) in text.grapheme_indices(true) {
|
for (offset, _) in text.grapheme_indices(true) {
|
||||||
if i == pos {
|
if i == pos {
|
||||||
|
|
|
@ -30,8 +30,8 @@ const K_CTRL_S: u16 = 19;
|
||||||
pub struct TermUI {
|
pub struct TermUI {
|
||||||
rb: rustbox::RustBox,
|
rb: rustbox::RustBox,
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
width: uint,
|
width: usize,
|
||||||
height: uint,
|
height: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -159,8 +159,8 @@ impl TermUI {
|
||||||
},
|
},
|
||||||
|
|
||||||
Ok(rustbox::Event::ResizeEvent(w, h)) => {
|
Ok(rustbox::Event::ResizeEvent(w, h)) => {
|
||||||
self.width = w as uint;
|
self.width = w as usize;
|
||||||
self.height = h as uint;
|
self.height = h as usize;
|
||||||
self.editor.update_dim(self.height-1, self.width);
|
self.editor.update_dim(self.height-1, self.width);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -239,8 +239,8 @@ impl TermUI {
|
||||||
},
|
},
|
||||||
|
|
||||||
Ok(rustbox::Event::ResizeEvent(w, h)) => {
|
Ok(rustbox::Event::ResizeEvent(w, h)) => {
|
||||||
self.width = w as uint;
|
self.width = w as usize;
|
||||||
self.height = h as uint;
|
self.height = h as usize;
|
||||||
self.editor.update_dim(self.height-1, self.width);
|
self.editor.update_dim(self.height-1, self.width);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -261,7 +261,7 @@ impl TermUI {
|
||||||
// Jump to line!
|
// Jump to line!
|
||||||
if confirm {
|
if confirm {
|
||||||
if let Some(n) = line.parse() {
|
if let Some(n) = line.parse() {
|
||||||
let n2: uint = n; // Weird work-around: the type of n wasn't being inferred
|
let n2: usize = n; // Weird work-around: the type of n wasn't being inferred
|
||||||
if n2 > 0 {
|
if n2 > 0 {
|
||||||
self.editor.jump_to_line(n2-1);
|
self.editor.jump_to_line(n2-1);
|
||||||
}
|
}
|
||||||
|
@ -275,7 +275,7 @@ impl TermUI {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn draw_editor(&self, editor: &Editor, c1: (uint, uint), c2: (uint, uint)) {
|
fn draw_editor(&self, editor: &Editor, c1: (usize, usize), c2: (usize, usize)) {
|
||||||
let foreground = Color::Black;
|
let foreground = Color::Black;
|
||||||
let background = Color::Cyan;
|
let background = Color::Cyan;
|
||||||
|
|
||||||
|
@ -291,8 +291,8 @@ impl TermUI {
|
||||||
self.rb.print(c1.1 + 1, c1.0, rustbox::RB_NORMAL, foreground, background, name.as_slice());
|
self.rb.print(c1.1 + 1, c1.0, rustbox::RB_NORMAL, foreground, background, name.as_slice());
|
||||||
|
|
||||||
// Percentage position in document
|
// Percentage position in document
|
||||||
let percentage: uint = if editor.buffer.len() > 0 {
|
let percentage: usize = if editor.buffer.len() > 0 {
|
||||||
(((editor.cursor.range.0 as f32) / (editor.buffer.len() as f32)) * 100.0) as uint
|
(((editor.cursor.range.0 as f32) / (editor.buffer.len() as f32)) * 100.0) as usize
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
100
|
100
|
||||||
|
@ -321,7 +321,7 @@ impl TermUI {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn draw_editor_text(&self, editor: &Editor, c1: (uint, uint), c2: (uint, uint)) {
|
fn draw_editor_text(&self, editor: &Editor, c1: (usize, usize), c2: (usize, usize)) {
|
||||||
let mut line_iter = editor.buffer.line_iter_at_index(editor.view_pos.0);
|
let mut line_iter = editor.buffer.line_iter_at_index(editor.view_pos.0);
|
||||||
|
|
||||||
let mut grapheme_index;
|
let mut grapheme_index;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user