Skip to content
Snippets Groups Projects
Commit ffb461c6 authored by Ticki's avatar Ticki
Browse files

Aaaand, it working (almost)

parent 37f32f45
No related branches found
No related tags found
No related merge requests found
...@@ -121,7 +121,7 @@ impl<'a> Buffer<'a> for SplitBuffer { ...@@ -121,7 +121,7 @@ impl<'a> Buffer<'a> for SplitBuffer {
if n < self.before.len() { if n < self.before.len() {
Some(&self.before[n]) Some(&self.before[n])
} else if n < self.len() { } else if n < self.len() {
let n = self.after.len() - (n - self.before.len()) - 1; let n = self.len() + 1 - n;
Some(&self.after[n]) Some(&self.after[n])
} else { } else {
None None
...@@ -133,7 +133,7 @@ impl<'a> Buffer<'a> for SplitBuffer { ...@@ -133,7 +133,7 @@ impl<'a> Buffer<'a> for SplitBuffer {
if n < self.before.len() { if n < self.before.len() {
Some(&mut self.before[n]) Some(&mut self.before[n])
} else if n < self.len() { } else if n < self.len() {
let n = self.after.len() - (n - self.before.len()) - 1; let n = self.len() + 1 - n;
Some(&mut self.after[n]) Some(&mut self.after[n])
} else { } else {
None None
...@@ -145,7 +145,7 @@ impl<'a> Buffer<'a> for SplitBuffer { ...@@ -145,7 +145,7 @@ impl<'a> Buffer<'a> for SplitBuffer {
if n < self.before.len() { if n < self.before.len() {
self.before.remove(n) self.before.remove(n)
} else if n < self.len() { } else if n < self.len() {
let n = self.after.len() - (n - self.before.len()) - 1; let n = self.len() + 1 - n;
self.after.remove(n) self.after.remove(n)
} else { } else {
panic!("Out of bound"); panic!("Out of bound");
...@@ -157,7 +157,7 @@ impl<'a> Buffer<'a> for SplitBuffer { ...@@ -157,7 +157,7 @@ impl<'a> Buffer<'a> for SplitBuffer {
if n < self.before.len() { if n < self.before.len() {
self.before.insert(n, line); self.before.insert(n, line);
} else if n < self.len() { } else if n < self.len() {
let n = self.after.len() - (n - self.before.len()) - 1; let n = self.len() + 1 - n;
self.after.insert(n, line); self.after.insert(n, line);
} else { } else {
panic!("Out of bound"); panic!("Out of bound");
...@@ -210,19 +210,18 @@ impl<'a> Buffer<'a> for SplitBuffer { ...@@ -210,19 +210,18 @@ impl<'a> Buffer<'a> for SplitBuffer {
/// Get the leading whitespaces of the nth line. Used for autoindenting. /// Get the leading whitespaces of the nth line. Used for autoindenting.
fn get_indent(&self, n: usize) -> &str { fn get_indent(&self, n: usize) -> &str {
let ln = if let Some(s) = self.get_line(n) { if let Some(ln) = self.get_line(n) {
s let mut len = 0;
} else { for c in ln.chars() {
return ""; match c {
}; '\t' | ' ' => len += 1,
let mut len = 0; _ => break,
for c in ln.chars() { }
match c {
'\t' | ' ' => len += 1,
_ => break,
} }
&ln[..len]
} else {
""
} }
&ln[..len]
} }
} }
...@@ -265,13 +264,12 @@ impl<'a> Iterator for SplitBufIter<'a> { ...@@ -265,13 +264,12 @@ impl<'a> Iterator for SplitBufIter<'a> {
type Item = &'a String; type Item = &'a String;
fn next(&mut self) -> Option<&'a String> { fn next(&mut self) -> Option<&'a String> {
let ln = self.line; self.nth(1)
self.nth(ln)
} }
fn nth(&mut self, n: usize) -> Option<&'a String> { fn nth(&mut self, n: usize) -> Option<&'a String> {
self.line = n; self.line += n;
self.buffer.get_line(n) self.buffer.get_line(self.line)
} }
fn count(self) -> usize { fn count(self) -> usize {
......
...@@ -41,7 +41,6 @@ impl Editor { ...@@ -41,7 +41,6 @@ impl Editor {
/// Create new default state editor /// Create new default state editor
pub fn init() { pub fn init() {
#[cfg(feature = "orbital")] #[cfg(feature = "orbital")]
let window = Window::new(-1, -1, 700, 500, &"Sodium").unwrap(); let window = Window::new(-1, -1, 700, 500, &"Sodium").unwrap();
...@@ -74,11 +73,16 @@ impl Editor { ...@@ -74,11 +73,16 @@ impl Editor {
redraw_task: RedrawTask::Null, redraw_task: RedrawTask::Null,
}; };
debugln!(editor, "Starting Sodium");
editor.redraw(); editor.redraw();
debugln!(editor, "First redraw of the screen");
loop { loop {
let inp = editor.get_inst(); let inp = editor.get_inst();
if let Inst(_, Cmd { key: Key::Quit }) = inp { if let Inst(_, Cmd { key: Key::Quit }) = inp {
debugln!(editor, "C'ya");
break; break;
} }
editor.exec(inp); editor.exec(inp);
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
#[cfg(feature = "orbital")] #[cfg(feature = "orbital")]
extern crate orbital; extern crate orbital;
#[macro_use]
pub mod debug;
pub mod editor; pub mod editor;
pub mod buffer; pub mod buffer;
pub mod parse; pub mod parse;
......
...@@ -25,8 +25,7 @@ impl Mode { ...@@ -25,8 +25,7 @@ impl Mode {
Command(Normal) => "Normal", Command(Normal) => "Normal",
Primitive(Insert(_)) => "Insert", Primitive(Insert(_)) => "Insert",
Primitive(Prompt) => "Prompt", Primitive(Prompt) => "Prompt",
} }.to_string()
.to_string()
} }
} }
......
...@@ -2,6 +2,7 @@ pub struct Options { ...@@ -2,6 +2,7 @@ pub struct Options {
pub highlight: bool, pub highlight: bool,
pub autoindent: bool, pub autoindent: bool,
pub line_marker: bool, pub line_marker: bool,
pub debug: bool,
} }
impl Options { impl Options {
...@@ -11,6 +12,7 @@ impl Options { ...@@ -11,6 +12,7 @@ impl Options {
highlight: true, highlight: true,
autoindent: true, autoindent: true,
line_marker: true, line_marker: true,
debug: true, // TODO: Let this be `true` only in debug compilation cfg
} }
} }
...@@ -20,6 +22,7 @@ impl Options { ...@@ -20,6 +22,7 @@ impl Options {
"hightlight" | "hl" => Some(&mut self.highlight), "hightlight" | "hl" => Some(&mut self.highlight),
"autoindent" | "ai" => Some(&mut self.autoindent), "autoindent" | "ai" => Some(&mut self.autoindent),
"line_marker" | "linemarker" | "linemark" | "lm" => Some(&mut self.line_marker), "line_marker" | "linemarker" | "linemark" | "lm" => Some(&mut self.line_marker),
"debug" | "debug_mode" => Some(&mut self.debug),
_ => None, _ => None,
} }
} }
...@@ -30,6 +33,7 @@ impl Options { ...@@ -30,6 +33,7 @@ impl Options {
"hightlight" | "hl" => Some(self.highlight), "hightlight" | "hl" => Some(self.highlight),
"autoindent" | "ai" => Some(self.autoindent), "autoindent" | "ai" => Some(self.autoindent),
"line_marker" | "linemarker" | "linemark" | "lm" => Some(self.line_marker), "line_marker" | "linemarker" | "linemark" | "lm" => Some(self.line_marker),
"debug" | "debug_mode" => Some(self.debug),
_ => None, _ => None,
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment