diff options
Diffstat (limited to 'crates/ra_editor/src')
-rw-r--r-- | crates/ra_editor/src/line_index.rs | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/crates/ra_editor/src/line_index.rs b/crates/ra_editor/src/line_index.rs index 0b3a28cd4..26b309b78 100644 --- a/crates/ra_editor/src/line_index.rs +++ b/crates/ra_editor/src/line_index.rs | |||
@@ -11,7 +11,7 @@ pub struct LineIndex { | |||
11 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | 11 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
12 | pub struct LineCol { | 12 | pub struct LineCol { |
13 | pub line: u32, | 13 | pub line: u32, |
14 | pub col: u32, | 14 | pub col_utf16: u32, |
15 | } | 15 | } |
16 | 16 | ||
17 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] | 17 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] |
@@ -75,13 +75,13 @@ impl LineIndex { | |||
75 | 75 | ||
76 | LineCol { | 76 | LineCol { |
77 | line: line as u32, | 77 | line: line as u32, |
78 | col: self.utf8_to_utf16_col(line as u32, col) as u32, | 78 | col_utf16: self.utf8_to_utf16_col(line as u32, col) as u32, |
79 | } | 79 | } |
80 | } | 80 | } |
81 | 81 | ||
82 | pub fn offset(&self, line_col: LineCol) -> TextUnit { | 82 | pub fn offset(&self, line_col: LineCol) -> TextUnit { |
83 | //TODO: return Result | 83 | //TODO: return Result |
84 | let col = self.utf16_to_utf8_col(line_col.line, line_col.col); | 84 | let col = self.utf16_to_utf8_col(line_col.line, line_col.col_utf16); |
85 | self.newlines[line_col.line as usize] + col | 85 | self.newlines[line_col.line as usize] + col |
86 | } | 86 | } |
87 | 87 | ||
@@ -126,23 +126,23 @@ impl LineIndex { | |||
126 | fn test_line_index() { | 126 | fn test_line_index() { |
127 | let text = "hello\nworld"; | 127 | let text = "hello\nworld"; |
128 | let index = LineIndex::new(text); | 128 | let index = LineIndex::new(text); |
129 | assert_eq!(index.line_col(0.into()), LineCol { line: 0, col: 0 }); | 129 | assert_eq!(index.line_col(0.into()), LineCol { line: 0, col_utf16: 0 }); |
130 | assert_eq!(index.line_col(1.into()), LineCol { line: 0, col: 1 }); | 130 | assert_eq!(index.line_col(1.into()), LineCol { line: 0, col_utf16: 1 }); |
131 | assert_eq!(index.line_col(5.into()), LineCol { line: 0, col: 5 }); | 131 | assert_eq!(index.line_col(5.into()), LineCol { line: 0, col_utf16: 5 }); |
132 | assert_eq!(index.line_col(6.into()), LineCol { line: 1, col: 0 }); | 132 | assert_eq!(index.line_col(6.into()), LineCol { line: 1, col_utf16: 0 }); |
133 | assert_eq!(index.line_col(7.into()), LineCol { line: 1, col: 1 }); | 133 | assert_eq!(index.line_col(7.into()), LineCol { line: 1, col_utf16: 1 }); |
134 | assert_eq!(index.line_col(8.into()), LineCol { line: 1, col: 2 }); | 134 | assert_eq!(index.line_col(8.into()), LineCol { line: 1, col_utf16: 2 }); |
135 | assert_eq!(index.line_col(10.into()), LineCol { line: 1, col: 4 }); | 135 | assert_eq!(index.line_col(10.into()), LineCol { line: 1, col_utf16: 4 }); |
136 | assert_eq!(index.line_col(11.into()), LineCol { line: 1, col: 5 }); | 136 | assert_eq!(index.line_col(11.into()), LineCol { line: 1, col_utf16: 5 }); |
137 | assert_eq!(index.line_col(12.into()), LineCol { line: 1, col: 6 }); | 137 | assert_eq!(index.line_col(12.into()), LineCol { line: 1, col_utf16: 6 }); |
138 | 138 | ||
139 | let text = "\nhello\nworld"; | 139 | let text = "\nhello\nworld"; |
140 | let index = LineIndex::new(text); | 140 | let index = LineIndex::new(text); |
141 | assert_eq!(index.line_col(0.into()), LineCol { line: 0, col: 0 }); | 141 | assert_eq!(index.line_col(0.into()), LineCol { line: 0, col_utf16: 0 }); |
142 | assert_eq!(index.line_col(1.into()), LineCol { line: 1, col: 0 }); | 142 | assert_eq!(index.line_col(1.into()), LineCol { line: 1, col_utf16: 0 }); |
143 | assert_eq!(index.line_col(2.into()), LineCol { line: 1, col: 1 }); | 143 | assert_eq!(index.line_col(2.into()), LineCol { line: 1, col_utf16: 1 }); |
144 | assert_eq!(index.line_col(6.into()), LineCol { line: 1, col: 5 }); | 144 | assert_eq!(index.line_col(6.into()), LineCol { line: 1, col_utf16: 5 }); |
145 | assert_eq!(index.line_col(7.into()), LineCol { line: 2, col: 0 }); | 145 | assert_eq!(index.line_col(7.into()), LineCol { line: 2, col_utf16: 0 }); |
146 | } | 146 | } |
147 | 147 | ||
148 | #[cfg(test)] | 148 | #[cfg(test)] |