Skip to content

Commit

Permalink
Merge branch 'main' into setting-store
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunsfeld committed May 17, 2023
2 parents 67a2512 + 5ef0399 commit 1f0e79e
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 41 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
runs-on:
- self-hosted
- test
needs: rustfmt
env:
RUSTFLAGS: -D warnings
steps:
Expand Down
66 changes: 31 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions assets/settings/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@
// 3. Draw all invisible symbols:
// "all"
"show_whitespaces": "selection",
// Whether to show the scrollbar in the editor.
// This setting can take four values:
//
// 1. Show the scrollbar if there's important information or
// follow the system's configured behavior (default):
// "auto"
// 2. Match the system's configured behavior:
// "system"
// 3. Always show the scrollbar:
// "always"
// 4. Never show the scrollbar:
// "never"
"show_scrollbars": "auto",
// Whether the screen sharing icon is shown in the os status bar.
"show_call_status_icon": true,
// Whether to use language servers to provide code intelligence.
Expand Down
9 changes: 9 additions & 0 deletions crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,15 @@ pub struct EditorSnapshot {
ongoing_scroll: OngoingScroll,
}

impl EditorSnapshot {
fn has_scrollbar_info(&self) -> bool {
self.buffer_snapshot
.git_diff_hunks_in_range(0..self.max_point().row(), false)
.next()
.is_some()
}
}

#[derive(Clone, Debug)]
struct SelectionHistoryEntry {
selections: Arc<[Selection<Anchor>]>,
Expand Down
12 changes: 12 additions & 0 deletions crates/editor/src/editor_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,25 @@ pub struct EditorSettings {
pub cursor_blink: bool,
pub hover_popover_enabled: bool,
pub show_completions_on_input: bool,
pub show_scrollbars: ShowScrollbars,
}

#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq, Default)]
#[serde(rename_all = "snake_case")]
pub enum ShowScrollbars {
#[default]
Auto,
System,
Always,
Never,
}

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
pub struct EditorSettingsContent {
pub cursor_blink: Option<bool>,
pub hover_popover_enabled: Option<bool>,
pub show_completions_on_input: Option<bool>,
pub show_scrollbars: Option<ShowScrollbars>,
}

impl Setting for EditorSettings {
Expand Down
63 changes: 59 additions & 4 deletions crates/editor/src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use super::{
};
use crate::{
display_map::{BlockStyle, DisplaySnapshot, FoldStatus, TransformBlock},
editor_settings::ShowScrollbars,
git::{diff_hunk_to_display, DisplayDiffHunk},
hover_popover::{
hide_hover, hover_at, HOVER_POPOVER_GAP, MIN_POPOVER_CHARACTER_WIDTH,
Expand All @@ -13,7 +14,7 @@ use crate::{
link_go_to_definition::{
go_to_fetched_definition, go_to_fetched_type_definition, update_go_to_definition_link,
},
mouse_context_menu, EditorStyle, GutterHover, UnfoldAt,
mouse_context_menu, EditorSettings, EditorStyle, GutterHover, UnfoldAt,
};
use clock::ReplicaId;
use collections::{BTreeMap, HashMap};
Expand Down Expand Up @@ -1026,15 +1027,16 @@ impl EditorElement {
let mut first_row_y_offset = 0.0;

// Impose a minimum height on the scrollbar thumb
let row_height = height / max_row;
let min_thumb_height =
style.min_height_factor * cx.font_cache.line_height(self.style.text.font_size);
let thumb_height = (row_range.end - row_range.start) * height / max_row;
let thumb_height = (row_range.end - row_range.start) * row_height;
if thumb_height < min_thumb_height {
first_row_y_offset = (min_thumb_height - thumb_height) / 2.0;
height -= min_thumb_height - thumb_height;
}

let y_for_row = |row: f32| -> f32 { top + first_row_y_offset + row * height / max_row };
let y_for_row = |row: f32| -> f32 { top + first_row_y_offset + row * row_height };

let thumb_top = y_for_row(row_range.start) - first_row_y_offset;
let thumb_bottom = y_for_row(row_range.end) + first_row_y_offset;
Expand All @@ -1048,6 +1050,50 @@ impl EditorElement {
background: style.track.background_color,
..Default::default()
});

let diff_style = theme::current(cx).editor.diff.clone();
for hunk in layout
.position_map
.snapshot
.buffer_snapshot
.git_diff_hunks_in_range(0..(max_row.floor() as u32), false)
{
let start_y = y_for_row(hunk.buffer_range.start as f32);
let mut end_y = if hunk.buffer_range.start == hunk.buffer_range.end {
y_for_row((hunk.buffer_range.end + 1) as f32)
} else {
y_for_row((hunk.buffer_range.end) as f32)
};

if end_y - start_y < 1. {
end_y = start_y + 1.;
}
let bounds = RectF::from_points(vec2f(left, start_y), vec2f(right, end_y));

let color = match hunk.status() {
DiffHunkStatus::Added => diff_style.inserted,
DiffHunkStatus::Modified => diff_style.modified,
DiffHunkStatus::Removed => diff_style.deleted,
};

let border = Border {
width: 1.,
color: style.thumb.border.color,
overlay: false,
top: false,
right: true,
bottom: false,
left: true,
};

scene.push_quad(Quad {
bounds,
background: Some(color),
border,
corner_radius: style.thumb.corner_radius,
})
}

scene.push_quad(Quad {
bounds: thumb_bounds,
border: style.thumb.border,
Expand Down Expand Up @@ -2014,7 +2060,16 @@ impl Element<Editor> for EditorElement {
));
}

let show_scrollbars = editor.scroll_manager.scrollbars_visible();
let show_scrollbars =
match settings::get_setting::<EditorSettings>(None, cx).show_scrollbars {
ShowScrollbars::Auto => {
snapshot.has_scrollbar_info() || editor.scroll_manager.scrollbars_visible()
}
ShowScrollbars::System => editor.scroll_manager.scrollbars_visible(),
ShowScrollbars::Always => true,
ShowScrollbars::Never => false,
};

let include_root = editor
.project
.as_ref()
Expand Down
2 changes: 1 addition & 1 deletion crates/gpui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ cocoa = "0.24"
core-foundation = { version = "0.9.3", features = ["with-uuid"] }
core-graphics = "0.22.3"
core-text = "19.2"
font-kit = { git = "https://github.com/zed-industries/font-kit", rev = "8eaf7a918eafa28b0a37dc759e2e0e7683fa24f1" }
font-kit = { git = "https://github.com/zed-industries/font-kit", rev = "b2f77d56f450338aa4f7dd2f0197d8c9acb0cf18" }
foreign-types = "0.3"
log.workspace = true
metal = "0.21.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/zed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ authors = ["Nathan Sobo <nathansobo@gmail.com>"]
description = "The fast, collaborative code editor."
edition = "2021"
name = "zed"
version = "0.87.0"
version = "0.88.0"
publish = false

[lib]
Expand Down

0 comments on commit 1f0e79e

Please sign in to comment.