mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-09 14:54:39 +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,
|
DOWN,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum SearchDirection {
|
||||||
|
LEFT,
|
||||||
|
RIGHT,
|
||||||
|
}
|
||||||
|
|
||||||
/// AppScrollWidgetState deals with fields for a scrollable app's current state.
|
/// AppScrollWidgetState deals with fields for a scrollable app's current state.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct AppScrollWidgetState {
|
pub struct AppScrollWidgetState {
|
||||||
@ -644,7 +650,7 @@ impl App {
|
|||||||
&self.process_search_state.search_state.current_search_query[start_position..],
|
&self.process_search_state.search_state.current_search_query[start_position..],
|
||||||
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) {
|
pub fn search_walk_back(&mut self, start_position: usize) {
|
||||||
@ -819,7 +825,7 @@ impl App {
|
|||||||
self.last_key_press = current_key_press_inst;
|
self.last_key_press = current_key_press_inst;
|
||||||
|
|
||||||
if let WidgetPosition::ProcessSearch = self.current_widget_selected {
|
if let WidgetPosition::ProcessSearch = self.current_widget_selected {
|
||||||
if UnicodeWidthStr::width_cjk(
|
if UnicodeWidthStr::width(
|
||||||
self.process_search_state
|
self.process_search_state
|
||||||
.search_state
|
.search_state
|
||||||
.current_search_query
|
.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 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 query = app_state.get_current_search_query().as_str();
|
||||||
let grapheme_indices = UnicodeSegmentation::grapheme_indices(query, true)
|
let grapheme_indices = UnicodeSegmentation::grapheme_indices(query, true).rev(); // Reverse due to us wanting to draw from back -> front
|
||||||
.rev()
|
|
||||||
.enumerate(); // Reverse due to us wanting to draw from back -> front
|
|
||||||
let num_graphemes = min(UnicodeWidthStr::width_cjk(query), width as usize);
|
|
||||||
let cursor_position = app_state.get_cursor_position();
|
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 =
|
let mut query_with_cursor: Vec<Text<'_>> = if let app::WidgetPosition::ProcessSearch =
|
||||||
app_state.current_widget_selected
|
app_state.current_widget_selected
|
||||||
{
|
{
|
||||||
@ -1178,8 +1182,8 @@ impl Painter {
|
|||||||
|
|
||||||
res.extend(
|
res.extend(
|
||||||
grapheme_indices
|
grapheme_indices
|
||||||
.filter_map(|(itx, grapheme)| {
|
.filter_map(|grapheme| {
|
||||||
if itx >= num_graphemes {
|
if itx >= right_border {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let styled = if grapheme.0 == cursor_position {
|
let styled = if grapheme.0 == cursor_position {
|
||||||
@ -1187,6 +1191,7 @@ impl Painter {
|
|||||||
} else {
|
} else {
|
||||||
Text::styled(grapheme.1, self.colours.text_style)
|
Text::styled(grapheme.1, self.colours.text_style)
|
||||||
};
|
};
|
||||||
|
itx += UnicodeWidthStr::width(grapheme.1);
|
||||||
Some(styled)
|
Some(styled)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -1198,11 +1203,12 @@ impl Painter {
|
|||||||
// This is easier - we just need to get a range of graphemes, rather than
|
// This is easier - we just need to get a range of graphemes, rather than
|
||||||
// dealing with possibly inserting a cursor (as none is shown!)
|
// dealing with possibly inserting a cursor (as none is shown!)
|
||||||
grapheme_indices
|
grapheme_indices
|
||||||
.filter_map(|(itx, grapheme)| {
|
.filter_map(|grapheme| {
|
||||||
if itx >= num_graphemes {
|
if itx >= right_border {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let styled = Text::styled(grapheme.1, self.colours.text_style);
|
let styled = Text::styled(grapheme.1, self.colours.text_style);
|
||||||
|
itx += UnicodeWidthStr::width(grapheme.1);
|
||||||
Some(styled)
|
Some(styled)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -70,6 +70,15 @@ pub fn get_variable_intrinsic_widths(
|
|||||||
(resulting_widths, last_index)
|
(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(
|
pub fn get_start_position(
|
||||||
num_rows: u64, scroll_direction: &app::ScrollDirection, scroll_position_bar: &mut u64,
|
num_rows: u64, scroll_direction: &app::ScrollDirection, scroll_position_bar: &mut u64,
|
||||||
currently_selected_position: u64, is_resized: bool,
|
currently_selected_position: u64, is_resized: bool,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user