editor: rename code/diff view features and modules

This commit is contained in:
2026-11-11 09:11:23 +07:00
parent 6d6861a766
commit 63ed15c9cb
10 changed files with 34 additions and 34 deletions
+6 -6
View File
@@ -27,21 +27,21 @@ gpui = { workspace = true, features = ["test-support"] }
[features]
default = ["full"]
full = [
"code_view",
"diff_view",
"markdown_view",
"code",
"diff",
"markdown",
"rust",
"typescript",
"javascript",
"python",
]
code_view = [
code = [
"dep:gpui-native-core",
"gpui-native-core/scroll_area",
"gpui-native-core/scrollbar",
]
diff_view = ["code_view"]
markdown_view = [
diff = ["code"]
markdown = [
"dep:gpui-native-core",
"gpui-native-core/button",
"gpui-native-core/checkbox",
+5 -5
View File
@@ -2,13 +2,13 @@
//! code views, one cargo feature per language grammar. A language whose
//! grammar feature is off renders as plain text.
#[cfg(feature = "code_view")]
pub mod code_view;
#[cfg(feature = "code")]
pub mod code;
#[cfg(feature = "diff_view")]
pub mod diff_view;
#[cfg(feature = "diff")]
pub mod diff;
#[cfg(feature = "markdown_view")]
#[cfg(feature = "markdown")]
pub mod markdown;
pub mod highlight;
+14 -14
View File
@@ -1,24 +1,24 @@
//! Shared helpers for the editor's views: gutter cells, role colors and run
//! styles, code line text, language mapping and change washes.
#[cfg(any(feature = "code_view", feature = "markdown_view"))]
#[cfg(any(feature = "code", feature = "markdown"))]
use std::ops::Range;
#[cfg(feature = "markdown_view")]
#[cfg(feature = "markdown")]
use crate::highlight::{Language, Line};
#[cfg(feature = "markdown_view")]
#[cfg(feature = "markdown")]
use gpui::StyledText;
#[cfg(any(feature = "code_view", feature = "markdown_view"))]
#[cfg(any(feature = "code", feature = "markdown"))]
use gpui::{App, HighlightStyle, Hsla, IntoElement, ParentElement as _, Styled as _, div};
#[cfg(any(feature = "code_view", feature = "markdown_view"))]
#[cfg(any(feature = "code", feature = "markdown"))]
use gpui_native_theme::{ActiveTheme as _, ColorTokens, Ramps};
#[cfg(feature = "diff_view")]
#[cfg(feature = "diff")]
use gpui_native_theme::{WASH_ALPHA, WASH_ALPHA_GUTTER, WASH_ALPHA_STRONG};
#[cfg(any(feature = "code_view", feature = "markdown_view"))]
#[cfg(any(feature = "code", feature = "markdown"))]
use crate::highlight::Role;
#[cfg(any(feature = "code_view", feature = "markdown_view"))]
#[cfg(any(feature = "code", feature = "markdown"))]
impl Role {
/// Maps the role to the theme's semantic palette.
pub(crate) fn color(self, colors: ColorTokens, ramps: Ramps) -> Hsla {
@@ -50,7 +50,7 @@ impl Role {
}
}
#[cfg(feature = "markdown_view")]
#[cfg(feature = "markdown")]
impl Language {
/// Maps a fence info string to a bundled grammar.
pub(crate) fn from_fence_info(info: &str) -> Option<Language> {
@@ -65,7 +65,7 @@ impl Language {
}
/// A gutter cell sized to the whole row.
#[cfg(feature = "code_view")]
#[cfg(feature = "code")]
pub(crate) fn gutter_cell<E>(cx: &App, color: Hsla, content: E) -> gpui::Div
where
E: IntoElement,
@@ -86,7 +86,7 @@ where
}
/// A change wash: the ramp color at the alpha rows tint with.
#[cfg(feature = "diff_view")]
#[cfg(feature = "diff")]
pub(crate) fn wash(color: Hsla) -> Hsla {
Hsla {
a: color.a * WASH_ALPHA,
@@ -95,7 +95,7 @@ pub(crate) fn wash(color: Hsla) -> Hsla {
}
/// The stronger wash under number gutters and intra-line word changes.
#[cfg(feature = "diff_view")]
#[cfg(feature = "diff")]
pub(crate) fn wash_strong(color: Hsla) -> Hsla {
Hsla {
a: color.a * WASH_ALPHA_STRONG,
@@ -104,7 +104,7 @@ pub(crate) fn wash_strong(color: Hsla) -> Hsla {
}
/// The subtle wash that sets the number gutter off from the code.
#[cfg(feature = "diff_view")]
#[cfg(feature = "diff")]
pub(crate) fn wash_gutter(colors: &ColorTokens) -> Hsla {
Hsla {
a: colors.muted.a * WASH_ALPHA_GUTTER,
@@ -113,7 +113,7 @@ pub(crate) fn wash_gutter(colors: &ColorTokens) -> Hsla {
}
/// One highlighted code line as styled text, roles resolved from the theme.
#[cfg(feature = "markdown_view")]
#[cfg(feature = "markdown")]
pub(crate) fn code_line(line: &Line, colors: ColorTokens, ramps: Ramps) -> StyledText {
let mut highlights: Vec<(Range<usize>, HighlightStyle)> = Vec::new();
let mut offset = 0usize;
@@ -5,7 +5,7 @@ use gpui::{
AppContext as _, Context, Entity, Focusable as _, IntoElement, ParentElement as _, Render,
Styled as _, TestAppContext, VisualTestContext, Window, div,
};
use gpui_native_editor::code_view::{CodeViewState, bind_code_view_keys};
use gpui_native_editor::code::{CodeViewState, bind_code_view_keys};
use gpui_native_editor::highlight::{HighlightedCode, Language, Role, highlight};
fn spans_with_role(code: &HighlightedCode, role: Role) -> Vec<&str> {
@@ -176,8 +176,8 @@ fn selecting_then_copying_writes_the_clipboard() {
cx.update(|cx| {
state.update(cx, |state, cx| {
state.select_range(
gpui_native_editor::code_view::SelectionPoint { row: 0, col: 0 },
gpui_native_editor::code_view::SelectionPoint { row: 0, col: 3 },
gpui_native_editor::code::SelectionPoint { row: 0, col: 0 },
gpui_native_editor::code::SelectionPoint { row: 0, col: 3 },
cx,
);
});
@@ -8,7 +8,7 @@ use gpui::{
ScrollDelta, ScrollEvent, Styled as _, TestAppContext, VisualTestContext, Window, div, point,
px,
};
use gpui_native_editor::code_view::{CodeViewState, bind_code_view_keys};
use gpui_native_editor::code::{CodeViewState, bind_code_view_keys};
use gpui_native_editor::highlight::Language;
/// Deterministic pseudo-Rust with mixed tokens, roughly `lines` lines long.
@@ -5,7 +5,7 @@ use gpui::{
AppContext as _, Context, Entity, IntoElement, MouseButton, ParentElement as _, Render,
Styled as _, TestAppContext, VisualTestContext, Window, div, point, px,
};
use gpui_native_editor::diff_view::{DiffRow, DiffRowKind, DiffViewState};
use gpui_native_editor::diff::{DiffRow, DiffRowKind, DiffViewState};
use gpui_native_editor::highlight::{Language, Role};
const OLD: &str = "fn a() {}\nfn b() {}\nfn c() {}\n";
@@ -8,7 +8,7 @@ use gpui::{
ScrollDelta, ScrollEvent, Styled as _, TestAppContext, VisualTestContext, Window, div, point,
px,
};
use gpui_native_editor::diff_view::DiffViewState;
use gpui_native_editor::diff::DiffViewState;
/// Deterministic old/new pairs of roughly `lines` lines each, with changes
/// sprinkled through.