Auto-fix clippy::collapsible_if violations (#36428)

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2025-08-19 15:27:24 +02:00 committed by GitHub
parent 9e8ec72bd5
commit 8f567383e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
281 changed files with 6628 additions and 7089 deletions

View file

@ -327,10 +327,10 @@ mod windows {
/// You can set the `GPUI_FXC_PATH` environment variable to specify the path to the fxc.exe compiler.
fn find_fxc_compiler() -> String {
// Check environment variable
if let Ok(path) = std::env::var("GPUI_FXC_PATH") {
if Path::new(&path).exists() {
return path;
}
if let Ok(path) = std::env::var("GPUI_FXC_PATH")
&& Path::new(&path).exists()
{
return path;
}
// Try to find in PATH
@ -338,11 +338,10 @@ mod windows {
if let Ok(output) = std::process::Command::new("where.exe")
.arg("fxc.exe")
.output()
&& output.status.success()
{
if output.status.success() {
let path = String::from_utf8_lossy(&output.stdout);
return path.trim().to_string();
}
let path = String::from_utf8_lossy(&output.stdout);
return path.trim().to_string();
}
// Check the default path

View file

@ -549,10 +549,10 @@ impl Element for TextElement {
line.paint(bounds.origin, window.line_height(), window, cx)
.unwrap();
if focus_handle.is_focused(window) {
if let Some(cursor) = prepaint.cursor.take() {
window.paint_quad(cursor);
}
if focus_handle.is_focused(window)
&& let Some(cursor) = prepaint.cursor.take()
{
window.paint_quad(cursor);
}
self.input.update(cx, |input, _cx| {

View file

@ -1516,12 +1516,11 @@ impl App {
/// the bindings in the element tree, and any global action listeners.
pub fn is_action_available(&mut self, action: &dyn Action) -> bool {
let mut action_available = false;
if let Some(window) = self.active_window() {
if let Ok(window_action_available) =
if let Some(window) = self.active_window()
&& let Ok(window_action_available) =
window.update(self, |_, window, cx| window.is_action_available(action, cx))
{
action_available = window_action_available;
}
{
action_available = window_action_available;
}
action_available
@ -1606,27 +1605,26 @@ impl App {
.insert(action.as_any().type_id(), global_listeners);
}
if self.propagate_event {
if let Some(mut global_listeners) = self
if self.propagate_event
&& let Some(mut global_listeners) = self
.global_action_listeners
.remove(&action.as_any().type_id())
{
for listener in global_listeners.iter().rev() {
listener(action.as_any(), DispatchPhase::Bubble, self);
if !self.propagate_event {
break;
}
{
for listener in global_listeners.iter().rev() {
listener(action.as_any(), DispatchPhase::Bubble, self);
if !self.propagate_event {
break;
}
global_listeners.extend(
self.global_action_listeners
.remove(&action.as_any().type_id())
.unwrap_or_default(),
);
self.global_action_listeners
.insert(action.as_any().type_id(), global_listeners);
}
global_listeners.extend(
self.global_action_listeners
.remove(&action.as_any().type_id())
.unwrap_or_default(),
);
self.global_action_listeners
.insert(action.as_any().type_id(), global_listeners);
}
}

View file

@ -610,16 +610,16 @@ impl<'a, T: 'static> Context<'a, T> {
let (subscription, activate) =
window.new_focus_listener(Box::new(move |event, window, cx| {
view.update(cx, |view, cx| {
if let Some(blurred_id) = event.previous_focus_path.last().copied() {
if event.is_focus_out(focus_id) {
let event = FocusOutEvent {
blurred: WeakFocusHandle {
id: blurred_id,
handles: Arc::downgrade(&cx.focus_handles),
},
};
listener(view, event, window, cx)
}
if let Some(blurred_id) = event.previous_focus_path.last().copied()
&& event.is_focus_out(focus_id)
{
let event = FocusOutEvent {
blurred: WeakFocusHandle {
id: blurred_id,
handles: Arc::downgrade(&cx.focus_handles),
},
};
listener(view, event, window, cx)
}
})
.is_ok()

View file

@ -603,10 +603,8 @@ impl AnyElement {
self.0.prepaint(window, cx);
if !focus_assigned {
if let Some(focus_id) = window.next_frame.focus {
return FocusHandle::for_id(focus_id, &cx.focus_handles);
}
if !focus_assigned && let Some(focus_id) = window.next_frame.focus {
return FocusHandle::for_id(focus_id, &cx.focus_handles);
}
None

View file

@ -286,21 +286,20 @@ impl Interactivity {
{
self.mouse_move_listeners
.push(Box::new(move |event, phase, hitbox, window, cx| {
if phase == DispatchPhase::Capture {
if let Some(drag) = &cx.active_drag {
if drag.value.as_ref().type_id() == TypeId::of::<T>() {
(listener)(
&DragMoveEvent {
event: event.clone(),
bounds: hitbox.bounds,
drag: PhantomData,
dragged_item: Arc::clone(&drag.value),
},
window,
cx,
);
}
}
if phase == DispatchPhase::Capture
&& let Some(drag) = &cx.active_drag
&& drag.value.as_ref().type_id() == TypeId::of::<T>()
{
(listener)(
&DragMoveEvent {
event: event.clone(),
bounds: hitbox.bounds,
drag: PhantomData,
dragged_item: Arc::clone(&drag.value),
},
window,
cx,
);
}
}));
}
@ -1514,15 +1513,14 @@ impl Interactivity {
let mut element_state =
element_state.map(|element_state| element_state.unwrap_or_default());
if let Some(element_state) = element_state.as_ref() {
if cx.has_active_drag() {
if let Some(pending_mouse_down) = element_state.pending_mouse_down.as_ref()
{
*pending_mouse_down.borrow_mut() = None;
}
if let Some(clicked_state) = element_state.clicked_state.as_ref() {
*clicked_state.borrow_mut() = ElementClickedState::default();
}
if let Some(element_state) = element_state.as_ref()
&& cx.has_active_drag()
{
if let Some(pending_mouse_down) = element_state.pending_mouse_down.as_ref() {
*pending_mouse_down.borrow_mut() = None;
}
if let Some(clicked_state) = element_state.clicked_state.as_ref() {
*clicked_state.borrow_mut() = ElementClickedState::default();
}
}
@ -1530,35 +1528,35 @@ impl Interactivity {
// If there's an explicit focus handle we're tracking, use that. Otherwise
// create a new handle and store it in the element state, which lives for as
// as frames contain an element with this id.
if self.focusable && self.tracked_focus_handle.is_none() {
if let Some(element_state) = element_state.as_mut() {
let mut handle = element_state
.focus_handle
.get_or_insert_with(|| cx.focus_handle())
.clone()
.tab_stop(false);
if self.focusable
&& self.tracked_focus_handle.is_none()
&& let Some(element_state) = element_state.as_mut()
{
let mut handle = element_state
.focus_handle
.get_or_insert_with(|| cx.focus_handle())
.clone()
.tab_stop(false);
if let Some(index) = self.tab_index {
handle = handle.tab_index(index).tab_stop(true);
}
self.tracked_focus_handle = Some(handle);
if let Some(index) = self.tab_index {
handle = handle.tab_index(index).tab_stop(true);
}
self.tracked_focus_handle = Some(handle);
}
if let Some(scroll_handle) = self.tracked_scroll_handle.as_ref() {
self.scroll_offset = Some(scroll_handle.0.borrow().offset.clone());
} else if self.base_style.overflow.x == Some(Overflow::Scroll)
|| self.base_style.overflow.y == Some(Overflow::Scroll)
} else if (self.base_style.overflow.x == Some(Overflow::Scroll)
|| self.base_style.overflow.y == Some(Overflow::Scroll))
&& let Some(element_state) = element_state.as_mut()
{
if let Some(element_state) = element_state.as_mut() {
self.scroll_offset = Some(
element_state
.scroll_offset
.get_or_insert_with(Rc::default)
.clone(),
);
}
self.scroll_offset = Some(
element_state
.scroll_offset
.get_or_insert_with(Rc::default)
.clone(),
);
}
let style = self.compute_style_internal(None, element_state.as_mut(), window, cx);
@ -2031,26 +2029,27 @@ impl Interactivity {
let hitbox = hitbox.clone();
window.on_mouse_event({
move |_: &MouseUpEvent, phase, window, cx| {
if let Some(drag) = &cx.active_drag {
if phase == DispatchPhase::Bubble && hitbox.is_hovered(window) {
let drag_state_type = drag.value.as_ref().type_id();
for (drop_state_type, listener) in &drop_listeners {
if *drop_state_type == drag_state_type {
let drag = cx
.active_drag
.take()
.expect("checked for type drag state type above");
if let Some(drag) = &cx.active_drag
&& phase == DispatchPhase::Bubble
&& hitbox.is_hovered(window)
{
let drag_state_type = drag.value.as_ref().type_id();
for (drop_state_type, listener) in &drop_listeners {
if *drop_state_type == drag_state_type {
let drag = cx
.active_drag
.take()
.expect("checked for type drag state type above");
let mut can_drop = true;
if let Some(predicate) = &can_drop_predicate {
can_drop = predicate(drag.value.as_ref(), window, cx);
}
let mut can_drop = true;
if let Some(predicate) = &can_drop_predicate {
can_drop = predicate(drag.value.as_ref(), window, cx);
}
if can_drop {
listener(drag.value.as_ref(), window, cx);
window.refresh();
cx.stop_propagation();
}
if can_drop {
listener(drag.value.as_ref(), window, cx);
window.refresh();
cx.stop_propagation();
}
}
}
@ -2094,31 +2093,24 @@ impl Interactivity {
}
let mut pending_mouse_down = pending_mouse_down.borrow_mut();
if let Some(mouse_down) = pending_mouse_down.clone() {
if !cx.has_active_drag()
&& (event.position - mouse_down.position).magnitude()
> DRAG_THRESHOLD
{
if let Some((drag_value, drag_listener)) = drag_listener.take() {
*clicked_state.borrow_mut() = ElementClickedState::default();
let cursor_offset = event.position - hitbox.origin;
let drag = (drag_listener)(
drag_value.as_ref(),
cursor_offset,
window,
cx,
);
cx.active_drag = Some(AnyDrag {
view: drag,
value: drag_value,
cursor_offset,
cursor_style: drag_cursor_style,
});
pending_mouse_down.take();
window.refresh();
cx.stop_propagation();
}
}
if let Some(mouse_down) = pending_mouse_down.clone()
&& !cx.has_active_drag()
&& (event.position - mouse_down.position).magnitude() > DRAG_THRESHOLD
&& let Some((drag_value, drag_listener)) = drag_listener.take()
{
*clicked_state.borrow_mut() = ElementClickedState::default();
let cursor_offset = event.position - hitbox.origin;
let drag =
(drag_listener)(drag_value.as_ref(), cursor_offset, window, cx);
cx.active_drag = Some(AnyDrag {
view: drag,
value: drag_value,
cursor_offset,
cursor_style: drag_cursor_style,
});
pending_mouse_down.take();
window.refresh();
cx.stop_propagation();
}
}
});
@ -2428,33 +2420,32 @@ impl Interactivity {
style.refine(&self.base_style);
if let Some(focus_handle) = self.tracked_focus_handle.as_ref() {
if let Some(in_focus_style) = self.in_focus_style.as_ref() {
if focus_handle.within_focused(window, cx) {
style.refine(in_focus_style);
}
if let Some(in_focus_style) = self.in_focus_style.as_ref()
&& focus_handle.within_focused(window, cx)
{
style.refine(in_focus_style);
}
if let Some(focus_style) = self.focus_style.as_ref() {
if focus_handle.is_focused(window) {
style.refine(focus_style);
}
if let Some(focus_style) = self.focus_style.as_ref()
&& focus_handle.is_focused(window)
{
style.refine(focus_style);
}
}
if let Some(hitbox) = hitbox {
if !cx.has_active_drag() {
if let Some(group_hover) = self.group_hover_style.as_ref() {
if let Some(group_hitbox_id) = GroupHitboxes::get(&group_hover.group, cx) {
if group_hitbox_id.is_hovered(window) {
style.refine(&group_hover.style);
}
}
if let Some(group_hover) = self.group_hover_style.as_ref()
&& let Some(group_hitbox_id) = GroupHitboxes::get(&group_hover.group, cx)
&& group_hitbox_id.is_hovered(window)
{
style.refine(&group_hover.style);
}
if let Some(hover_style) = self.hover_style.as_ref() {
if hitbox.is_hovered(window) {
style.refine(hover_style);
}
if let Some(hover_style) = self.hover_style.as_ref()
&& hitbox.is_hovered(window)
{
style.refine(hover_style);
}
}
@ -2468,12 +2459,10 @@ impl Interactivity {
for (state_type, group_drag_style) in &self.group_drag_over_styles {
if let Some(group_hitbox_id) =
GroupHitboxes::get(&group_drag_style.group, cx)
&& *state_type == drag.value.as_ref().type_id()
&& group_hitbox_id.is_hovered(window)
{
if *state_type == drag.value.as_ref().type_id()
&& group_hitbox_id.is_hovered(window)
{
style.refine(&group_drag_style.style);
}
style.refine(&group_drag_style.style);
}
}
@ -2495,16 +2484,16 @@ impl Interactivity {
.clicked_state
.get_or_insert_with(Default::default)
.borrow();
if clicked_state.group {
if let Some(group) = self.group_active_style.as_ref() {
style.refine(&group.style)
}
if clicked_state.group
&& let Some(group) = self.group_active_style.as_ref()
{
style.refine(&group.style)
}
if let Some(active_style) = self.active_style.as_ref() {
if clicked_state.element {
style.refine(active_style)
}
if let Some(active_style) = self.active_style.as_ref()
&& clicked_state.element
{
style.refine(active_style)
}
}

View file

@ -297,10 +297,10 @@ impl RetainAllImageCache {
/// Remove the image from the cache by the given source.
pub fn remove(&mut self, source: &Resource, window: &mut Window, cx: &mut App) {
let hash = hash(source);
if let Some(mut item) = self.0.remove(&hash) {
if let Some(Ok(image)) = item.get() {
cx.drop_image(image, Some(window));
}
if let Some(mut item) = self.0.remove(&hash)
&& let Some(Ok(image)) = item.get()
{
cx.drop_image(image, Some(window));
}
}

View file

@ -379,13 +379,12 @@ impl Element for Img {
None => {
if let Some(state) = &mut state {
if let Some((started_loading, _)) = state.started_loading {
if started_loading.elapsed() > LOADING_DELAY {
if let Some(loading) = self.style.loading.as_ref() {
let mut element = loading();
replacement_id =
Some(element.request_layout(window, cx));
layout_state.replacement = Some(element);
}
if started_loading.elapsed() > LOADING_DELAY
&& let Some(loading) = self.style.loading.as_ref()
{
let mut element = loading();
replacement_id = Some(element.request_layout(window, cx));
layout_state.replacement = Some(element);
}
} else {
let current_view = window.current_view();

View file

@ -732,46 +732,44 @@ impl StateInner {
item.element.prepaint_at(item_origin, window, cx);
});
if let Some(autoscroll_bounds) = window.take_autoscroll() {
if autoscroll {
if autoscroll_bounds.top() < bounds.top() {
return Err(ListOffset {
item_ix: item.index,
offset_in_item: autoscroll_bounds.top() - item_origin.y,
});
} else if autoscroll_bounds.bottom() > bounds.bottom() {
let mut cursor = self.items.cursor::<Count>(&());
cursor.seek(&Count(item.index), Bias::Right);
let mut height = bounds.size.height - padding.top - padding.bottom;
// Account for the height of the element down until the autoscroll bottom.
height -= autoscroll_bounds.bottom() - item_origin.y;
// Keep decreasing the scroll top until we fill all the available space.
while height > Pixels::ZERO {
cursor.prev();
let Some(item) = cursor.item() else { break };
let size = item.size().unwrap_or_else(|| {
let mut item = render_item(cursor.start().0, window, cx);
let item_available_size = size(
bounds.size.width.into(),
AvailableSpace::MinContent,
);
item.layout_as_root(item_available_size, window, cx)
});
height -= size.height;
}
return Err(ListOffset {
item_ix: cursor.start().0,
offset_in_item: if height < Pixels::ZERO {
-height
} else {
Pixels::ZERO
},
if let Some(autoscroll_bounds) = window.take_autoscroll()
&& autoscroll
{
if autoscroll_bounds.top() < bounds.top() {
return Err(ListOffset {
item_ix: item.index,
offset_in_item: autoscroll_bounds.top() - item_origin.y,
});
} else if autoscroll_bounds.bottom() > bounds.bottom() {
let mut cursor = self.items.cursor::<Count>(&());
cursor.seek(&Count(item.index), Bias::Right);
let mut height = bounds.size.height - padding.top - padding.bottom;
// Account for the height of the element down until the autoscroll bottom.
height -= autoscroll_bounds.bottom() - item_origin.y;
// Keep decreasing the scroll top until we fill all the available space.
while height > Pixels::ZERO {
cursor.prev();
let Some(item) = cursor.item() else { break };
let size = item.size().unwrap_or_else(|| {
let mut item = render_item(cursor.start().0, window, cx);
let item_available_size =
size(bounds.size.width.into(), AvailableSpace::MinContent);
item.layout_as_root(item_available_size, window, cx)
});
height -= size.height;
}
return Err(ListOffset {
item_ix: cursor.start().0,
offset_in_item: if height < Pixels::ZERO {
-height
} else {
Pixels::ZERO
},
});
}
}

View file

@ -356,12 +356,11 @@ impl TextLayout {
(None, "".into())
};
if let Some(text_layout) = element_state.0.borrow().as_ref() {
if text_layout.size.is_some()
&& (wrap_width.is_none() || wrap_width == text_layout.wrap_width)
{
return text_layout.size.unwrap();
}
if let Some(text_layout) = element_state.0.borrow().as_ref()
&& text_layout.size.is_some()
&& (wrap_width.is_none() || wrap_width == text_layout.wrap_width)
{
return text_layout.size.unwrap();
}
let mut line_wrapper = cx.text_system().line_wrapper(text_style.font(), font_size);
@ -763,14 +762,13 @@ impl Element for InteractiveText {
let mut interactive_state = interactive_state.unwrap_or_default();
if let Some(click_listener) = self.click_listener.take() {
let mouse_position = window.mouse_position();
if let Ok(ix) = text_layout.index_for_position(mouse_position) {
if self
if let Ok(ix) = text_layout.index_for_position(mouse_position)
&& self
.clickable_ranges
.iter()
.any(|range| range.contains(&ix))
{
window.set_cursor_style(crate::CursorStyle::PointingHand, hitbox)
}
{
window.set_cursor_style(crate::CursorStyle::PointingHand, hitbox)
}
let text_layout = text_layout.clone();
@ -803,13 +801,13 @@ impl Element for InteractiveText {
} else {
let hitbox = hitbox.clone();
window.on_mouse_event(move |event: &MouseDownEvent, phase, window, _| {
if phase == DispatchPhase::Bubble && hitbox.is_hovered(window) {
if let Ok(mouse_down_index) =
if phase == DispatchPhase::Bubble
&& hitbox.is_hovered(window)
&& let Ok(mouse_down_index) =
text_layout.index_for_position(event.position)
{
mouse_down.set(Some(mouse_down_index));
window.refresh();
}
{
mouse_down.set(Some(mouse_down_index));
window.refresh();
}
});
}

View file

@ -53,10 +53,10 @@ impl KeyBinding {
if let Some(equivalents) = key_equivalents {
for keystroke in keystrokes.iter_mut() {
if keystroke.key.chars().count() == 1 {
if let Some(key) = equivalents.get(&keystroke.key.chars().next().unwrap()) {
keystroke.key = key.to_string();
}
if keystroke.key.chars().count() == 1
&& let Some(key) = equivalents.get(&keystroke.key.chars().next().unwrap())
{
keystroke.key = key.to_string();
}
}
}

View file

@ -434,24 +434,24 @@ impl BladeRenderer {
}
fn wait_for_gpu(&mut self) {
if let Some(last_sp) = self.last_sync_point.take() {
if !self.gpu.wait_for(&last_sp, MAX_FRAME_TIME_MS) {
log::error!("GPU hung");
#[cfg(target_os = "linux")]
if self.gpu.device_information().driver_name == "radv" {
log::error!(
"there's a known bug with amdgpu/radv, try setting ZED_PATH_SAMPLE_COUNT=0 as a workaround"
);
log::error!(
"if that helps you're running into https://github.com/zed-industries/zed/issues/26143"
);
}
if let Some(last_sp) = self.last_sync_point.take()
&& !self.gpu.wait_for(&last_sp, MAX_FRAME_TIME_MS)
{
log::error!("GPU hung");
#[cfg(target_os = "linux")]
if self.gpu.device_information().driver_name == "radv" {
log::error!(
"your device information is: {:?}",
self.gpu.device_information()
"there's a known bug with amdgpu/radv, try setting ZED_PATH_SAMPLE_COUNT=0 as a workaround"
);
log::error!(
"if that helps you're running into https://github.com/zed-industries/zed/issues/26143"
);
while !self.gpu.wait_for(&last_sp, MAX_FRAME_TIME_MS) {}
}
log::error!(
"your device information is: {:?}",
self.gpu.device_information()
);
while !self.gpu.wait_for(&last_sp, MAX_FRAME_TIME_MS) {}
}
}

View file

@ -359,13 +359,13 @@ impl WaylandClientStatePtr {
}
changed
};
if changed {
if let Some(mut callback) = state.common.callbacks.keyboard_layout_change.take() {
drop(state);
callback();
state = client.borrow_mut();
state.common.callbacks.keyboard_layout_change = Some(callback);
}
if changed && let Some(mut callback) = state.common.callbacks.keyboard_layout_change.take()
{
drop(state);
callback();
state = client.borrow_mut();
state.common.callbacks.keyboard_layout_change = Some(callback);
}
}
@ -373,15 +373,15 @@ impl WaylandClientStatePtr {
let mut client = self.get_client();
let mut state = client.borrow_mut();
let closed_window = state.windows.remove(surface_id).unwrap();
if let Some(window) = state.mouse_focused_window.take() {
if !window.ptr_eq(&closed_window) {
state.mouse_focused_window = Some(window);
}
if let Some(window) = state.mouse_focused_window.take()
&& !window.ptr_eq(&closed_window)
{
state.mouse_focused_window = Some(window);
}
if let Some(window) = state.keyboard_focused_window.take() {
if !window.ptr_eq(&closed_window) {
state.keyboard_focused_window = Some(window);
}
if let Some(window) = state.keyboard_focused_window.take()
&& !window.ptr_eq(&closed_window)
{
state.keyboard_focused_window = Some(window);
}
if state.windows.is_empty() {
state.common.signal.stop();
@ -1784,17 +1784,17 @@ impl Dispatch<wl_pointer::WlPointer, ()> for WaylandClientStatePtr {
drop(state);
window.handle_input(input);
}
} else if let Some(discrete) = discrete {
if let Some(window) = state.mouse_focused_window.clone() {
let input = PlatformInput::ScrollWheel(ScrollWheelEvent {
position: state.mouse_location.unwrap(),
delta: ScrollDelta::Lines(discrete),
modifiers: state.modifiers,
touch_phase: TouchPhase::Moved,
});
drop(state);
window.handle_input(input);
}
} else if let Some(discrete) = discrete
&& let Some(window) = state.mouse_focused_window.clone()
{
let input = PlatformInput::ScrollWheel(ScrollWheelEvent {
position: state.mouse_location.unwrap(),
delta: ScrollDelta::Lines(discrete),
modifiers: state.modifiers,
touch_phase: TouchPhase::Moved,
});
drop(state);
window.handle_input(input);
}
}
}

View file

@ -45,10 +45,11 @@ impl Cursor {
}
fn set_theme_internal(&mut self, theme_name: Option<String>) {
if let Some(loaded_theme) = self.loaded_theme.as_ref() {
if loaded_theme.name == theme_name && loaded_theme.scaled_size == self.scaled_size {
return;
}
if let Some(loaded_theme) = self.loaded_theme.as_ref()
&& loaded_theme.name == theme_name
&& loaded_theme.scaled_size == self.scaled_size
{
return;
}
let result = if let Some(theme_name) = theme_name.as_ref() {
CursorTheme::load_from_name(

View file

@ -713,21 +713,20 @@ impl WaylandWindowStatePtr {
}
pub fn handle_input(&self, input: PlatformInput) {
if let Some(ref mut fun) = self.callbacks.borrow_mut().input {
if !fun(input.clone()).propagate {
return;
}
if let Some(ref mut fun) = self.callbacks.borrow_mut().input
&& !fun(input.clone()).propagate
{
return;
}
if let PlatformInput::KeyDown(event) = input {
if event.keystroke.modifiers.is_subset_of(&Modifiers::shift()) {
if let Some(key_char) = &event.keystroke.key_char {
let mut state = self.state.borrow_mut();
if let Some(mut input_handler) = state.input_handler.take() {
drop(state);
input_handler.replace_text_in_range(None, key_char);
self.state.borrow_mut().input_handler = Some(input_handler);
}
}
if let PlatformInput::KeyDown(event) = input
&& event.keystroke.modifiers.is_subset_of(&Modifiers::shift())
&& let Some(key_char) = &event.keystroke.key_char
{
let mut state = self.state.borrow_mut();
if let Some(mut input_handler) = state.input_handler.take() {
drop(state);
input_handler.replace_text_in_range(None, key_char);
self.state.borrow_mut().input_handler = Some(input_handler);
}
}
}

View file

@ -565,10 +565,10 @@ impl X11Client {
events.push(last_keymap_change_event);
}
if let Some(last_press) = last_key_press.as_ref() {
if last_press.detail == key_press.detail {
continue;
}
if let Some(last_press) = last_key_press.as_ref()
&& last_press.detail == key_press.detail
{
continue;
}
if let Some(Event::KeyRelease(key_release)) =
@ -2035,12 +2035,11 @@ fn xdnd_get_supported_atom(
),
)
.log_with_level(Level::Warn)
&& let Some(atoms) = reply.value32()
{
if let Some(atoms) = reply.value32() {
for atom in atoms {
if xdnd_is_atom_supported(atom, supported_atoms) {
return atom;
}
for atom in atoms {
if xdnd_is_atom_supported(atom, supported_atoms) {
return atom;
}
}
}
@ -2411,11 +2410,13 @@ fn legacy_get_randr_scale_factor(connection: &XCBConnection, root: u32) -> Optio
let mut crtc_infos: HashMap<randr::Crtc, randr::GetCrtcInfoReply> = HashMap::default();
let mut valid_outputs: HashSet<randr::Output> = HashSet::new();
for (crtc, cookie) in crtc_cookies {
if let Ok(reply) = cookie.reply() {
if reply.width > 0 && reply.height > 0 && !reply.outputs.is_empty() {
crtc_infos.insert(crtc, reply.clone());
valid_outputs.extend(&reply.outputs);
}
if let Ok(reply) = cookie.reply()
&& reply.width > 0
&& reply.height > 0
&& !reply.outputs.is_empty()
{
crtc_infos.insert(crtc, reply.clone());
valid_outputs.extend(&reply.outputs);
}
}

View file

@ -1120,25 +1120,25 @@ impl Drop for Clipboard {
log::error!("Failed to flush the clipboard window. Error: {}", e);
return;
}
if let Some(global_cb) = global_cb {
if let Err(e) = global_cb.server_handle.join() {
// Let's try extracting the error message
let message;
if let Some(msg) = e.downcast_ref::<&'static str>() {
message = Some((*msg).to_string());
} else if let Some(msg) = e.downcast_ref::<String>() {
message = Some(msg.clone());
} else {
message = None;
}
if let Some(message) = message {
log::error!(
"The clipboard server thread panicked. Panic message: '{}'",
message,
);
} else {
log::error!("The clipboard server thread panicked.");
}
if let Some(global_cb) = global_cb
&& let Err(e) = global_cb.server_handle.join()
{
// Let's try extracting the error message
let message;
if let Some(msg) = e.downcast_ref::<&'static str>() {
message = Some((*msg).to_string());
} else if let Some(msg) = e.downcast_ref::<String>() {
message = Some(msg.clone());
} else {
message = None;
}
if let Some(message) = message {
log::error!(
"The clipboard server thread panicked. Panic message: '{}'",
message,
);
} else {
log::error!("The clipboard server thread panicked.");
}
}
}

View file

@ -515,19 +515,19 @@ impl X11WindowState {
xcb.configure_window(x_window, &xproto::ConfigureWindowAux::new().x(x).y(y)),
)?;
}
if let Some(titlebar) = params.titlebar {
if let Some(title) = titlebar.title {
check_reply(
|| "X11 ChangeProperty8 on window title failed.",
xcb.change_property8(
xproto::PropMode::REPLACE,
x_window,
xproto::AtomEnum::WM_NAME,
xproto::AtomEnum::STRING,
title.as_bytes(),
),
)?;
}
if let Some(titlebar) = params.titlebar
&& let Some(title) = titlebar.title
{
check_reply(
|| "X11 ChangeProperty8 on window title failed.",
xcb.change_property8(
xproto::PropMode::REPLACE,
x_window,
xproto::AtomEnum::WM_NAME,
xproto::AtomEnum::STRING,
title.as_bytes(),
),
)?;
}
if params.kind == WindowKind::PopUp {
check_reply(
@ -956,10 +956,10 @@ impl X11WindowStatePtr {
}
pub fn handle_input(&self, input: PlatformInput) {
if let Some(ref mut fun) = self.callbacks.borrow_mut().input {
if !fun(input.clone()).propagate {
return;
}
if let Some(ref mut fun) = self.callbacks.borrow_mut().input
&& !fun(input.clone()).propagate
{
return;
}
if let PlatformInput::KeyDown(event) = input {
// only allow shift modifier when inserting text
@ -1068,15 +1068,14 @@ impl X11WindowStatePtr {
}
let mut callbacks = self.callbacks.borrow_mut();
if let Some((content_size, scale_factor)) = resize_args {
if let Some(ref mut fun) = callbacks.resize {
fun(content_size, scale_factor)
}
if let Some((content_size, scale_factor)) = resize_args
&& let Some(ref mut fun) = callbacks.resize
{
fun(content_size, scale_factor)
}
if !is_resize {
if let Some(ref mut fun) = callbacks.moved {
fun();
}
if !is_resize && let Some(ref mut fun) = callbacks.moved {
fun();
}
Ok(())

View file

@ -35,14 +35,14 @@ pub fn apply_features_and_fallbacks(
unsafe {
let mut keys = vec![kCTFontFeatureSettingsAttribute];
let mut values = vec![generate_feature_array(features)];
if let Some(fallbacks) = fallbacks {
if !fallbacks.fallback_list().is_empty() {
keys.push(kCTFontCascadeListAttribute);
values.push(generate_fallback_array(
fallbacks,
font.native_font().as_concrete_TypeRef(),
));
}
if let Some(fallbacks) = fallbacks
&& !fallbacks.fallback_list().is_empty()
{
keys.push(kCTFontCascadeListAttribute);
values.push(generate_fallback_array(
fallbacks,
font.native_font().as_concrete_TypeRef(),
));
}
let attrs = CFDictionaryCreate(
kCFAllocatorDefault,

View file

@ -715,10 +715,10 @@ impl Platform for MacPlatform {
let urls = panel.URLs();
for i in 0..urls.count() {
let url = urls.objectAtIndex(i);
if url.isFileURL() == YES {
if let Ok(path) = ns_url_to_path(url) {
result.push(path)
}
if url.isFileURL() == YES
&& let Ok(path) = ns_url_to_path(url)
{
result.push(path)
}
}
Some(result)
@ -786,15 +786,16 @@ impl Platform for MacPlatform {
// This is conditional on OS version because I'd like to get rid of it, so that
// you can manually create a file called `a.sql.s`. That said it seems better
// to break that use-case than breaking `a.sql`.
if chunks.len() == 3 && chunks[1].starts_with(chunks[2]) {
if Self::os_version() >= SemanticVersion::new(15, 0, 0) {
let new_filename = OsStr::from_bytes(
&filename.as_bytes()
[..chunks[0].len() + 1 + chunks[1].len()],
)
.to_owned();
result.set_file_name(&new_filename);
}
if chunks.len() == 3
&& chunks[1].starts_with(chunks[2])
&& Self::os_version() >= SemanticVersion::new(15, 0, 0)
{
let new_filename = OsStr::from_bytes(
&filename.as_bytes()
[..chunks[0].len() + 1 + chunks[1].len()],
)
.to_owned();
result.set_file_name(&new_filename);
}
return result;
})

View file

@ -1478,18 +1478,18 @@ extern "C" fn handle_key_event(this: &Object, native_event: id, key_equivalent:
return YES;
}
if key_down_event.is_held {
if let Some(key_char) = key_down_event.keystroke.key_char.as_ref() {
let handled = with_input_handler(this, |input_handler| {
if !input_handler.apple_press_and_hold_enabled() {
input_handler.replace_text_in_range(None, key_char);
return YES;
}
NO
});
if handled == Some(YES) {
if key_down_event.is_held
&& let Some(key_char) = key_down_event.keystroke.key_char.as_ref()
{
let handled = with_input_handler(this, |input_handler| {
if !input_handler.apple_press_and_hold_enabled() {
input_handler.replace_text_in_range(None, key_char);
return YES;
}
NO
});
if handled == Some(YES) {
return YES;
}
}
@ -1624,10 +1624,10 @@ extern "C" fn handle_view_event(this: &Object, _: Sel, native_event: id) {
modifiers: prev_modifiers,
capslock: prev_capslock,
})) = &lock.previous_modifiers_changed_event
&& prev_modifiers == modifiers
&& prev_capslock == capslock
{
if prev_modifiers == modifiers && prev_capslock == capslock {
return;
}
return;
}
lock.previous_modifiers_changed_event = Some(event.clone());
@ -1995,10 +1995,10 @@ extern "C" fn attributed_substring_for_proposed_range(
let mut adjusted: Option<Range<usize>> = None;
let selected_text = input_handler.text_for_range(range.clone(), &mut adjusted)?;
if let Some(adjusted) = adjusted {
if adjusted != range {
unsafe { (actual_range as *mut NSRange).write(NSRange::from(adjusted)) };
}
if let Some(adjusted) = adjusted
&& adjusted != range
{
unsafe { (actual_range as *mut NSRange).write(NSRange::from(adjusted)) };
}
unsafe {
let string: id = msg_send![class!(NSAttributedString), alloc];
@ -2073,11 +2073,10 @@ extern "C" fn dragging_entered(this: &Object, _: Sel, dragging_info: id) -> NSDr
let paths = external_paths_from_event(dragging_info);
if let Some(event) =
paths.map(|paths| PlatformInput::FileDrop(FileDropEvent::Entered { position, paths }))
&& send_new_event(&window_state, event)
{
if send_new_event(&window_state, event) {
window_state.lock().external_files_dragged = true;
return NSDragOperationCopy;
}
window_state.lock().external_files_dragged = true;
return NSDragOperationCopy;
}
NSDragOperationNone
}

View file

@ -78,11 +78,11 @@ impl TestDispatcher {
let state = self.state.lock();
let next_due_time = state.delayed.first().map(|(time, _)| *time);
drop(state);
if let Some(due_time) = next_due_time {
if due_time <= new_now {
self.state.lock().time = due_time;
continue;
}
if let Some(due_time) = next_due_time
&& due_time <= new_now
{
self.state.lock().time = due_time;
continue;
}
break;
}

View file

@ -201,10 +201,10 @@ impl TestPlatform {
executor
.spawn(async move {
if let Some(previous_window) = previous_window {
if let Some(window) = window.as_ref() {
if Rc::ptr_eq(&previous_window.0, &window.0) {
return;
}
if let Some(window) = window.as_ref()
&& Rc::ptr_eq(&previous_window.0, &window.0)
{
return;
}
previous_window.simulate_active_status_change(false);
}

View file

@ -701,29 +701,28 @@ impl WindowsWindowInner {
// Fix auto hide taskbar not showing. This solution is based on the approach
// used by Chrome. However, it may result in one row of pixels being obscured
// in our client area. But as Chrome says, "there seems to be no better solution."
if is_maximized {
if let Some(ref taskbar_position) = self
if is_maximized
&& let Some(ref taskbar_position) = self
.state
.borrow()
.system_settings
.auto_hide_taskbar_position
{
// Fot the auto-hide taskbar, adjust in by 1 pixel on taskbar edge,
// so the window isn't treated as a "fullscreen app", which would cause
// the taskbar to disappear.
match taskbar_position {
AutoHideTaskbarPosition::Left => {
requested_client_rect[0].left += AUTO_HIDE_TASKBAR_THICKNESS_PX
}
AutoHideTaskbarPosition::Top => {
requested_client_rect[0].top += AUTO_HIDE_TASKBAR_THICKNESS_PX
}
AutoHideTaskbarPosition::Right => {
requested_client_rect[0].right -= AUTO_HIDE_TASKBAR_THICKNESS_PX
}
AutoHideTaskbarPosition::Bottom => {
requested_client_rect[0].bottom -= AUTO_HIDE_TASKBAR_THICKNESS_PX
}
{
// Fot the auto-hide taskbar, adjust in by 1 pixel on taskbar edge,
// so the window isn't treated as a "fullscreen app", which would cause
// the taskbar to disappear.
match taskbar_position {
AutoHideTaskbarPosition::Left => {
requested_client_rect[0].left += AUTO_HIDE_TASKBAR_THICKNESS_PX
}
AutoHideTaskbarPosition::Top => {
requested_client_rect[0].top += AUTO_HIDE_TASKBAR_THICKNESS_PX
}
AutoHideTaskbarPosition::Right => {
requested_client_rect[0].right -= AUTO_HIDE_TASKBAR_THICKNESS_PX
}
AutoHideTaskbarPosition::Bottom => {
requested_client_rect[0].bottom -= AUTO_HIDE_TASKBAR_THICKNESS_PX
}
}
}
@ -1125,28 +1124,26 @@ impl WindowsWindowInner {
// lParam is a pointer to a string that indicates the area containing the system parameter
// that was changed.
let parameter = PCWSTR::from_raw(lparam.0 as _);
if unsafe { !parameter.is_null() && !parameter.is_empty() } {
if let Some(parameter_string) = unsafe { parameter.to_string() }.log_err() {
log::info!("System settings changed: {}", parameter_string);
match parameter_string.as_str() {
"ImmersiveColorSet" => {
let new_appearance = system_appearance()
.context(
"unable to get system appearance when handling ImmersiveColorSet",
)
.log_err()?;
let mut lock = self.state.borrow_mut();
if new_appearance != lock.appearance {
lock.appearance = new_appearance;
let mut callback = lock.callbacks.appearance_changed.take()?;
drop(lock);
callback();
self.state.borrow_mut().callbacks.appearance_changed = Some(callback);
configure_dwm_dark_mode(handle, new_appearance);
}
if unsafe { !parameter.is_null() && !parameter.is_empty() }
&& let Some(parameter_string) = unsafe { parameter.to_string() }.log_err()
{
log::info!("System settings changed: {}", parameter_string);
match parameter_string.as_str() {
"ImmersiveColorSet" => {
let new_appearance = system_appearance()
.context("unable to get system appearance when handling ImmersiveColorSet")
.log_err()?;
let mut lock = self.state.borrow_mut();
if new_appearance != lock.appearance {
lock.appearance = new_appearance;
let mut callback = lock.callbacks.appearance_changed.take()?;
drop(lock);
callback();
self.state.borrow_mut().callbacks.appearance_changed = Some(callback);
configure_dwm_dark_mode(handle, new_appearance);
}
_ => {}
}
_ => {}
}
}
Some(0)

View file

@ -821,14 +821,14 @@ fn file_save_dialog(
window: Option<HWND>,
) -> Result<Option<PathBuf>> {
let dialog: IFileSaveDialog = unsafe { CoCreateInstance(&FileSaveDialog, None, CLSCTX_ALL)? };
if !directory.to_string_lossy().is_empty() {
if let Some(full_path) = directory.canonicalize().log_err() {
let full_path = SanitizedPath::from(full_path);
let full_path_string = full_path.to_string();
let path_item: IShellItem =
unsafe { SHCreateItemFromParsingName(&HSTRING::from(full_path_string), None)? };
unsafe { dialog.SetFolder(&path_item).log_err() };
}
if !directory.to_string_lossy().is_empty()
&& let Some(full_path) = directory.canonicalize().log_err()
{
let full_path = SanitizedPath::from(full_path);
let full_path_string = full_path.to_string();
let path_item: IShellItem =
unsafe { SHCreateItemFromParsingName(&HSTRING::from(full_path_string), None)? };
unsafe { dialog.SetFolder(&path_item).log_err() };
}
if let Some(suggested_name) = suggested_name {

View file

@ -366,15 +366,14 @@ impl WindowTextSystem {
let mut decoration_runs = SmallVec::<[DecorationRun; 32]>::new();
for run in runs {
if let Some(last_run) = decoration_runs.last_mut() {
if last_run.color == run.color
&& last_run.underline == run.underline
&& last_run.strikethrough == run.strikethrough
&& last_run.background_color == run.background_color
{
last_run.len += run.len as u32;
continue;
}
if let Some(last_run) = decoration_runs.last_mut()
&& last_run.color == run.color
&& last_run.underline == run.underline
&& last_run.strikethrough == run.strikethrough
&& last_run.background_color == run.background_color
{
last_run.len += run.len as u32;
continue;
}
decoration_runs.push(DecorationRun {
len: run.len as u32,
@ -492,14 +491,14 @@ impl WindowTextSystem {
let mut split_lines = text.split('\n');
let mut processed = false;
if let Some(first_line) = split_lines.next() {
if let Some(second_line) = split_lines.next() {
processed = true;
process_line(first_line.to_string().into());
process_line(second_line.to_string().into());
for line_text in split_lines {
process_line(line_text.to_string().into());
}
if let Some(first_line) = split_lines.next()
&& let Some(second_line) = split_lines.next()
{
processed = true;
process_line(first_line.to_string().into());
process_line(second_line.to_string().into());
for line_text in split_lines {
process_line(line_text.to_string().into());
}
}
@ -534,11 +533,11 @@ impl WindowTextSystem {
let mut font_runs = self.font_runs_pool.lock().pop().unwrap_or_default();
for run in runs.iter() {
let font_id = self.resolve_font(&run.font);
if let Some(last_run) = font_runs.last_mut() {
if last_run.font_id == font_id {
last_run.len += run.len;
continue;
}
if let Some(last_run) = font_runs.last_mut()
&& last_run.font_id == font_id
{
last_run.len += run.len;
continue;
}
font_runs.push(FontRun {
len: run.len,

View file

@ -292,10 +292,10 @@ fn paint_line(
}
if let Some(style_run) = style_run {
if let Some((_, underline_style)) = &mut current_underline {
if style_run.underline.as_ref() != Some(underline_style) {
finished_underline = current_underline.take();
}
if let Some((_, underline_style)) = &mut current_underline
&& style_run.underline.as_ref() != Some(underline_style)
{
finished_underline = current_underline.take();
}
if let Some(run_underline) = style_run.underline.as_ref() {
current_underline.get_or_insert((
@ -310,10 +310,10 @@ fn paint_line(
},
));
}
if let Some((_, strikethrough_style)) = &mut current_strikethrough {
if style_run.strikethrough.as_ref() != Some(strikethrough_style) {
finished_strikethrough = current_strikethrough.take();
}
if let Some((_, strikethrough_style)) = &mut current_strikethrough
&& style_run.strikethrough.as_ref() != Some(strikethrough_style)
{
finished_strikethrough = current_strikethrough.take();
}
if let Some(run_strikethrough) = style_run.strikethrough.as_ref() {
current_strikethrough.get_or_insert((
@ -509,10 +509,10 @@ fn paint_line_background(
}
if let Some(style_run) = style_run {
if let Some((_, background_color)) = &mut current_background {
if style_run.background_color.as_ref() != Some(background_color) {
finished_background = current_background.take();
}
if let Some((_, background_color)) = &mut current_background
&& style_run.background_color.as_ref() != Some(background_color)
{
finished_background = current_background.take();
}
if let Some(run_background) = style_run.background_color {
current_background.get_or_insert((

View file

@ -185,10 +185,10 @@ impl LineLayout {
if width > wrap_width && boundary > last_boundary {
// When used line_clamp, we should limit the number of lines.
if let Some(max_lines) = max_lines {
if boundaries.len() >= max_lines - 1 {
break;
}
if let Some(max_lines) = max_lines
&& boundaries.len() >= max_lines - 1
{
break;
}
if let Some(last_candidate_ix) = last_candidate_ix.take() {

View file

@ -205,22 +205,21 @@ impl Element for AnyView {
let content_mask = window.content_mask();
let text_style = window.text_style();
if let Some(mut element_state) = element_state {
if element_state.cache_key.bounds == bounds
&& element_state.cache_key.content_mask == content_mask
&& element_state.cache_key.text_style == text_style
&& !window.dirty_views.contains(&self.entity_id())
&& !window.refreshing
{
let prepaint_start = window.prepaint_index();
window.reuse_prepaint(element_state.prepaint_range.clone());
cx.entities
.extend_accessed(&element_state.accessed_entities);
let prepaint_end = window.prepaint_index();
element_state.prepaint_range = prepaint_start..prepaint_end;
if let Some(mut element_state) = element_state
&& element_state.cache_key.bounds == bounds
&& element_state.cache_key.content_mask == content_mask
&& element_state.cache_key.text_style == text_style
&& !window.dirty_views.contains(&self.entity_id())
&& !window.refreshing
{
let prepaint_start = window.prepaint_index();
window.reuse_prepaint(element_state.prepaint_range.clone());
cx.entities
.extend_accessed(&element_state.accessed_entities);
let prepaint_end = window.prepaint_index();
element_state.prepaint_range = prepaint_start..prepaint_end;
return (None, element_state);
}
return (None, element_state);
}
let refreshing = mem::replace(&mut window.refreshing, true);

View file

@ -3401,16 +3401,16 @@ impl Window {
let focus_id = handle.id;
let (subscription, activate) =
self.new_focus_listener(Box::new(move |event, window, cx| {
if let Some(blurred_id) = event.previous_focus_path.last().copied() {
if event.is_focus_out(focus_id) {
let event = FocusOutEvent {
blurred: WeakFocusHandle {
id: blurred_id,
handles: Arc::downgrade(&cx.focus_handles),
},
};
listener(event, window, cx)
}
if let Some(blurred_id) = event.previous_focus_path.last().copied()
&& event.is_focus_out(focus_id)
{
let event = FocusOutEvent {
blurred: WeakFocusHandle {
id: blurred_id,
handles: Arc::downgrade(&cx.focus_handles),
},
};
listener(event, window, cx)
}
true
}));
@ -3444,12 +3444,12 @@ impl Window {
return true;
}
if let Some(input) = keystroke.key_char {
if let Some(mut input_handler) = self.platform_window.take_input_handler() {
input_handler.dispatch_input(&input, self, cx);
self.platform_window.set_input_handler(input_handler);
return true;
}
if let Some(input) = keystroke.key_char
&& let Some(mut input_handler) = self.platform_window.take_input_handler()
{
input_handler.dispatch_input(&input, self, cx);
self.platform_window.set_input_handler(input_handler);
return true;
}
false
@ -3864,11 +3864,11 @@ impl Window {
if !cx.propagate_event {
continue 'replay;
}
if let Some(input) = replay.keystroke.key_char.as_ref().cloned() {
if let Some(mut input_handler) = self.platform_window.take_input_handler() {
input_handler.dispatch_input(&input, self, cx);
self.platform_window.set_input_handler(input_handler)
}
if let Some(input) = replay.keystroke.key_char.as_ref().cloned()
&& let Some(mut input_handler) = self.platform_window.take_input_handler()
{
input_handler.dispatch_input(&input, self, cx);
self.platform_window.set_input_handler(input_handler)
}
}
}
@ -4309,15 +4309,15 @@ impl Window {
cx: &mut App,
f: impl FnOnce(&mut Option<T>, &mut Self) -> R,
) -> R {
if let Some(inspector_id) = _inspector_id {
if let Some(inspector) = &self.inspector {
let inspector = inspector.clone();
let active_element_id = inspector.read(cx).active_element_id();
if Some(inspector_id) == active_element_id {
return inspector.update(cx, |inspector, _cx| {
inspector.with_active_element_state(self, f)
});
}
if let Some(inspector_id) = _inspector_id
&& let Some(inspector) = &self.inspector
{
let inspector = inspector.clone();
let active_element_id = inspector.read(cx).active_element_id();
if Some(inspector_id) == active_element_id {
return inspector.update(cx, |inspector, _cx| {
inspector.with_active_element_state(self, f)
});
}
}
f(&mut None, self)
@ -4389,15 +4389,13 @@ impl Window {
if let Some(inspector) = self.inspector.as_ref() {
let inspector = inspector.read(cx);
if let Some((hitbox_id, _)) = self.hovered_inspector_hitbox(inspector, &self.next_frame)
{
if let Some(hitbox) = self
&& let Some(hitbox) = self
.next_frame
.hitboxes
.iter()
.find(|hitbox| hitbox.id == hitbox_id)
{
self.paint_quad(crate::fill(hitbox.bounds, crate::rgba(0x61afef4d)));
}
{
self.paint_quad(crate::fill(hitbox.bounds, crate::rgba(0x61afef4d)));
}
}
}