First pass on fixes

This commit is contained in:
Piotr Osiewicz 2025-08-19 14:23:59 +02:00
parent 5826d89b97
commit 2f3be75fc7
269 changed files with 1593 additions and 2574 deletions

View file

@ -969,15 +969,14 @@ impl DisplaySnapshot {
if let Some(chunk_highlight) = chunk.highlight_style {
// For color inlays, blend the color with the editor background
let mut processed_highlight = chunk_highlight;
if chunk.is_inlay {
if let Some(inlay_color) = chunk_highlight.color {
if chunk.is_inlay
&& let Some(inlay_color) = chunk_highlight.color {
// Only blend if the color has transparency (alpha < 1.0)
if inlay_color.a < 1.0 {
let blended_color = editor_style.background.blend(inlay_color);
processed_highlight.color = Some(blended_color);
}
}
}
if let Some(highlight_style) = highlight_style.as_mut() {
highlight_style.highlight(processed_highlight);
@ -2351,12 +2350,11 @@ pub mod tests {
.highlight_style
.and_then(|style| style.color)
.map_or(black, |color| color.to_rgb());
if let Some((last_chunk, last_severity, last_color)) = chunks.last_mut() {
if *last_severity == chunk.diagnostic_severity && *last_color == color {
if let Some((last_chunk, last_severity, last_color)) = chunks.last_mut()
&& *last_severity == chunk.diagnostic_severity && *last_color == color {
last_chunk.push_str(chunk.text);
continue;
}
}
chunks.push((chunk.text.to_string(), chunk.diagnostic_severity, color));
}
@ -2901,12 +2899,11 @@ pub mod tests {
.syntax_highlight_id
.and_then(|id| id.style(theme)?.color);
let highlight_color = chunk.highlight_style.and_then(|style| style.color);
if let Some((last_chunk, last_syntax_color, last_highlight_color)) = chunks.last_mut() {
if syntax_color == *last_syntax_color && highlight_color == *last_highlight_color {
if let Some((last_chunk, last_syntax_color, last_highlight_color)) = chunks.last_mut()
&& syntax_color == *last_syntax_color && highlight_color == *last_highlight_color {
last_chunk.push_str(chunk.text);
continue;
}
}
chunks.push((chunk.text.to_string(), syntax_color, highlight_color));
}
chunks

View file

@ -525,8 +525,8 @@ impl BlockMap {
// * Below blocks that end at the start of the edit
// However, if we hit a replace block that ends at the start of the edit we want to reconstruct it.
new_transforms.append(cursor.slice(&old_start, Bias::Left), &());
if let Some(transform) = cursor.item() {
if transform.summary.input_rows > 0
if let Some(transform) = cursor.item()
&& transform.summary.input_rows > 0
&& cursor.end() == old_start
&& transform
.block
@ -547,7 +547,6 @@ impl BlockMap {
}
}
}
}
// Ensure the edit starts at a transform boundary.
// If the edit starts within an isomorphic transform, preserve its prefix
@ -657,11 +656,10 @@ impl BlockMap {
.iter()
.filter_map(|block| {
let placement = block.placement.to_wrap_row(wrap_snapshot)?;
if let BlockPlacement::Above(row) = placement {
if row < new_start {
if let BlockPlacement::Above(row) = placement
&& row < new_start {
return None;
}
}
Some((placement, Block::Custom(block.clone())))
}),
);
@ -977,11 +975,10 @@ impl BlockMapReader<'_> {
break;
}
if let Some(BlockId::Custom(id)) = transform.block.as_ref().map(|block| block.id()) {
if id == block_id {
if let Some(BlockId::Custom(id)) = transform.block.as_ref().map(|block| block.id())
&& id == block_id {
return Some(cursor.start().1);
}
}
cursor.next();
}
@ -1299,15 +1296,14 @@ impl BlockSnapshot {
let mut input_start = transform_input_start;
let mut input_end = transform_input_start;
if let Some(transform) = cursor.item() {
if transform.block.is_none() {
if let Some(transform) = cursor.item()
&& transform.block.is_none() {
input_start += rows.start - transform_output_start;
input_end += cmp::min(
rows.end - transform_output_start,
transform.summary.input_rows,
);
}
}
BlockChunks {
input_chunks: self.wrap_snapshot.chunks(
@ -1472,8 +1468,8 @@ impl BlockSnapshot {
longest_row_chars = summary.longest_row_chars;
}
if let Some(transform) = cursor.item() {
if transform.block.is_none() {
if let Some(transform) = cursor.item()
&& transform.block.is_none() {
let Dimensions(output_start, input_start, _) = cursor.start();
let overshoot = range.end.0 - output_start.0;
let wrap_start_row = input_start.0;
@ -1485,7 +1481,6 @@ impl BlockSnapshot {
longest_row = BlockRow(output_start.0 + summary.longest_row);
}
}
}
}
longest_row
@ -1557,13 +1552,12 @@ impl BlockSnapshot {
match transform.block.as_ref() {
Some(block) => {
if block.is_replacement() {
if ((bias == Bias::Left || search_left) && output_start <= point.0)
|| (!search_left && output_start >= point.0)
if block.is_replacement()
&& (((bias == Bias::Left || search_left) && output_start <= point.0)
|| (!search_left && output_start >= point.0))
{
return BlockPoint(output_start);
}
}
}
None => {
let input_point = if point.row >= output_end_row.0 {
@ -3228,8 +3222,7 @@ mod tests {
let mut is_in_replace_block = false;
if let Some((BlockPlacement::Replace(replace_range), block)) =
sorted_blocks_iter.peek()
{
if wrap_row >= replace_range.start().0 {
&& wrap_row >= replace_range.start().0 {
is_in_replace_block = true;
if wrap_row == replace_range.start().0 {
@ -3257,7 +3250,6 @@ mod tests {
sorted_blocks_iter.next();
}
}
}
if is_in_replace_block {
expected_replaced_buffer_rows.insert(MultiBufferRow(multibuffer_row));

View file

@ -289,8 +289,8 @@ impl FoldMapWriter<'_> {
let ChunkRendererId::Fold(id) = id else {
continue;
};
if let Some(metadata) = self.0.snapshot.fold_metadata_by_id.get(&id).cloned() {
if Some(new_width) != metadata.width {
if let Some(metadata) = self.0.snapshot.fold_metadata_by_id.get(&id).cloned()
&& Some(new_width) != metadata.width {
let buffer_start = metadata.range.start.to_offset(buffer);
let buffer_end = metadata.range.end.to_offset(buffer);
let inlay_range = inlay_snapshot.to_inlay_offset(buffer_start)
@ -308,7 +308,6 @@ impl FoldMapWriter<'_> {
},
);
}
}
}
let edits = consolidate_inlay_edits(edits);
@ -417,8 +416,8 @@ impl FoldMap {
cursor.seek(&InlayOffset(0), Bias::Right);
while let Some(mut edit) = inlay_edits_iter.next() {
if let Some(item) = cursor.item() {
if !item.is_fold() {
if let Some(item) = cursor.item()
&& !item.is_fold() {
new_transforms.update_last(
|transform| {
if !transform.is_fold() {
@ -429,7 +428,6 @@ impl FoldMap {
&(),
);
}
}
new_transforms.append(cursor.slice(&edit.old.start, Bias::Left), &());
edit.new.start -= edit.old.start - *cursor.start();
edit.old.start = *cursor.start();

View file

@ -557,12 +557,11 @@ impl InlayMap {
let mut buffer_edits_iter = buffer_edits.iter().peekable();
while let Some(buffer_edit) = buffer_edits_iter.next() {
new_transforms.append(cursor.slice(&buffer_edit.old.start, Bias::Left), &());
if let Some(Transform::Isomorphic(transform)) = cursor.item() {
if cursor.end().0 == buffer_edit.old.start {
if let Some(Transform::Isomorphic(transform)) = cursor.item()
&& cursor.end().0 == buffer_edit.old.start {
push_isomorphic(&mut new_transforms, *transform);
cursor.next();
}
}
// Remove all the inlays and transforms contained by the edit.
let old_start =

View file

@ -249,8 +249,8 @@ impl WrapMap {
return;
}
if let Some(wrap_width) = self.wrap_width {
if self.background_task.is_none() {
if let Some(wrap_width) = self.wrap_width
&& self.background_task.is_none() {
let pending_edits = self.pending_edits.clone();
let mut snapshot = self.snapshot.clone();
let text_system = cx.text_system().clone();
@ -293,7 +293,6 @@ impl WrapMap {
}
}
}
}
let was_interpolated = self.snapshot.interpolated;
let mut to_remove_len = 0;
@ -1065,13 +1064,12 @@ impl sum_tree::Item for Transform {
}
fn push_isomorphic(transforms: &mut Vec<Transform>, summary: TextSummary) {
if let Some(last_transform) = transforms.last_mut() {
if last_transform.is_isomorphic() {
if let Some(last_transform) = transforms.last_mut()
&& last_transform.is_isomorphic() {
last_transform.summary.input += &summary;
last_transform.summary.output += &summary;
return;
}
}
transforms.push(Transform::isomorphic(summary));
}

View file

@ -942,11 +942,10 @@ impl ChangeList {
}
pub fn invert_last_group(&mut self) {
if let Some(last) = self.changes.last_mut() {
if let Some(current) = last.current.as_mut() {
if let Some(last) = self.changes.last_mut()
&& let Some(current) = last.current.as_mut() {
mem::swap(&mut last.original, current);
}
}
}
}
@ -1861,8 +1860,8 @@ impl Editor {
.then(|| language_settings::SoftWrap::None);
let mut project_subscriptions = Vec::new();
if full_mode {
if let Some(project) = project.as_ref() {
if full_mode
&& let Some(project) = project.as_ref() {
project_subscriptions.push(cx.subscribe_in(
project,
window,
@ -1969,7 +1968,6 @@ impl Editor {
}
}));
}
}
let buffer_snapshot = buffer.read(cx).snapshot(cx);
@ -2323,8 +2321,8 @@ impl Editor {
editor.go_to_active_debug_line(window, cx);
if let Some(buffer) = buffer.read(cx).as_singleton() {
if let Some(project) = editor.project() {
if let Some(buffer) = buffer.read(cx).as_singleton()
&& let Some(project) = editor.project() {
let handle = project.update(cx, |project, cx| {
project.register_buffer_with_language_servers(&buffer, cx)
});
@ -2332,7 +2330,6 @@ impl Editor {
.registered_buffers
.insert(buffer.read(cx).remote_id(), handle);
}
}
editor.minimap =
editor.create_minimap(EditorSettings::get_global(cx).minimap, window, cx);
@ -3035,9 +3032,9 @@ impl Editor {
}
if local {
if let Some(buffer_id) = new_cursor_position.buffer_id {
if !self.registered_buffers.contains_key(&buffer_id) {
if let Some(project) = self.project.as_ref() {
if let Some(buffer_id) = new_cursor_position.buffer_id
&& !self.registered_buffers.contains_key(&buffer_id)
&& let Some(project) = self.project.as_ref() {
project.update(cx, |project, cx| {
let Some(buffer) = self.buffer.read(cx).buffer(buffer_id) else {
return;
@ -3048,8 +3045,6 @@ impl Editor {
);
})
}
}
}
let mut context_menu = self.context_menu.borrow_mut();
let completion_menu = match context_menu.as_ref() {
@ -3063,8 +3058,8 @@ impl Editor {
let completion_position = completion_menu.map(|menu| menu.initial_position);
drop(context_menu);
if effects.completions {
if let Some(completion_position) = completion_position {
if effects.completions
&& let Some(completion_position) = completion_position {
let start_offset = selection_start.to_offset(buffer);
let position_matches = start_offset == completion_position.to_offset(buffer);
let continue_showing = if position_matches {
@ -3086,7 +3081,6 @@ impl Editor {
self.hide_context_menu(window, cx);
}
}
}
hide_hover(self, cx);
@ -3115,8 +3109,8 @@ impl Editor {
if selections.len() == 1 {
cx.emit(SearchEvent::ActiveMatchChanged)
}
if local {
if let Some((_, _, buffer_snapshot)) = buffer.as_singleton() {
if local
&& let Some((_, _, buffer_snapshot)) = buffer.as_singleton() {
let inmemory_selections = selections
.iter()
.map(|s| {
@ -3130,8 +3124,7 @@ impl Editor {
if WorkspaceSettings::get(None, cx).restore_on_startup
!= RestoreOnStartupBehavior::None
{
if let Some(workspace_id) =
&& let Some(workspace_id) =
self.workspace.as_ref().and_then(|workspace| workspace.1)
{
let snapshot = self.buffer().read(cx).snapshot(cx);
@ -3156,9 +3149,7 @@ impl Editor {
.log_err();
});
}
}
}
}
cx.notify();
}
@ -4154,12 +4145,10 @@ impl Editor {
if self.auto_replace_emoji_shortcode
&& selection.is_empty()
&& text.as_ref().ends_with(':')
{
if let Some(possible_emoji_short_code) =
&& let Some(possible_emoji_short_code) =
Self::find_possible_emoji_shortcode_at_position(&snapshot, selection.start)
{
if !possible_emoji_short_code.is_empty() {
if let Some(emoji) = emojis::get_by_shortcode(&possible_emoji_short_code) {
&& !possible_emoji_short_code.is_empty()
&& let Some(emoji) = emojis::get_by_shortcode(&possible_emoji_short_code) {
let emoji_shortcode_start = Point::new(
selection.start.row,
selection.start.column - possible_emoji_short_code.len() as u32 - 1,
@ -4188,9 +4177,6 @@ impl Editor {
continue;
}
}
}
}
// If not handling any auto-close operation, then just replace the selected
// text with the given input and move the selection to the end of the
@ -4303,13 +4289,12 @@ impl Editor {
|s| s.select(new_selections),
);
if !bracket_inserted {
if let Some(on_type_format_task) =
if !bracket_inserted
&& let Some(on_type_format_task) =
this.trigger_on_type_formatting(text.to_string(), window, cx)
{
on_type_format_task.detach_and_log_err(cx);
}
}
let editor_settings = EditorSettings::get_global(cx);
if bracket_inserted
@ -5274,11 +5259,10 @@ impl Editor {
}
let language = buffer.language()?;
if let Some(restrict_to_languages) = restrict_to_languages {
if !restrict_to_languages.contains(language) {
if let Some(restrict_to_languages) = restrict_to_languages
&& !restrict_to_languages.contains(language) {
return None;
}
}
Some((
excerpt_id,
(
@ -5605,8 +5589,8 @@ impl Editor {
// that having one source with `is_incomplete: true` doesn't cause all to be re-queried.
let mut completions = Vec::new();
let mut is_incomplete = false;
if let Some(provider_responses) = provider_responses.await.log_err() {
if !provider_responses.is_empty() {
if let Some(provider_responses) = provider_responses.await.log_err()
&& !provider_responses.is_empty() {
for response in provider_responses {
completions.extend(response.completions);
is_incomplete = is_incomplete || response.is_incomplete;
@ -5615,7 +5599,6 @@ impl Editor {
words = Task::ready(BTreeMap::default());
}
}
}
let mut words = words.await;
if let Some(word_to_exclude) = &word_to_exclude {
@ -5718,8 +5701,8 @@ impl Editor {
editor
.update_in(cx, |editor, window, cx| {
if editor.focus_handle.is_focused(window) {
if let Some(menu) = menu {
if editor.focus_handle.is_focused(window)
&& let Some(menu) = menu {
*editor.context_menu.borrow_mut() =
Some(CodeContextMenu::Completions(menu));
@ -5733,7 +5716,6 @@ impl Editor {
cx.notify();
return;
}
}
if editor.completion_tasks.len() <= 1 {
// If there are no more completion tasks and the last menu was empty, we should hide it.
@ -6079,12 +6061,11 @@ impl Editor {
Some(CodeActionSource::Indicator(_)) => Task::ready(Ok(Default::default())),
_ => {
let mut task_context_task = Task::ready(None);
if let Some(tasks) = &tasks {
if let Some(project) = project {
if let Some(tasks) = &tasks
&& let Some(project) = project {
task_context_task =
Self::build_tasks_context(&project, &buffer, buffer_row, tasks, cx);
}
}
cx.spawn_in(window, {
let buffer = buffer.clone();
@ -6148,15 +6129,14 @@ impl Editor {
deployed_from,
}));
cx.notify();
if spawn_straight_away {
if let Some(task) = editor.confirm_code_action(
if spawn_straight_away
&& let Some(task) = editor.confirm_code_action(
&ConfirmCodeAction { item_ix: Some(0) },
window,
cx,
) {
return task;
}
}
Task::ready(Ok(()))
})
@ -6342,8 +6322,8 @@ impl Editor {
.read(cx)
.excerpt_containing(editor.selections.newest_anchor().head(), cx)
})?;
if let Some((_, excerpted_buffer, excerpt_range)) = excerpt {
if excerpted_buffer == *buffer {
if let Some((_, excerpted_buffer, excerpt_range)) = excerpt
&& excerpted_buffer == *buffer {
let all_edits_within_excerpt = buffer.read_with(cx, |buffer, _| {
let excerpt_range = excerpt_range.to_offset(buffer);
buffer
@ -6358,7 +6338,6 @@ impl Editor {
return Ok(());
}
}
}
}
} else {
return Ok(());
@ -7779,11 +7758,10 @@ impl Editor {
let indents = multibuffer.suggested_indents(cursor_point.row..cursor_point.row + 1, cx);
if let Some((_, indent)) = indents.iter().next() {
if indent.len == cursor_point.column {
if let Some((_, indent)) = indents.iter().next()
&& indent.len == cursor_point.column {
self.edit_prediction_indent_conflict = false;
}
}
}
let edit_prediction = provider.suggest(&buffer, cursor_buffer_position, cx)?;
@ -9531,11 +9509,10 @@ impl Editor {
let context_menu = self.context_menu.borrow_mut().take();
self.stale_edit_prediction_in_menu.take();
self.update_visible_edit_prediction(window, cx);
if let Some(CodeContextMenu::Completions(_)) = &context_menu {
if let Some(completion_provider) = &self.completion_provider {
if let Some(CodeContextMenu::Completions(_)) = &context_menu
&& let Some(completion_provider) = &self.completion_provider {
completion_provider.selection_changed(None, window, cx);
}
}
context_menu
}
@ -9639,11 +9616,10 @@ impl Editor {
s.select_ranges(tabstop.ranges.iter().rev().cloned());
});
if let Some(choices) = &tabstop.choices {
if let Some(selection) = tabstop.ranges.first() {
if let Some(choices) = &tabstop.choices
&& let Some(selection) = tabstop.ranges.first() {
self.show_snippet_choices(choices, selection.clone(), cx)
}
}
// If we're already at the last tabstop and it's at the end of the snippet,
// we're done, we don't need to keep the state around.
@ -9776,11 +9752,10 @@ impl Editor {
s.select_ranges(current_ranges.iter().rev().cloned())
});
if let Some(choices) = &snippet.choices[snippet.active_index] {
if let Some(selection) = current_ranges.first() {
if let Some(choices) = &snippet.choices[snippet.active_index]
&& let Some(selection) = current_ranges.first() {
self.show_snippet_choices(choices, selection.clone(), cx);
}
}
// If snippet state is not at the last tabstop, push it back on the stack
if snippet.active_index + 1 < snippet.ranges.len() {
@ -10176,11 +10151,10 @@ impl Editor {
// Avoid re-outdenting a row that has already been outdented by a
// previous selection.
if let Some(last_row) = last_outdent {
if last_row == rows.start {
if let Some(last_row) = last_outdent
&& last_row == rows.start {
rows.start = rows.start.next_row();
}
}
let has_multiple_rows = rows.len() > 1;
for row in rows.iter_rows() {
let indent_size = snapshot.indent_size_for_line(row);
@ -10357,12 +10331,11 @@ impl Editor {
MultiBufferRow(selection.end.row)
};
if let Some(last_row_range) = row_ranges.last_mut() {
if start <= last_row_range.end {
if let Some(last_row_range) = row_ranges.last_mut()
&& start <= last_row_range.end {
last_row_range.end = end;
continue;
}
}
row_ranges.push(start..end);
}
@ -15331,9 +15304,9 @@ impl Editor {
if direction == ExpandExcerptDirection::Down {
let multi_buffer = self.buffer.read(cx);
let snapshot = multi_buffer.snapshot(cx);
if let Some(buffer_id) = snapshot.buffer_id_for_excerpt(excerpt) {
if let Some(buffer) = multi_buffer.buffer(buffer_id) {
if let Some(excerpt_range) = snapshot.buffer_range_for_excerpt(excerpt) {
if let Some(buffer_id) = snapshot.buffer_id_for_excerpt(excerpt)
&& let Some(buffer) = multi_buffer.buffer(buffer_id)
&& let Some(excerpt_range) = snapshot.buffer_range_for_excerpt(excerpt) {
let buffer_snapshot = buffer.read(cx).snapshot();
let excerpt_end_row =
Point::from_anchor(&excerpt_range.end, &buffer_snapshot).row;
@ -15341,8 +15314,6 @@ impl Editor {
let lines_below = last_row.saturating_sub(excerpt_end_row);
should_scroll_up = lines_below >= lines_to_expand;
}
}
}
}
self.buffer.update(cx, |buffer, cx| {
@ -15426,11 +15397,10 @@ impl Editor {
let selection = self.selections.newest::<usize>(cx);
let mut active_group_id = None;
if let ActiveDiagnostic::Group(active_group) = &self.active_diagnostics {
if active_group.active_range.start.to_offset(&buffer) == selection.start {
if let ActiveDiagnostic::Group(active_group) = &self.active_diagnostics
&& active_group.active_range.start.to_offset(&buffer) == selection.start {
active_group_id = Some(active_group.group_id);
}
}
fn filtered(
snapshot: EditorSnapshot,
@ -16674,11 +16644,10 @@ impl Editor {
buffer
.update(cx, |buffer, cx| {
if let Some(transaction) = transaction {
if !buffer.is_singleton() {
if let Some(transaction) = transaction
&& !buffer.is_singleton() {
buffer.push_transaction(&transaction.0, cx);
}
}
cx.notify();
})
.ok();
@ -16743,11 +16712,10 @@ impl Editor {
buffer
.update(cx, |buffer, cx| {
// check if we need this
if let Some(transaction) = transaction {
if !buffer.is_singleton() {
if let Some(transaction) = transaction
&& !buffer.is_singleton() {
buffer.push_transaction(&transaction.0, cx);
}
}
cx.notify();
})
.ok();
@ -17378,14 +17346,13 @@ impl Editor {
}
for row in (0..=range.start.row).rev() {
if let Some(crease) = display_map.crease_for_buffer_row(MultiBufferRow(row)) {
if crease.range().end.row >= buffer_start_row {
if let Some(crease) = display_map.crease_for_buffer_row(MultiBufferRow(row))
&& crease.range().end.row >= buffer_start_row {
to_fold.push(crease);
if row <= range.start.row {
break;
}
}
}
}
}
@ -18693,11 +18660,10 @@ impl Editor {
pub fn working_directory(&self, cx: &App) -> Option<PathBuf> {
if let Some(buffer) = self.buffer().read(cx).as_singleton() {
if let Some(file) = buffer.read(cx).file().and_then(|f| f.as_local()) {
if let Some(dir) = file.abs_path(cx).parent() {
if let Some(file) = buffer.read(cx).file().and_then(|f| f.as_local())
&& let Some(dir) = file.abs_path(cx).parent() {
return Some(dir.to_owned());
}
}
if let Some(project_path) = buffer.read(cx).project_path(cx) {
return Some(project_path.path.to_path_buf());
@ -18756,11 +18722,10 @@ impl Editor {
_window: &mut Window,
cx: &mut Context<Self>,
) {
if let Some(path) = self.target_file_abs_path(cx) {
if let Some(path) = path.to_str() {
if let Some(path) = self.target_file_abs_path(cx)
&& let Some(path) = path.to_str() {
cx.write_to_clipboard(ClipboardItem::new_string(path.to_string()));
}
}
}
pub fn copy_relative_path(
@ -18769,11 +18734,10 @@ impl Editor {
_window: &mut Window,
cx: &mut Context<Self>,
) {
if let Some(path) = self.target_file_path(cx) {
if let Some(path) = path.to_str() {
if let Some(path) = self.target_file_path(cx)
&& let Some(path) = path.to_str() {
cx.write_to_clipboard(ClipboardItem::new_string(path.to_string()));
}
}
}
pub fn project_path(&self, cx: &App) -> Option<ProjectPath> {
@ -18841,23 +18805,19 @@ impl Editor {
_: &mut Window,
cx: &mut Context<Self>,
) {
if let Some(file) = self.target_file(cx) {
if let Some(file_stem) = file.path().file_stem() {
if let Some(name) = file_stem.to_str() {
if let Some(file) = self.target_file(cx)
&& let Some(file_stem) = file.path().file_stem()
&& let Some(name) = file_stem.to_str() {
cx.write_to_clipboard(ClipboardItem::new_string(name.to_string()));
}
}
}
}
pub fn copy_file_name(&mut self, _: &CopyFileName, _: &mut Window, cx: &mut Context<Self>) {
if let Some(file) = self.target_file(cx) {
if let Some(file_name) = file.path().file_name() {
if let Some(name) = file_name.to_str() {
if let Some(file) = self.target_file(cx)
&& let Some(file_name) = file.path().file_name()
&& let Some(name) = file_name.to_str() {
cx.write_to_clipboard(ClipboardItem::new_string(name.to_string()));
}
}
}
}
pub fn toggle_git_blame(
@ -19126,11 +19086,10 @@ impl Editor {
cx: &mut Context<Self>,
) {
let selection = self.selections.newest::<Point>(cx).start.row + 1;
if let Some(file) = self.target_file(cx) {
if let Some(path) = file.path().to_str() {
if let Some(file) = self.target_file(cx)
&& let Some(path) = file.path().to_str() {
cx.write_to_clipboard(ClipboardItem::new_string(format!("{path}:{selection}")));
}
}
}
pub fn open_permalink_to_line(
@ -19769,11 +19728,10 @@ impl Editor {
break;
}
let end = range.end.to_point(&display_snapshot.buffer_snapshot);
if let Some(current_row) = &end_row {
if end.row == current_row.row {
if let Some(current_row) = &end_row
&& end.row == current_row.row {
continue;
}
}
let start = range.start.to_point(&display_snapshot.buffer_snapshot);
if start_row.is_none() {
assert_eq!(end_row, None);
@ -20064,8 +20022,8 @@ impl Editor {
if self.has_active_edit_prediction() {
self.update_visible_edit_prediction(window, cx);
}
if let Some(project) = self.project.as_ref() {
if let Some(edited_buffer) = edited_buffer {
if let Some(project) = self.project.as_ref()
&& let Some(edited_buffer) = edited_buffer {
project.update(cx, |project, cx| {
self.registered_buffers
.entry(edited_buffer.read(cx).remote_id())
@ -20074,7 +20032,6 @@ impl Editor {
});
});
}
}
cx.emit(EditorEvent::BufferEdited);
cx.emit(SearchEvent::MatchesInvalidated);
@ -20083,11 +20040,10 @@ impl Editor {
}
if *singleton_buffer_edited {
if let Some(buffer) = edited_buffer {
if buffer.read(cx).file().is_none() {
if let Some(buffer) = edited_buffer
&& buffer.read(cx).file().is_none() {
cx.emit(EditorEvent::TitleChanged);
}
}
if let Some(project) = &self.project {
#[allow(clippy::mutable_key_type)]
let languages_affected = multibuffer.update(cx, |multibuffer, cx| {
@ -20132,8 +20088,8 @@ impl Editor {
} => {
self.tasks_update_task = Some(self.refresh_runnables(window, cx));
let buffer_id = buffer.read(cx).remote_id();
if self.buffer.read(cx).diff_for(buffer_id).is_none() {
if let Some(project) = &self.project {
if self.buffer.read(cx).diff_for(buffer_id).is_none()
&& let Some(project) = &self.project {
update_uncommitted_diff_for_buffer(
cx.entity(),
project,
@ -20143,7 +20099,6 @@ impl Editor {
)
.detach();
}
}
self.update_lsp_data(false, Some(buffer_id), window, cx);
cx.emit(EditorEvent::ExcerptsAdded {
buffer: buffer.clone(),
@ -20746,12 +20701,11 @@ impl Editor {
let mut chunk_lines = chunk.text.split('\n').peekable();
while let Some(text) = chunk_lines.next() {
let mut merged_with_last_token = false;
if let Some(last_token) = line.back_mut() {
if last_token.highlight == highlight {
if let Some(last_token) = line.back_mut()
&& last_token.highlight == highlight {
last_token.text.push_str(text);
merged_with_last_token = true;
}
}
if !merged_with_last_token {
line.push_back(Chunk {
@ -21209,8 +21163,8 @@ impl Editor {
{
let buffer_snapshot = OnceCell::new();
if let Some(folds) = DB.get_editor_folds(item_id, workspace_id).log_err() {
if !folds.is_empty() {
if let Some(folds) = DB.get_editor_folds(item_id, workspace_id).log_err()
&& !folds.is_empty() {
let snapshot =
buffer_snapshot.get_or_init(|| self.buffer.read(cx).snapshot(cx));
self.fold_ranges(
@ -21226,10 +21180,9 @@ impl Editor {
cx,
);
}
}
if let Some(selections) = DB.get_editor_selections(item_id, workspace_id).log_err() {
if !selections.is_empty() {
if let Some(selections) = DB.get_editor_selections(item_id, workspace_id).log_err()
&& !selections.is_empty() {
let snapshot =
buffer_snapshot.get_or_init(|| self.buffer.read(cx).snapshot(cx));
// skip adding the initial selection to selection history
@ -21241,8 +21194,7 @@ impl Editor {
}));
});
self.selection_history.mode = SelectionHistoryMode::Normal;
}
};
};
}
self.read_scroll_position_from_db(item_id, workspace_id, window, cx);
@ -21283,18 +21235,15 @@ fn process_completion_for_edit(
let mut snippet_source = completion.new_text.clone();
let mut previous_point = text::ToPoint::to_point(cursor_position, buffer);
previous_point.column = previous_point.column.saturating_sub(1);
if let Some(scope) = buffer_snapshot.language_scope_at(previous_point) {
if scope.prefers_label_for_snippet_in_completion() {
if let Some(label) = completion.label() {
if matches!(
if let Some(scope) = buffer_snapshot.language_scope_at(previous_point)
&& scope.prefers_label_for_snippet_in_completion()
&& let Some(label) = completion.label()
&& matches!(
completion.kind(),
Some(CompletionItemKind::FUNCTION) | Some(CompletionItemKind::METHOD)
) {
snippet_source = label;
}
}
}
}
match Snippet::parse(&snippet_source).log_err() {
Some(parsed_snippet) => (Some(parsed_snippet.clone()), parsed_snippet.text),
None => (None, completion.new_text.clone()),
@ -21347,11 +21296,10 @@ fn process_completion_for_edit(
);
let mut current_needle = text_to_replace.next();
for haystack_ch in completion.label.text.chars() {
if let Some(needle_ch) = current_needle {
if haystack_ch.eq_ignore_ascii_case(&needle_ch) {
if let Some(needle_ch) = current_needle
&& haystack_ch.eq_ignore_ascii_case(&needle_ch) {
current_needle = text_to_replace.next();
}
}
}
current_needle.is_none()
}
@ -21604,12 +21552,11 @@ impl<'a> Iterator for WordBreakingTokenizer<'a> {
offset += first_grapheme.len();
grapheme_len += 1;
if is_grapheme_ideographic(first_grapheme) && !is_whitespace {
if let Some(grapheme) = iter.peek().copied() {
if should_stay_with_preceding_ideograph(grapheme) {
if let Some(grapheme) = iter.peek().copied()
&& should_stay_with_preceding_ideograph(grapheme) {
offset += grapheme.len();
grapheme_len += 1;
}
}
} else {
let mut words = self.input[offset..].split_word_bound_indices().peekable();
let mut next_word_bound = words.peek().copied();

View file

@ -916,8 +916,7 @@ impl EditorElement {
cx.stop_propagation();
} else if cfg!(any(target_os = "linux", target_os = "freebsd"))
&& event.button == MouseButton::Middle
{
if !text_hitbox.is_hovered(window) || editor.read_only(cx) {
&& (!text_hitbox.is_hovered(window) || editor.read_only(cx)) {
return;
}
@ -940,7 +939,6 @@ impl EditorElement {
}
cx.stop_propagation()
}
}
}
fn click(
@ -1387,8 +1385,7 @@ impl EditorElement {
ref drop_cursor,
ref hide_drop_cursor,
} = editor.selection_drag_state
{
if !hide_drop_cursor
&& !hide_drop_cursor
&& (drop_cursor
.start
.cmp(&selection.start, &snapshot.buffer_snapshot)
@ -1410,7 +1407,6 @@ impl EditorElement {
let absent_color = cx.theme().players().absent();
selections.push((absent_color, vec![drag_cursor_layout]));
}
}
}
if let Some(collaboration_hub) = &editor.collaboration_hub {
@ -1420,20 +1416,16 @@ impl EditorElement {
CollaboratorId::PeerId(peer_id) => {
if let Some(collaborator) =
collaboration_hub.collaborators(cx).get(&peer_id)
{
if let Some(participant_index) = collaboration_hub
&& let Some(participant_index) = collaboration_hub
.user_participant_indices(cx)
.get(&collaborator.user_id)
{
if let Some((local_selection_style, _)) = selections.first_mut()
&& let Some((local_selection_style, _)) = selections.first_mut()
{
*local_selection_style = cx
.theme()
.players()
.color_for_participant(participant_index.0);
}
}
}
}
CollaboratorId::Agent => {
if let Some((local_selection_style, _)) = selections.first_mut() {
@ -3518,10 +3510,10 @@ impl EditorElement {
let mut x_offset = px(0.);
let mut is_block = true;
if let BlockId::Custom(custom_block_id) = block_id {
if block.has_height() {
if block.place_near() {
if let Some((x_target, line_width)) = x_position {
if let BlockId::Custom(custom_block_id) = block_id
&& block.has_height() {
if block.place_near()
&& let Some((x_target, line_width)) = x_position {
let margin = em_width * 2;
if line_width + final_size.width + margin
< editor_width + editor_margins.gutter.full_width()
@ -3540,13 +3532,11 @@ impl EditorElement {
.max(editor_margins.gutter.full_width());
x_offset = x_target.min(max_offset).max(min_offset);
}
}
};
};
if element_height_in_lines != block.height() {
resized_blocks.insert(custom_block_id, element_height_in_lines);
}
}
}
for i in 0..element_height_in_lines {
row_block_types.insert(row + i, is_block);
}
@ -3987,10 +3977,10 @@ impl EditorElement {
}
}
if let Some(focused_block) = focused_block {
if let Some(focus_handle) = focused_block.focus_handle.upgrade() {
if focus_handle.is_focused(window) {
if let Some(block) = snapshot.block_for_id(focused_block.id) {
if let Some(focused_block) = focused_block
&& let Some(focus_handle) = focused_block.focus_handle.upgrade()
&& focus_handle.is_focused(window)
&& let Some(block) = snapshot.block_for_id(focused_block.id) {
let style = block.style();
let width = match style {
BlockStyle::Fixed => AvailableSpace::MinContent,
@ -4040,9 +4030,6 @@ impl EditorElement {
});
}
}
}
}
}
if resized_blocks.is_empty() {
*scroll_width =
@ -4203,8 +4190,8 @@ impl EditorElement {
edit_prediction_popover_visible = true;
}
if editor.context_menu_visible() {
if let Some(crate::ContextMenuOrigin::Cursor) = editor.context_menu_origin() {
if editor.context_menu_visible()
&& let Some(crate::ContextMenuOrigin::Cursor) = editor.context_menu_origin() {
let (min_height_in_lines, max_height_in_lines) = editor
.context_menu_options
.as_ref()
@ -4216,7 +4203,6 @@ impl EditorElement {
max_menu_height += line_height * max_height_in_lines as f32 + POPOVER_Y_PADDING;
context_menu_visible = true;
}
}
context_menu_placement = editor
.context_menu_options
.as_ref()
@ -5761,8 +5747,8 @@ impl EditorElement {
cx: &mut App,
) {
for (_, hunk_hitbox) in &layout.display_hunks {
if let Some(hunk_hitbox) = hunk_hitbox {
if !self
if let Some(hunk_hitbox) = hunk_hitbox
&& !self
.editor
.read(cx)
.buffer()
@ -5771,7 +5757,6 @@ impl EditorElement {
{
window.set_cursor_style(CursorStyle::PointingHand, hunk_hitbox);
}
}
}
let show_git_gutter = layout
@ -10152,11 +10137,10 @@ fn compute_auto_height_layout(
let overscroll = size(em_width, px(0.));
let editor_width = text_width - gutter_dimensions.margin - overscroll.width - em_width;
if !matches!(editor.soft_wrap_mode(cx), SoftWrap::None) {
if editor.set_wrap_width(Some(editor_width), cx) {
if !matches!(editor.soft_wrap_mode(cx), SoftWrap::None)
&& editor.set_wrap_width(Some(editor_width), cx) {
snapshot = editor.snapshot(window, cx);
}
}
let scroll_height = (snapshot.max_point().row().next_row().0 as f32) * line_height;

View file

@ -312,11 +312,10 @@ impl GitBlame {
.as_ref()
.and_then(|entry| entry.author.as_ref())
.map(|author| author.len());
if let Some(author_len) = author_len {
if author_len > max_author_length {
if let Some(author_len) = author_len
&& author_len > max_author_length {
max_author_length = author_len;
}
}
}
max_author_length
@ -416,8 +415,7 @@ impl GitBlame {
if row_edits
.peek()
.map_or(true, |next_edit| next_edit.old.start >= old_end)
{
if let Some(entry) = cursor.item() {
&& let Some(entry) = cursor.item() {
if old_end > edit.old.end {
new_entries.push(
GitBlameEntry {
@ -430,7 +428,6 @@ impl GitBlame {
cursor.next();
}
}
}
new_entries.append(cursor.suffix(), &());
drop(cursor);

View file

@ -418,8 +418,7 @@ pub fn update_inlay_link_and_hover_points(
}
if let Some((language_server_id, location)) =
hovered_hint_part.location
{
if secondary_held
&& secondary_held
&& !editor.has_pending_nonempty_selection()
{
go_to_definition_updated = true;
@ -436,7 +435,6 @@ pub fn update_inlay_link_and_hover_points(
cx,
);
}
}
}
}
};
@ -766,11 +764,10 @@ pub(crate) fn find_url_from_range(
let mut finder = LinkFinder::new();
finder.kinds(&[LinkKind::Url]);
if let Some(link) = finder.links(&text).next() {
if link.start() == 0 && link.end() == text.len() {
if let Some(link) = finder.links(&text).next()
&& link.start() == 0 && link.end() == text.len() {
return Some(link.as_str().to_string());
}
}
None
}

View file

@ -142,12 +142,11 @@ pub fn hover_at_inlay(
.info_popovers
.iter()
.any(|InfoPopover { symbol_range, .. }| {
if let RangeInEditor::Inlay(range) = symbol_range {
if range == &inlay_hover.range {
if let RangeInEditor::Inlay(range) = symbol_range
&& range == &inlay_hover.range {
// Hover triggered from same location as last time. Don't show again.
return true;
}
}
false
})
{
@ -270,14 +269,13 @@ fn show_hover(
}
// Don't request again if the location is the same as the previous request
if let Some(triggered_from) = &editor.hover_state.triggered_from {
if triggered_from
if let Some(triggered_from) = &editor.hover_state.triggered_from
&& triggered_from
.cmp(&anchor, &snapshot.buffer_snapshot)
.is_eq()
{
return None;
}
}
let hover_popover_delay = EditorSettings::get_global(cx).hover_popover_delay;
let all_diagnostics_active = editor.active_diagnostics == ActiveDiagnostic::All;
@ -717,9 +715,9 @@ pub fn diagnostics_markdown_style(window: &Window, cx: &App) -> MarkdownStyle {
}
pub fn open_markdown_url(link: SharedString, window: &mut Window, cx: &mut App) {
if let Ok(uri) = Url::parse(&link) {
if uri.scheme() == "file" {
if let Some(workspace) = window.root::<Workspace>().flatten() {
if let Ok(uri) = Url::parse(&link)
&& uri.scheme() == "file"
&& let Some(workspace) = window.root::<Workspace>().flatten() {
workspace.update(cx, |workspace, cx| {
let task = workspace.open_abs_path(
PathBuf::from(uri.path()),
@ -769,8 +767,6 @@ pub fn open_markdown_url(link: SharedString, window: &mut Window, cx: &mut App)
});
return;
}
}
}
cx.open_url(&link);
}
@ -839,21 +835,19 @@ impl HoverState {
pub fn focused(&self, window: &mut Window, cx: &mut Context<Editor>) -> bool {
let mut hover_popover_is_focused = false;
for info_popover in &self.info_popovers {
if let Some(markdown_view) = &info_popover.parsed_content {
if markdown_view.focus_handle(cx).is_focused(window) {
if let Some(markdown_view) = &info_popover.parsed_content
&& markdown_view.focus_handle(cx).is_focused(window) {
hover_popover_is_focused = true;
}
}
}
if let Some(diagnostic_popover) = &self.diagnostic_popover {
if diagnostic_popover
if let Some(diagnostic_popover) = &self.diagnostic_popover
&& diagnostic_popover
.markdown
.focus_handle(cx)
.is_focused(window)
{
hover_popover_is_focused = true;
}
}
hover_popover_is_focused
}
}

View file

@ -168,12 +168,11 @@ pub fn indent_guides_in_range(
while let Some(fold) = folds.next() {
let start = fold.range.start.to_point(&snapshot.buffer_snapshot);
let end = fold.range.end.to_point(&snapshot.buffer_snapshot);
if let Some(last_range) = fold_ranges.last_mut() {
if last_range.end >= start {
if let Some(last_range) = fold_ranges.last_mut()
&& last_range.end >= start {
last_range.end = last_range.end.max(end);
continue;
}
}
fold_ranges.push(start..end);
}

View file

@ -498,8 +498,7 @@ impl InlayHintCache {
cmp::Ordering::Less | cmp::Ordering::Equal => {
if !old_kinds.contains(&cached_hint.kind)
&& new_kinds.contains(&cached_hint.kind)
{
if let Some(anchor) = multi_buffer_snapshot
&& let Some(anchor) = multi_buffer_snapshot
.anchor_in_excerpt(*excerpt_id, cached_hint.position)
{
to_insert.push(Inlay::hint(
@ -508,7 +507,6 @@ impl InlayHintCache {
cached_hint,
));
}
}
excerpt_cache.next();
}
cmp::Ordering::Greater => return true,
@ -522,8 +520,8 @@ impl InlayHintCache {
for cached_hint_id in excerpt_cache {
let maybe_missed_cached_hint = &excerpt_cached_hints.hints_by_id[cached_hint_id];
let cached_hint_kind = maybe_missed_cached_hint.kind;
if !old_kinds.contains(&cached_hint_kind) && new_kinds.contains(&cached_hint_kind) {
if let Some(anchor) = multi_buffer_snapshot
if !old_kinds.contains(&cached_hint_kind) && new_kinds.contains(&cached_hint_kind)
&& let Some(anchor) = multi_buffer_snapshot
.anchor_in_excerpt(*excerpt_id, maybe_missed_cached_hint.position)
{
to_insert.push(Inlay::hint(
@ -532,7 +530,6 @@ impl InlayHintCache {
maybe_missed_cached_hint,
));
}
}
}
}
@ -620,8 +617,8 @@ impl InlayHintCache {
) {
if let Some(excerpt_hints) = self.hints.get(&excerpt_id) {
let mut guard = excerpt_hints.write();
if let Some(cached_hint) = guard.hints_by_id.get_mut(&id) {
if let ResolveState::CanResolve(server_id, _) = &cached_hint.resolve_state {
if let Some(cached_hint) = guard.hints_by_id.get_mut(&id)
&& let ResolveState::CanResolve(server_id, _) = &cached_hint.resolve_state {
let hint_to_resolve = cached_hint.clone();
let server_id = *server_id;
cached_hint.resolve_state = ResolveState::Resolving;
@ -644,12 +641,11 @@ impl InlayHintCache {
editor.inlay_hint_cache.hints.get(&excerpt_id)
{
let mut guard = excerpt_hints.write();
if let Some(cached_hint) = guard.hints_by_id.get_mut(&id) {
if cached_hint.resolve_state == ResolveState::Resolving {
if let Some(cached_hint) = guard.hints_by_id.get_mut(&id)
&& cached_hint.resolve_state == ResolveState::Resolving {
resolved_hint.resolve_state = ResolveState::Resolved;
*cached_hint = resolved_hint;
}
}
}
})?;
}
@ -658,7 +654,6 @@ impl InlayHintCache {
})
.detach_and_log_err(cx);
}
}
}
}
}
@ -990,8 +985,8 @@ fn fetch_and_update_hints(
let buffer = editor.buffer().read(cx).buffer(query.buffer_id)?;
if !editor.registered_buffers.contains_key(&query.buffer_id) {
if let Some(project) = editor.project.as_ref() {
if !editor.registered_buffers.contains_key(&query.buffer_id)
&& let Some(project) = editor.project.as_ref() {
project.update(cx, |project, cx| {
editor.registered_buffers.insert(
query.buffer_id,
@ -999,7 +994,6 @@ fn fetch_and_update_hints(
);
})
}
}
editor
.semantics_provider
@ -1240,15 +1234,13 @@ fn apply_hint_update(
.inlay_hint_cache
.allowed_hint_kinds
.contains(&new_hint.kind)
{
if let Some(new_hint_position) =
&& let Some(new_hint_position) =
multi_buffer_snapshot.anchor_in_excerpt(query.excerpt_id, new_hint.position)
{
splice
.to_insert
.push(Inlay::hint(new_inlay_id, new_hint_position, &new_hint));
}
}
let new_id = InlayId::Hint(new_inlay_id);
cached_excerpt_hints.hints_by_id.insert(new_id, new_hint);
if cached_excerpt_hints.ordered_hints.len() <= insert_position {

View file

@ -930,11 +930,10 @@ impl Item for Editor {
})?;
buffer
.update(cx, |buffer, cx| {
if let Some(transaction) = transaction {
if !buffer.is_singleton() {
if let Some(transaction) = transaction
&& !buffer.is_singleton() {
buffer.push_transaction(&transaction.0, cx);
}
}
})
.ok();
Ok(())
@ -1374,9 +1373,8 @@ impl ProjectItem for Editor {
let mut editor = Self::for_buffer(buffer.clone(), Some(project), window, cx);
if let Some((excerpt_id, buffer_id, snapshot)) =
editor.buffer().read(cx).snapshot(cx).as_singleton()
{
if WorkspaceSettings::get(None, cx).restore_on_file_reopen {
if let Some(restoration_data) = Self::project_item_kind()
&& WorkspaceSettings::get(None, cx).restore_on_file_reopen
&& let Some(restoration_data) = Self::project_item_kind()
.and_then(|kind| pane.as_ref()?.project_item_restoration_data.get(&kind))
.and_then(|data| data.downcast_ref::<EditorRestorationData>())
.and_then(|data| {
@ -1403,8 +1401,6 @@ impl ProjectItem for Editor {
);
editor.set_scroll_anchor(ScrollAnchor { anchor, offset }, window, cx);
}
}
}
editor
}

View file

@ -51,13 +51,11 @@ pub(crate) fn should_auto_close(
continue;
};
let mut jsx_open_tag_node = node;
if node.grammar_name() != config.open_tag_node_name {
if let Some(parent) = node.parent() {
if parent.grammar_name() == config.open_tag_node_name {
if node.grammar_name() != config.open_tag_node_name
&& let Some(parent) = node.parent()
&& parent.grammar_name() == config.open_tag_node_name {
jsx_open_tag_node = parent;
}
}
}
if jsx_open_tag_node.grammar_name() != config.open_tag_node_name {
continue;
}
@ -284,11 +282,10 @@ pub(crate) fn generate_auto_close_edits(
unclosed_open_tag_count -= 1;
}
} else if has_erroneous_close_tag && kind == erroneous_close_tag_node_name {
if tag_node_name_equals(&node, &tag_name) {
if !is_after_open_tag(&node) {
if tag_node_name_equals(&node, &tag_name)
&& !is_after_open_tag(&node) {
unclosed_open_tag_count -= 1;
}
}
} else if kind == config.jsx_element_node_name {
// perf: filter only open,close,element,erroneous nodes
stack.extend(node.children(&mut cursor));

View file

@ -147,8 +147,8 @@ pub fn lsp_tasks(
},
cx,
)
}) {
if let Some(new_runnables) = runnables_task.await.log_err() {
})
&& let Some(new_runnables) = runnables_task.await.log_err() {
new_lsp_tasks.extend(new_runnables.runnables.into_iter().filter_map(
|(location, runnable)| {
let resolved_task =
@ -157,7 +157,6 @@ pub fn lsp_tasks(
},
));
}
}
lsp_tasks
.entry(source_kind)
.or_insert_with(Vec::new)

View file

@ -510,11 +510,10 @@ pub fn find_preceding_boundary_point(
if find_range == FindRange::SingleLine && ch == '\n' {
break;
}
if let Some(prev_ch) = prev_ch {
if is_boundary(ch, prev_ch) {
if let Some(prev_ch) = prev_ch
&& is_boundary(ch, prev_ch) {
break;
}
}
offset -= ch.len_utf8();
prev_ch = Some(ch);
@ -562,15 +561,14 @@ pub fn find_boundary_point(
if find_range == FindRange::SingleLine && ch == '\n' {
break;
}
if let Some(prev_ch) = prev_ch {
if is_boundary(prev_ch, ch) {
if let Some(prev_ch) = prev_ch
&& is_boundary(prev_ch, ch) {
if return_point_before_boundary {
return map.clip_point(prev_offset.to_display_point(map), Bias::Right);
} else {
break;
}
}
}
prev_offset = offset;
offset += ch.len_utf8();
prev_ch = Some(ch);
@ -603,15 +601,14 @@ pub fn find_preceding_boundary_trail(
// Find the boundary
let start_offset = offset;
for ch in forward {
if let Some(prev_ch) = prev_ch {
if is_boundary(prev_ch, ch) {
if let Some(prev_ch) = prev_ch
&& is_boundary(prev_ch, ch) {
if start_offset == offset {
trail_offset = Some(offset);
} else {
break;
}
}
}
offset -= ch.len_utf8();
prev_ch = Some(ch);
}
@ -651,15 +648,14 @@ pub fn find_boundary_trail(
// Find the boundary
let start_offset = offset;
for ch in forward {
if let Some(prev_ch) = prev_ch {
if is_boundary(prev_ch, ch) {
if let Some(prev_ch) = prev_ch
&& is_boundary(prev_ch, ch) {
if start_offset == offset {
trail_offset = Some(offset);
} else {
break;
}
}
}
offset += ch.len_utf8();
prev_ch = Some(ch);
}

View file

@ -285,12 +285,11 @@ pub fn open_docs(editor: &mut Editor, _: &OpenDocs, window: &mut Window, cx: &mu
workspace.update(cx, |_workspace, cx| {
// Check if the local document exists, otherwise fallback to the online document.
// Open with the default browser.
if let Some(local_url) = docs_urls.local {
if fs::metadata(Path::new(&local_url[8..])).is_ok() {
if let Some(local_url) = docs_urls.local
&& fs::metadata(Path::new(&local_url[8..])).is_ok() {
cx.open_url(&local_url);
return;
}
}
if let Some(web_url) = docs_urls.web {
cx.open_url(&web_url);

View file

@ -703,21 +703,19 @@ impl Editor {
if matches!(
settings.defaults.soft_wrap,
SoftWrap::PreferredLineLength | SoftWrap::Bounded
) {
if (settings.defaults.preferred_line_length as f32) < visible_column_count {
)
&& (settings.defaults.preferred_line_length as f32) < visible_column_count {
visible_column_count = settings.defaults.preferred_line_length as f32;
}
}
// If the scroll position is currently at the left edge of the document
// (x == 0.0) and the intent is to scroll right, the gutter's margin
// should first be added to the current position, otherwise the cursor
// will end at the column position minus the margin, which looks off.
if current_position.x == 0.0 && amount.columns(visible_column_count) > 0. {
if let Some(last_position_map) = &self.last_position_map {
if current_position.x == 0.0 && amount.columns(visible_column_count) > 0.
&& let Some(last_position_map) = &self.last_position_map {
current_position.x += self.gutter_dimensions.margin / last_position_map.em_advance;
}
}
let new_position = current_position
+ point(
amount.columns(visible_column_count),
@ -749,13 +747,11 @@ impl Editor {
if let (Some(visible_lines), Some(visible_columns)) =
(self.visible_line_count(), self.visible_column_count())
{
if newest_head.row() <= DisplayRow(screen_top.row().0 + visible_lines as u32)
&& newest_head.row() <= DisplayRow(screen_top.row().0 + visible_lines as u32)
&& newest_head.column() <= screen_top.column() + visible_columns as u32
{
return Ordering::Equal;
}
}
Ordering::Greater
}

View file

@ -116,14 +116,13 @@ impl Editor {
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
let mut scroll_position = self.scroll_manager.scroll_position(&display_map);
let original_y = scroll_position.y;
if let Some(last_bounds) = self.expect_bounds_change.take() {
if scroll_position.y != 0. {
if let Some(last_bounds) = self.expect_bounds_change.take()
&& scroll_position.y != 0. {
scroll_position.y += (bounds.top() - last_bounds.top()) / line_height;
if scroll_position.y < 0. {
scroll_position.y = 0.;
}
}
}
if scroll_position.y > max_scroll_top {
scroll_position.y = max_scroll_top;
}

View file

@ -184,11 +184,10 @@ pub fn editor_content_with_blocks(editor: &Entity<Editor>, cx: &mut VisualTestCo
for (row, block) in blocks {
match block {
Block::Custom(custom_block) => {
if let BlockPlacement::Near(x) = &custom_block.placement {
if snapshot.intersects_fold(x.to_point(&snapshot.buffer_snapshot)) {
if let BlockPlacement::Near(x) = &custom_block.placement
&& snapshot.intersects_fold(x.to_point(&snapshot.buffer_snapshot)) {
continue;
}
};
};
let content = block_content_for_tests(editor, custom_block.id, cx)
.expect("block content not found");
// 2: "related info 1 for diagnostic 0"