Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporary Fix: when selecting only a space or '\n' in TextEdit, the selection is not filled. #5120

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/egui/src/text_selection/label_text_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,9 @@ impl LabelSelectionState {

if let Some(cursor_range) = cursor_range {
paint_text_selection(
ui,
galley_pos,
galley,
ui.visuals(),
&cursor_range,
Some(&mut new_vertex_indices),
);
Expand Down
11 changes: 9 additions & 2 deletions crates/egui/src/text_selection/visuals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ pub struct RowVertexIndices {

/// Adds text selection rectangles to the galley.
pub fn paint_text_selection(
ui: &Ui,
galley_pos: crate::Pos2,
galley: &mut Arc<Galley>,
visuals: &Visuals,
cursor_range: &CursorRange,
mut new_vertex_indices: Option<&mut Vec<RowVertexIndices>>,
) {
Expand All @@ -25,7 +26,7 @@ pub fn paint_text_selection(
// and so we need to clone it if it is shared:
let galley: &mut Galley = Arc::make_mut(galley);

let color = visuals.selection.bg_fill;
let color = ui.visuals().selection.bg_fill;
let [min, max] = cursor_range.sorted_cursors();
let min = min.rcursor;
let max = max.rcursor;
Expand All @@ -48,6 +49,12 @@ pub fn paint_text_selection(
row.rect.right() + newline_size
};

let rect = Rect::from_min_max(
galley_pos + vec2(left, row.min_y()),
galley_pos + vec2(right, row.max_y()),
);
let _shape_idx = ui.painter().rect_filled(rect, 0.0, color);

let rect = Rect::from_min_max(pos2(left, row.min_y()), pos2(right, row.max_y()));
let mesh = &mut row.visuals.mesh;

Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/widgets/text_edit/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ impl<'t> TextEdit<'t> {
if has_focus {
if let Some(cursor_range) = state.cursor.range(&galley) {
// Add text selection rectangles to the galley:
paint_text_selection(&mut galley, ui.visuals(), &cursor_range, None);
paint_text_selection(ui, galley_pos, &mut galley, &cursor_range, None);
}
}

Expand Down
Loading