(&self)
| 142 | } |
| 143 | |
| 144 | fn selection_text(&self) -> Option<String> { |
| 145 | let (start, end) = self.selection_bounds()?; |
| 146 | if start.line >= self.visible_plain_lines.len() |
| 147 | || end.line >= self.visible_plain_lines.len() |
| 148 | { |
| 149 | return None; |
| 150 | } |
| 151 | |
| 152 | let mut out: Vec<String> = Vec::new(); |
| 153 | for line_idx in start.line..=end.line { |
| 154 | let line = &self.visible_plain_lines[line_idx]; |
| 155 | let piece = if start.line == end.line { |
| 156 | let b0 = Self::display_col_to_byte_idx(line, start.col); |
| 157 | let b1 = Self::display_col_to_byte_idx(line, end.col); |
| 158 | line[b0.min(b1)..b0.max(b1)].to_string() |
| 159 | } else if line_idx == start.line { |
| 160 | let b0 = Self::display_col_to_byte_idx(line, start.col); |
| 161 | line[b0..].to_string() |
| 162 | } else if line_idx == end.line { |
| 163 | let b1 = Self::display_col_to_byte_idx(line, end.col); |
| 164 | line[..b1].to_string() |
| 165 | } else { |
| 166 | line.clone() |
| 167 | }; |
| 168 | out.push(piece); |
| 169 | } |
| 170 | |
| 171 | let text = out.join("\n"); |
| 172 | if text.trim().is_empty() { |
| 173 | None |
| 174 | } else { |
| 175 | Some(text) |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | pub fn begin_mouse_selection(&mut self, column: u16, row: u16) -> bool { |
| 180 | let Some(point) = self.map_mouse_to_selection_point(column, row, false) else { |
no test coverage detected