tweak extend selection

This commit is contained in:
Aleksey Kladov 2018-08-31 14:52:29 +03:00
parent 8fc7f438c4
commit 05a9d42f54
3 changed files with 54 additions and 16 deletions

View file

@ -61,6 +61,18 @@ impl<'a> SyntaxText<'a> {
});
SyntaxText { node: self.node, range }
}
pub fn char_at(&self, offset: TextUnit) -> Option<char> {
let mut start: TextUnit = 0.into();
for chunk in self.chunks() {
let end = start + TextUnit::of_str(chunk);
if start <= offset && offset < end {
let off: usize = u32::from(offset - start) as usize;
return Some(chunk[off..].chars().next().unwrap());
}
start = end;
}
None
}
}
impl<'a> fmt::Debug for SyntaxText<'a> {