From 05a9d42f542c8eb876d06791579d948b2f571e04 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Aug 2018 14:52:29 +0300 Subject: tweak extend selection --- crates/libsyntax2/src/yellow/syntax_text.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'crates/libsyntax2/src/yellow') diff --git a/crates/libsyntax2/src/yellow/syntax_text.rs b/crates/libsyntax2/src/yellow/syntax_text.rs index b855687c4..280bedd78 100644 --- a/crates/libsyntax2/src/yellow/syntax_text.rs +++ b/crates/libsyntax2/src/yellow/syntax_text.rs @@ -61,6 +61,18 @@ impl<'a> SyntaxText<'a> { }); SyntaxText { node: self.node, range } } + pub fn char_at(&self, offset: TextUnit) -> Option { + 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> { -- cgit v1.2.3