mirror of
https://github.com/enso-org/enso.git
synced 2024-11-22 22:10:15 +03:00
Fixes
This commit is contained in:
parent
7ce7646beb
commit
5971faa53c
@ -8,3 +8,6 @@
|
||||
|
||||
pub mod formatted;
|
||||
pub mod word;
|
||||
|
||||
|
||||
|
||||
|
@ -1675,19 +1675,30 @@ impl TextModel {
|
||||
if range.single_line() {
|
||||
let view_line = ViewLine::from_in_context_snapped(self, range.start.line);
|
||||
let line = &mut lines[view_line];
|
||||
for glyph in &mut line.glyphs[range.start.offset..range.end.offset] {
|
||||
glyph.set_property(property);
|
||||
if let Some(last_index) = line.glyphs.last_valid_index() {
|
||||
let start = std::cmp::min(last_index, range.start.offset);
|
||||
let end = std::cmp::min(last_index + Column(1), range.end.offset);
|
||||
for glyph in &mut line.glyphs[start..end] {
|
||||
glyph.set_property(property);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let view_line = ViewLine::from_in_context_snapped(self, range.start.line);
|
||||
let first_line = &mut lines[view_line];
|
||||
for glyph in &mut first_line.glyphs[range.start.offset..] {
|
||||
glyph.set_property(property);
|
||||
if let Some(last_index) = first_line.glyphs.last_valid_index() {
|
||||
let start = std::cmp::min(last_index, range.start.offset);
|
||||
for glyph in &mut first_line.glyphs[start..] {
|
||||
glyph.set_property(property);
|
||||
}
|
||||
}
|
||||
|
||||
let view_line = ViewLine::from_in_context_snapped(self, range.end.line);
|
||||
let last_line = &mut lines[view_line];
|
||||
for glyph in &mut last_line.glyphs[..range.end.offset] {
|
||||
glyph.set_property(property);
|
||||
if let Some(last_index) = last_line.glyphs.last_valid_index() {
|
||||
let end = std::cmp::min(last_index + Column(1), range.end.offset);
|
||||
for glyph in &mut last_line.glyphs[..end] {
|
||||
glyph.set_property(property);
|
||||
}
|
||||
}
|
||||
for line_index in range.start.line.value + 1..range.end.line.value {
|
||||
let view_line = ViewLine::from_in_context_snapped(self, Line(line_index));
|
||||
|
@ -4,6 +4,7 @@
|
||||
//! of [`enso_text`] crate carefully.
|
||||
|
||||
#![recursion_limit = "1024"]
|
||||
|
||||
// === Features ===
|
||||
#![feature(const_trait_impl)]
|
||||
#![feature(trait_alias)]
|
||||
@ -15,10 +16,12 @@
|
||||
#![feature(allocator_api)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(step_trait)]
|
||||
|
||||
// === Standard Linter Configuration ===
|
||||
#![deny(non_ascii_idents)]
|
||||
#![warn(unsafe_code)]
|
||||
#![allow(clippy::let_and_return)]
|
||||
|
||||
// === Non-Standard Linter Configuration ===
|
||||
#![warn(missing_copy_implementations)]
|
||||
#![warn(missing_debug_implementations)]
|
||||
|
@ -63,6 +63,12 @@ impl<T, I> NonEmptyVec<T, I> {
|
||||
self.elems.len()
|
||||
}
|
||||
|
||||
/// Return the last valid index.
|
||||
pub fn last_valid_index(&self) -> I
|
||||
where I: From<usize> {
|
||||
(self.len() - 1).into()
|
||||
}
|
||||
|
||||
/// Construct a `NonEmptyVec` containing a single element.
|
||||
///
|
||||
/// # Examples
|
||||
|
@ -76,6 +76,16 @@ where A: Allocator
|
||||
self.vec.len()
|
||||
}
|
||||
|
||||
/// Return the last valid index, if any.
|
||||
pub fn last_valid_index(&self) -> Option<I>
|
||||
where I: From<usize> {
|
||||
if self.vec.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some((self.len() - 1).into())
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if the vector is empty.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.vec.is_empty()
|
||||
|
Loading…
Reference in New Issue
Block a user