mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-04-08 17:05:59 +02:00
Fix issue with cursor on canvas due to not incrementing by the SIZE of the grapheme.
This commit is contained in:
parent
2d02c53296
commit
cc751e19ae
10
src/app.rs
10
src/app.rs
@ -32,6 +32,12 @@ pub enum ScrollDirection {
|
||||
DOWN,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SearchDirection {
|
||||
LEFT,
|
||||
RIGHT,
|
||||
}
|
||||
|
||||
/// AppScrollWidgetState deals with fields for a scrollable app's current state.
|
||||
#[derive(Default)]
|
||||
pub struct AppScrollWidgetState {
|
||||
@ -644,7 +650,7 @@ impl App {
|
||||
&self.process_search_state.search_state.current_search_query[start_position..],
|
||||
start_position,
|
||||
)
|
||||
.unwrap();
|
||||
.unwrap(); // TODO: [UNWRAP] unwrap in this and walk_back seem sketch
|
||||
}
|
||||
|
||||
pub fn search_walk_back(&mut self, start_position: usize) {
|
||||
@ -819,7 +825,7 @@ impl App {
|
||||
self.last_key_press = current_key_press_inst;
|
||||
|
||||
if let WidgetPosition::ProcessSearch = self.current_widget_selected {
|
||||
if UnicodeWidthStr::width_cjk(
|
||||
if UnicodeWidthStr::width(
|
||||
self.process_search_state
|
||||
.search_state
|
||||
.current_search_query
|
||||
|
@ -1159,12 +1159,16 @@ impl Painter {
|
||||
) {
|
||||
let width = max(0, draw_loc.width as i64 - 34) as u64; // TODO: [REFACTOR] Hard coding this is terrible.
|
||||
let query = app_state.get_current_search_query().as_str();
|
||||
let grapheme_indices = UnicodeSegmentation::grapheme_indices(query, true)
|
||||
.rev()
|
||||
.enumerate(); // Reverse due to us wanting to draw from back -> front
|
||||
let num_graphemes = min(UnicodeWidthStr::width_cjk(query), width as usize);
|
||||
let grapheme_indices = UnicodeSegmentation::grapheme_indices(query, true).rev(); // Reverse due to us wanting to draw from back -> front
|
||||
let cursor_position = app_state.get_cursor_position();
|
||||
let right_border = min(UnicodeWidthStr::width(query), width as usize);
|
||||
debug!(
|
||||
"Width: {}, query length: {}",
|
||||
width,
|
||||
UnicodeWidthStr::width(query)
|
||||
);
|
||||
|
||||
let mut itx = 0;
|
||||
let mut query_with_cursor: Vec<Text<'_>> = if let app::WidgetPosition::ProcessSearch =
|
||||
app_state.current_widget_selected
|
||||
{
|
||||
@ -1178,8 +1182,8 @@ impl Painter {
|
||||
|
||||
res.extend(
|
||||
grapheme_indices
|
||||
.filter_map(|(itx, grapheme)| {
|
||||
if itx >= num_graphemes {
|
||||
.filter_map(|grapheme| {
|
||||
if itx >= right_border {
|
||||
None
|
||||
} else {
|
||||
let styled = if grapheme.0 == cursor_position {
|
||||
@ -1187,6 +1191,7 @@ impl Painter {
|
||||
} else {
|
||||
Text::styled(grapheme.1, self.colours.text_style)
|
||||
};
|
||||
itx += UnicodeWidthStr::width(grapheme.1);
|
||||
Some(styled)
|
||||
}
|
||||
})
|
||||
@ -1198,11 +1203,12 @@ impl Painter {
|
||||
// This is easier - we just need to get a range of graphemes, rather than
|
||||
// dealing with possibly inserting a cursor (as none is shown!)
|
||||
grapheme_indices
|
||||
.filter_map(|(itx, grapheme)| {
|
||||
if itx >= num_graphemes {
|
||||
.filter_map(|grapheme| {
|
||||
if itx >= right_border {
|
||||
None
|
||||
} else {
|
||||
let styled = Text::styled(grapheme.1, self.colours.text_style);
|
||||
itx += UnicodeWidthStr::width(grapheme.1);
|
||||
Some(styled)
|
||||
}
|
||||
})
|
||||
|
@ -70,6 +70,15 @@ pub fn get_variable_intrinsic_widths(
|
||||
(resulting_widths, last_index)
|
||||
}
|
||||
|
||||
#[allow(dead_code, unused_variables)]
|
||||
pub fn get_search_start_position(
|
||||
num_rows: u64, scroll_direction: &app::ScrollDirection, scroll_position_bar: &mut u64,
|
||||
currently_selected_position: u64, is_resized: bool,
|
||||
) -> u64 {
|
||||
//TODO: [Scroll] Gotta fix this too lol
|
||||
0
|
||||
}
|
||||
|
||||
pub fn get_start_position(
|
||||
num_rows: u64, scroll_direction: &app::ScrollDirection, scroll_position_bar: &mut u64,
|
||||
currently_selected_position: u64, is_resized: bool,
|
||||
|
Loading…
x
Reference in New Issue
Block a user