diff options
author | Aleksey Kladov <[email protected]> | 2018-08-31 12:52:29 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-31 12:52:29 +0100 |
commit | 05a9d42f542c8eb876d06791579d948b2f571e04 (patch) | |
tree | 33b5962641f57d65b8545b477885fcfadbbe801c /crates/libsyntax2/src/yellow/syntax_text.rs | |
parent | 8fc7f438c4347e027deda5cda4bcd5e560610bb7 (diff) |
tweak extend selection
Diffstat (limited to 'crates/libsyntax2/src/yellow/syntax_text.rs')
-rw-r--r-- | crates/libsyntax2/src/yellow/syntax_text.rs | 12 |
1 files changed, 12 insertions, 0 deletions
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> { | |||
61 | }); | 61 | }); |
62 | SyntaxText { node: self.node, range } | 62 | SyntaxText { node: self.node, range } |
63 | } | 63 | } |
64 | pub fn char_at(&self, offset: TextUnit) -> Option<char> { | ||
65 | let mut start: TextUnit = 0.into(); | ||
66 | for chunk in self.chunks() { | ||
67 | let end = start + TextUnit::of_str(chunk); | ||
68 | if start <= offset && offset < end { | ||
69 | let off: usize = u32::from(offset - start) as usize; | ||
70 | return Some(chunk[off..].chars().next().unwrap()); | ||
71 | } | ||
72 | start = end; | ||
73 | } | ||
74 | None | ||
75 | } | ||
64 | } | 76 | } |
65 | 77 | ||
66 | impl<'a> fmt::Debug for SyntaxText<'a> { | 78 | impl<'a> fmt::Debug for SyntaxText<'a> { |