Commit 85dc863f authored by Ticki's avatar Ticki

Add debug! and debugln! macro to kernel

parent 17951c05
......@@ -6,3 +6,16 @@ Known bugs:
- [ ] When using `t` with a char that isn't in the document, Sodium will crash.
- [ ] `d<motion>` does not do anything if: 1) the motion moves to the end of a line. 2) if the motion moves to the last line.
The bug causing these two bugs, is localised to be in position.rs. It resolves by returning a value one over bound x
- [ ] The x value is wrongly bounded. Reproduction:
1) Make two lines:
- abc
- abcdef
2) Go to the end of the first line.
3) Go one down. As you'll see you'll end up at d. That's right.
4) Now go two the end of the first line again.
5) Type 2l.
6) Now go one down
7) You'll end up on e, even though it should be d
......@@ -29,6 +29,7 @@ impl Editor {
/// Create new default state editor
pub fn new() -> Editor {
let window = Window::new((rand() % 400 + 50) as isize,
(rand() % 300 + 50) as isize,
700,
......
......@@ -5,8 +5,7 @@ impl Editor {
/// Redraw the window
pub fn redraw(&mut self) {
// TODO: Only draw when relevant for the window
let x = self.x();
let y = self.y();
let (x, y) = self.pos();
// Redraw window
self.window.set(Color::rgb(25, 25, 25));
......
......@@ -60,6 +60,7 @@ impl Editor {
}
},
Key::Char(c) => {
//debugln!("length is: {}. \n y is: {} \n x is: {} \n x bound is: {}", self.text.len(), y, x, self.text[y].len());
self.text[y].insert(x, c);
let right = self.right(1);
......
......@@ -23,12 +23,14 @@ impl Editor {
#[inline]
pub fn after(&self, (x, y): (usize, usize)) -> Option<(usize, usize)> {
if x == self.text[y].len() {
if y < self.text.len() - 1 {
if y < self.text.len() - 1 {
if x == self.text[y].len() - 1 {
Some((0, y + 1))
} else {
None //(x, y)
Some((x + 1, y))
}
} else if x == self.text[y].len() - 1 {
None
} else {
Some((x + 1, y))
}
......@@ -50,7 +52,7 @@ impl Editor {
/// Get the position of the right char
#[inline]
pub fn right(&self, n: usize) -> (usize, usize) {
(self.x() + n, self.y())
self.bound_hor((self.x() + n, self.y()))
}
/// Get the position of the left char
......@@ -76,7 +78,7 @@ impl Editor {
/// Get the position under the char
#[inline]
pub fn down(&self, n: usize) -> (usize, usize) {
(self.cursor().x, self.y() + n)
self.bound_ver((self.cursor().x, self.y() + n))
}
/// Get the position of the end of the line
......@@ -96,7 +98,7 @@ impl Editor {
match pos {
None => return None,
Some(mut p) => {
p = self.bounded(p);
p = self.bound(p);
if self.text[p.1][p.0] == c {
dn += 1;
......
......@@ -6,7 +6,7 @@ impl Editor {
#[inline]
pub fn pos(&self) -> (usize, usize) {
let cursor = self.cursor();
self.bounded((cursor.x, cursor.y))
self.bound((cursor.x, cursor.y))
}
#[inline]
......@@ -23,18 +23,44 @@ impl Editor {
/// Convert a position value to a bounded position value
#[inline]
pub fn bounded(&self, (x, mut y): (usize, usize)) -> (usize, usize) {
pub fn bound(&self, (x, mut y): (usize, usize)) -> (usize, usize) {
y = if y > self.text.len() - 1 {
y = if y >= self.text.len() {
self.text.len() - 1
} else {
y
};
if x >= self.text[y].len() {
(self.text[y].len(), y)
let ln = self.text[y].len();
if x >= ln {
if ln == 0 {
(0, y)
} else {
(ln - 1, y)
}
} else {
(x, y)
}
}
/// Bound horizontal
#[inline]
pub fn bound_hor(&self, (x, y): (usize, usize)) -> (usize, usize) {
(self.bound((x, y)).0, y)
}
/// Bound vertical
#[inline]
pub fn bound_ver(&self, (x, mut y): (usize, usize)) -> (usize, usize) {
// Is this premature optimization? Yes, yes it is!
y = if y > self.text.len() - 1 {
self.text.len() - 1
} else {
y
};
(x, y)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment