Skip to content

Commit

Permalink
Make location bar text yellow when dirty
Browse files Browse the repository at this point in the history
  • Loading branch information
delan committed Mar 27, 2024
1 parent 3d5307f commit 6779d50
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions ports/servoshell/minibrowser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,12 @@ impl Minibrowser {
);
});

let mut location_dirty = None;
let mut location_dirty = false;
let mut location = location.borrow_mut();
if let Some(webview_location) = webviews.focused_webview_mut().map(|w| &w.location) {
if webview_location != &*location {
*location = webview_location.clone();
if let Some(webview) = webviews.focused_webview_mut() {
location_dirty = webview.location_dirty;
if webview.location != *location {
*location = webview.location.clone();
}
}

Expand All @@ -215,7 +216,7 @@ impl Minibrowser {
|ui| {
if ui.button("go").clicked() {
event_queue.borrow_mut().push(MinibrowserEvent::Go);
location_dirty = Some(false);
location_dirty = false;
}

match self.load_status {
Expand All @@ -228,13 +229,13 @@ impl Minibrowser {
LoadStatus::LoadComplete => { /* No Spinner */ },
}

let location_field = ui.add_sized(
ui.available_size(),
egui::TextEdit::singleline(&mut *location),
);
let location_field = egui::TextEdit::singleline(&mut *location)
.text_color_opt(location_dirty.then_some(Color32::YELLOW));
let location_field =
ui.add_sized(ui.available_size(), location_field);

if location_field.changed() {
location_dirty = Some(true);
location_dirty = true;
}
if ui.input(|i| i.clone().consume_key(Modifiers::COMMAND, Key::L)) {
location_field.request_focus();
Expand All @@ -243,7 +244,7 @@ impl Minibrowser {
ui.input(|i| i.clone().key_pressed(Key::Enter))
{
event_queue.borrow_mut().push(MinibrowserEvent::Go);
location_dirty = Some(false);
location_dirty = false;
}
},
);
Expand All @@ -257,9 +258,7 @@ impl Minibrowser {
*toolbar_height = Length::new(ctx.available_rect().min.y);

if let Some(webview) = webviews.focused_webview_mut() {
if let Some(location_dirty) = location_dirty {
webview.location_dirty = location_dirty;
}
webview.location_dirty = location_dirty;
if *location != webview.location {
webview.location = location.clone();
}
Expand Down

0 comments on commit 6779d50

Please sign in to comment.