@@ 1,6 1,15 @@
-use ropey::Rope;
-use frappe::{Sink, Stream, Signal};
-use std::ops::{Deref, Range};
+use {
+ ropey::Rope,
+ frappe::{
+ Sink,
+ Stream,
+ Signal
+ },
+ std::ops::{
+ Deref,
+ Range
+ }
+};
pub struct Buffer {
text: Rope,
@@ 31,10 40,7 @@ impl Buffer {
Event::Remove { ref char_idx_range } => self.text.remove(char_idx_range.clone())
}
- self.event_sink.send(FiringEvent {
- event: event,
- text: text
- });
+ self.event_sink.send(FiringEvent { event, text });
}
pub fn signal_char_idx(&self, char_idx: usize) -> Signal<usize> {
@@ 4,6 4,7 @@ use {
Ropey,
frappe::Signal,
ropey::Rope,
+ std::ops::Range,
buffer::{
self,
Buffer
@@ 50,7 51,7 @@ impl Cursor {
/// Handles a mutation of the buffer.
pub fn handle_buf(&mut self, buf: &mut Buffer, event: BufferEvent) {
- let pos_lines = |text: &Rope, pos: Position| -> ::std::ops::Range<usize> {
+ let pos_lines = |text: &Rope, pos: Position| -> Range<usize> {
let (char_idx, sel_start) = pos;
if let Some(sel_start) = sel_start {
@@ 81,7 82,7 @@ impl Cursor {
buf.handle(buffer::Event::Insert {
char_idx: char_idx_signal.sample(),
- text: text.clone() // XXX
+ text: text.clone()
});
}
}
@@ 119,27 120,25 @@ impl Cursor {
}
}
}
- BufferEvent::Indent(indent) => indent.sample_with(|indent| {
- if buf.text().len_chars() == 0 {
- /* An empty Rope causes weird math afterwards
- * (see docs of `char_to_line()` and `line_to_char()`)
- * so we just handle this simple case here. */
- buf.handle(buffer::Event::Insert {
- char_idx: 0,
- text: (*indent).clone() // XXX
- })
- } else {
- for pos in self.positions() {
- for line_idx in pos_lines(buf.text(), pos) {
- let line_start_idx = buf.text().line_to_char(line_idx);
- buf.handle(buffer::Event::Insert {
- char_idx: line_start_idx,
- text: (*indent).clone() // XXX
- })
- }
+ BufferEvent::Indent(indent) => if buf.text().len_chars() == 0 {
+ /* An empty Rope causes weird math afterwards
+ * (see docs of `char_to_line()` and `line_to_char()`)
+ * so we just handle this simple case here. */
+ buf.handle(buffer::Event::Insert {
+ char_idx: 0,
+ text: indent.sample()
+ })
+ } else {
+ for pos in self.positions() {
+ for line_idx in pos_lines(buf.text(), pos) {
+ let line_start_idx = buf.text().line_to_char(line_idx);
+ buf.handle(buffer::Event::Insert {
+ char_idx: line_start_idx,
+ text: indent.sample()
+ })
}
}
- }),
+ },
BufferEvent::Dedent(indent) => indent.sample_with(|indent| {
if buf.text().len_chars() == 0 { return } // nothing to dedent
@@ 175,7 174,7 @@ impl Cursor {
}
}
-pub fn select(range: (usize, usize)) -> ::std::ops::Range<usize> {
+pub fn select(range: (usize, usize)) -> Range<usize> {
let (start_idx, end_idx) = range;
if start_idx < end_idx {
start_idx..end_idx