зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-09-04 23:05:50 +03:00
chore/integrate-open-prs (#5)
* docs: integrate upstream PR #116 * feat: integrate upstream PR #113 * chore: add portable-atomic for viewport atomics (upstream PR #111) * fix(examples): integrate upstream PR #100 * fix(word): integrate upstream PR #98 * fix(widget): handle wide unicode char widths in horizontal scroll (upstream PR #94) * feat(highlight): integrate upstream PR #93 * chore(release): prepare v0.8.0 docs and CI-clean merged upstream updates * docs(license): rename LICENSE.txt to LICENSE and fix header capitalization
Этот коммит содержится в:
@@ -15,6 +15,7 @@ enum Boundary {
|
||||
Select(Style),
|
||||
#[cfg(feature = "search")]
|
||||
Search(Style),
|
||||
Custom(Style, u8), // style, priority
|
||||
End,
|
||||
}
|
||||
|
||||
@@ -22,10 +23,11 @@ impl Boundary {
|
||||
fn cmp(&self, other: &Boundary) -> Ordering {
|
||||
fn rank(b: &Boundary) -> u8 {
|
||||
match b {
|
||||
Boundary::Cursor(_) => 3,
|
||||
Boundary::Cursor(_) => 30,
|
||||
#[cfg(feature = "search")]
|
||||
Boundary::Search(_) => 2,
|
||||
Boundary::Select(_) => 1,
|
||||
Boundary::Search(_) => 20,
|
||||
Boundary::Select(_) => 10,
|
||||
Boundary::Custom(_, p) => *p,
|
||||
Boundary::End => 0,
|
||||
}
|
||||
}
|
||||
@@ -38,6 +40,7 @@ impl Boundary {
|
||||
Boundary::Select(s) => Some(*s),
|
||||
#[cfg(feature = "search")]
|
||||
Boundary::Search(s) => Some(*s),
|
||||
Boundary::Custom(s, _) => Some(*s),
|
||||
Boundary::End => None,
|
||||
}
|
||||
}
|
||||
@@ -156,13 +159,15 @@ impl<'a> LineHighlighter<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn selection(
|
||||
// Shared code for selection and custom highlights
|
||||
fn multiline_highlight(
|
||||
&mut self,
|
||||
current_row: usize,
|
||||
start_row: usize,
|
||||
start_off: usize,
|
||||
end_row: usize,
|
||||
end_off: usize,
|
||||
boundary: Boundary,
|
||||
) {
|
||||
let (start, end) = if current_row == start_row {
|
||||
if start_row == end_row {
|
||||
@@ -180,12 +185,47 @@ impl<'a> LineHighlighter<'a> {
|
||||
return;
|
||||
};
|
||||
if start != end {
|
||||
self.boundaries
|
||||
.push((Boundary::Select(self.select_style), start));
|
||||
self.boundaries.push((boundary, start));
|
||||
self.boundaries.push((Boundary::End, end));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn selection(
|
||||
&mut self,
|
||||
current_row: usize,
|
||||
start_row: usize,
|
||||
start_off: usize,
|
||||
end_row: usize,
|
||||
end_off: usize,
|
||||
) {
|
||||
self.multiline_highlight(
|
||||
current_row,
|
||||
start_row,
|
||||
start_off,
|
||||
end_row,
|
||||
end_off,
|
||||
Boundary::Select(self.select_style),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn custom(
|
||||
&mut self,
|
||||
current_row: usize,
|
||||
range: ((usize, usize), (usize, usize)),
|
||||
style: Style,
|
||||
priority: u8,
|
||||
) {
|
||||
let ((start_row, start_off), (end_row, end_off)) = range;
|
||||
self.multiline_highlight(
|
||||
current_row,
|
||||
start_row,
|
||||
start_off,
|
||||
end_row,
|
||||
end_off,
|
||||
Boundary::Custom(style, priority),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn into_spans(self) -> Line<'a> {
|
||||
let Self {
|
||||
line,
|
||||
|
||||
Ссылка в новой задаче
Block a user