mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 05:40:03 -04:00
Fix text color when selecting newline character (#7951)
* Closes https://github.com/emilk/egui/issues/7865
This commit is contained in:
@@ -67,9 +67,7 @@ pub fn paint_text_selection(
|
|||||||
let first_vertex_index = row
|
let first_vertex_index = row
|
||||||
.glyphs
|
.glyphs
|
||||||
.get(first_glyph_index)
|
.get(first_glyph_index)
|
||||||
.map_or(row.visuals.glyph_vertex_range.start, |g| {
|
.map_or(row.visuals.glyph_vertex_range.end, |g| g.first_vertex as _);
|
||||||
g.first_vertex as _
|
|
||||||
});
|
|
||||||
let last_vertex_index = row
|
let last_vertex_index = row
|
||||||
.glyphs
|
.glyphs
|
||||||
.get(last_glyph_index)
|
.get(last_glyph_index)
|
||||||
|
|||||||
@@ -59,21 +59,27 @@ fn test_italics() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_text_selection() {
|
fn test_text_selection() {
|
||||||
let mut harness = Harness::builder().build_ui(|ui| {
|
let mut results = egui_kittest::SnapshotResults::new();
|
||||||
let visuals = ui.visuals_mut();
|
|
||||||
visuals.selection.bg_fill = Color32::LIGHT_GREEN;
|
|
||||||
visuals.selection.stroke.color = Color32::DARK_BLUE;
|
|
||||||
|
|
||||||
ui.label("Some varied ☺ text :)\nAnd it has a second line!");
|
for (test_idx, drag_start_x) in [0.2_f32, 0.9].into_iter().enumerate() {
|
||||||
});
|
let mut harness = Harness::builder().build_ui(|ui| {
|
||||||
harness.run();
|
let visuals = ui.visuals_mut();
|
||||||
harness.fit_contents();
|
visuals.selection.bg_fill = Color32::LIGHT_GREEN;
|
||||||
|
visuals.selection.stroke.color = Color32::RED;
|
||||||
|
|
||||||
// Drag to select text:
|
ui.label("Some varied ☺ text :)\nAnd it has a second line!");
|
||||||
let label = harness.get_by_role(Role::Label);
|
});
|
||||||
harness.drag_at(label.rect().lerp_inside([0.2, 0.25]));
|
harness.run();
|
||||||
harness.drop_at(label.rect().lerp_inside([0.6, 0.75]));
|
harness.fit_contents();
|
||||||
harness.run();
|
|
||||||
|
|
||||||
harness.snapshot("text_selection");
|
// Drag to select text:
|
||||||
|
let label = harness.get_by_role(Role::Label);
|
||||||
|
harness.drag_at(label.rect().lerp_inside([drag_start_x, 0.25]));
|
||||||
|
harness.drop_at(label.rect().lerp_inside([0.6, 0.75]));
|
||||||
|
harness.run();
|
||||||
|
|
||||||
|
harness.snapshot(format!("text_selection_{test_idx}"));
|
||||||
|
|
||||||
|
results.extend_harness(&mut harness);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
|
||||||
oid sha256:0475c5ac04ab8f79b79d43cfdb985f05b61dbe90e81f898a6dc216c308a28841
|
|
||||||
size 4707
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:344d90928510855dc718a2e36e31a97f084f1163ab750d0217fb8620469b621a
|
||||||
|
size 5276
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:60449af267336663304e44e254d0984e037bebfa2d1efdf32234cab4374e8c79
|
||||||
|
size 5301
|
||||||
Reference in New Issue
Block a user