forked from helix-editor/helix
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
search buffer contents during global search
- Loading branch information
1 parent
541d2b7
commit 0ad51c8
Showing
3 changed files
with
77 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use std::io; | ||
|
||
use ropey::iter::Chunks; | ||
use ropey::RopeSlice; | ||
|
||
pub struct RopeReader<'a> { | ||
current_chunk: &'a [u8], | ||
chunks: Chunks<'a>, | ||
} | ||
|
||
impl<'a> RopeReader<'a> { | ||
pub fn new(rope: RopeSlice<'a>) -> RopeReader<'a> { | ||
RopeReader { | ||
current_chunk: &[], | ||
chunks: rope.chunks(), | ||
} | ||
} | ||
} | ||
|
||
impl io::Read for RopeReader<'_> { | ||
fn read(&mut self, mut buf: &mut [u8]) -> io::Result<usize> { | ||
let buf_len = buf.len(); | ||
loop { | ||
let read_bytes = self.current_chunk.read(buf)?; | ||
buf = &mut buf[read_bytes..]; | ||
if buf.is_empty() { | ||
return Ok(buf_len); | ||
} | ||
|
||
if let Some(next_chunk) = self.chunks.next() { | ||
self.current_chunk = next_chunk.as_bytes(); | ||
} else { | ||
return Ok(buf_len - buf.len()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters