editor: rename code/diff view features and modules
This commit is contained in:
@@ -27,21 +27,21 @@ gpui = { workspace = true, features = ["test-support"] }
|
|||||||
[features]
|
[features]
|
||||||
default = ["full"]
|
default = ["full"]
|
||||||
full = [
|
full = [
|
||||||
"code_view",
|
"code",
|
||||||
"diff_view",
|
"diff",
|
||||||
"markdown_view",
|
"markdown",
|
||||||
"rust",
|
"rust",
|
||||||
"typescript",
|
"typescript",
|
||||||
"javascript",
|
"javascript",
|
||||||
"python",
|
"python",
|
||||||
]
|
]
|
||||||
code_view = [
|
code = [
|
||||||
"dep:gpui-native-core",
|
"dep:gpui-native-core",
|
||||||
"gpui-native-core/scroll_area",
|
"gpui-native-core/scroll_area",
|
||||||
"gpui-native-core/scrollbar",
|
"gpui-native-core/scrollbar",
|
||||||
]
|
]
|
||||||
diff_view = ["code_view"]
|
diff = ["code"]
|
||||||
markdown_view = [
|
markdown = [
|
||||||
"dep:gpui-native-core",
|
"dep:gpui-native-core",
|
||||||
"gpui-native-core/button",
|
"gpui-native-core/button",
|
||||||
"gpui-native-core/checkbox",
|
"gpui-native-core/checkbox",
|
||||||
|
|||||||
@@ -2,13 +2,13 @@
|
|||||||
//! code views, one cargo feature per language grammar. A language whose
|
//! code views, one cargo feature per language grammar. A language whose
|
||||||
//! grammar feature is off renders as plain text.
|
//! grammar feature is off renders as plain text.
|
||||||
|
|
||||||
#[cfg(feature = "code_view")]
|
#[cfg(feature = "code")]
|
||||||
pub mod code_view;
|
pub mod code;
|
||||||
|
|
||||||
#[cfg(feature = "diff_view")]
|
#[cfg(feature = "diff")]
|
||||||
pub mod diff_view;
|
pub mod diff;
|
||||||
|
|
||||||
#[cfg(feature = "markdown_view")]
|
#[cfg(feature = "markdown")]
|
||||||
pub mod markdown;
|
pub mod markdown;
|
||||||
|
|
||||||
pub mod highlight;
|
pub mod highlight;
|
||||||
|
|||||||
+14
-14
@@ -1,24 +1,24 @@
|
|||||||
//! Shared helpers for the editor's views: gutter cells, role colors and run
|
//! Shared helpers for the editor's views: gutter cells, role colors and run
|
||||||
//! styles, code line text, language mapping and change washes.
|
//! 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;
|
use std::ops::Range;
|
||||||
|
|
||||||
#[cfg(feature = "markdown_view")]
|
#[cfg(feature = "markdown")]
|
||||||
use crate::highlight::{Language, Line};
|
use crate::highlight::{Language, Line};
|
||||||
#[cfg(feature = "markdown_view")]
|
#[cfg(feature = "markdown")]
|
||||||
use gpui::StyledText;
|
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};
|
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};
|
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};
|
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;
|
use crate::highlight::Role;
|
||||||
|
|
||||||
#[cfg(any(feature = "code_view", feature = "markdown_view"))]
|
#[cfg(any(feature = "code", feature = "markdown"))]
|
||||||
impl Role {
|
impl Role {
|
||||||
/// Maps the role to the theme's semantic palette.
|
/// Maps the role to the theme's semantic palette.
|
||||||
pub(crate) fn color(self, colors: ColorTokens, ramps: Ramps) -> Hsla {
|
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 {
|
impl Language {
|
||||||
/// Maps a fence info string to a bundled grammar.
|
/// Maps a fence info string to a bundled grammar.
|
||||||
pub(crate) fn from_fence_info(info: &str) -> Option<Language> {
|
pub(crate) fn from_fence_info(info: &str) -> Option<Language> {
|
||||||
@@ -65,7 +65,7 @@ impl Language {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A gutter cell sized to the whole row.
|
/// 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
|
pub(crate) fn gutter_cell<E>(cx: &App, color: Hsla, content: E) -> gpui::Div
|
||||||
where
|
where
|
||||||
E: IntoElement,
|
E: IntoElement,
|
||||||
@@ -86,7 +86,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A change wash: the ramp color at the alpha rows tint with.
|
/// 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 {
|
pub(crate) fn wash(color: Hsla) -> Hsla {
|
||||||
Hsla {
|
Hsla {
|
||||||
a: color.a * WASH_ALPHA,
|
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.
|
/// 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 {
|
pub(crate) fn wash_strong(color: Hsla) -> Hsla {
|
||||||
Hsla {
|
Hsla {
|
||||||
a: color.a * WASH_ALPHA_STRONG,
|
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.
|
/// 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 {
|
pub(crate) fn wash_gutter(colors: &ColorTokens) -> Hsla {
|
||||||
Hsla {
|
Hsla {
|
||||||
a: colors.muted.a * WASH_ALPHA_GUTTER,
|
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.
|
/// 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 {
|
pub(crate) fn code_line(line: &Line, colors: ColorTokens, ramps: Ramps) -> StyledText {
|
||||||
let mut highlights: Vec<(Range<usize>, HighlightStyle)> = Vec::new();
|
let mut highlights: Vec<(Range<usize>, HighlightStyle)> = Vec::new();
|
||||||
let mut offset = 0usize;
|
let mut offset = 0usize;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use gpui::{
|
|||||||
AppContext as _, Context, Entity, Focusable as _, IntoElement, ParentElement as _, Render,
|
AppContext as _, Context, Entity, Focusable as _, IntoElement, ParentElement as _, Render,
|
||||||
Styled as _, TestAppContext, VisualTestContext, Window, div,
|
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};
|
use gpui_native_editor::highlight::{HighlightedCode, Language, Role, highlight};
|
||||||
|
|
||||||
fn spans_with_role(code: &HighlightedCode, role: Role) -> Vec<&str> {
|
fn spans_with_role(code: &HighlightedCode, role: Role) -> Vec<&str> {
|
||||||
@@ -176,8 +176,8 @@ fn selecting_then_copying_writes_the_clipboard() {
|
|||||||
cx.update(|cx| {
|
cx.update(|cx| {
|
||||||
state.update(cx, |state, cx| {
|
state.update(cx, |state, cx| {
|
||||||
state.select_range(
|
state.select_range(
|
||||||
gpui_native_editor::code_view::SelectionPoint { row: 0, col: 0 },
|
gpui_native_editor::code::SelectionPoint { row: 0, col: 0 },
|
||||||
gpui_native_editor::code_view::SelectionPoint { row: 0, col: 3 },
|
gpui_native_editor::code::SelectionPoint { row: 0, col: 3 },
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -8,7 +8,7 @@ use gpui::{
|
|||||||
ScrollDelta, ScrollEvent, Styled as _, TestAppContext, VisualTestContext, Window, div, point,
|
ScrollDelta, ScrollEvent, Styled as _, TestAppContext, VisualTestContext, Window, div, point,
|
||||||
px,
|
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;
|
use gpui_native_editor::highlight::Language;
|
||||||
|
|
||||||
/// Deterministic pseudo-Rust with mixed tokens, roughly `lines` lines long.
|
/// 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,
|
AppContext as _, Context, Entity, IntoElement, MouseButton, ParentElement as _, Render,
|
||||||
Styled as _, TestAppContext, VisualTestContext, Window, div, point, px,
|
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};
|
use gpui_native_editor::highlight::{Language, Role};
|
||||||
|
|
||||||
const OLD: &str = "fn a() {}\nfn b() {}\nfn c() {}\n";
|
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,
|
ScrollDelta, ScrollEvent, Styled as _, TestAppContext, VisualTestContext, Window, div, point,
|
||||||
px,
|
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
|
/// Deterministic old/new pairs of roughly `lines` lines each, with changes
|
||||||
/// sprinkled through.
|
/// sprinkled through.
|
||||||
@@ -44,8 +44,8 @@ use gpui_native_data::list::{List, ListItem};
|
|||||||
use gpui_native_data::sidebar::{Sidebar, SidebarEntry};
|
use gpui_native_data::sidebar::{Sidebar, SidebarEntry};
|
||||||
use gpui_native_data::tabs::{Tab, Tabs, TabsVariant};
|
use gpui_native_data::tabs::{Tab, Tabs, TabsVariant};
|
||||||
use gpui_native_data::tree::{Tree, TreeItem};
|
use gpui_native_data::tree::{Tree, TreeItem};
|
||||||
use gpui_native_editor::code_view::CodeViewState;
|
use gpui_native_editor::code::CodeViewState;
|
||||||
use gpui_native_editor::diff_view::{DiffRowKind, DiffViewState};
|
use gpui_native_editor::diff::{DiffRowKind, DiffViewState};
|
||||||
use gpui_native_editor::highlight::Language;
|
use gpui_native_editor::highlight::Language;
|
||||||
use gpui_native_editor::markdown::{ListMarker, MarkdownBlock, MarkdownViewState, TextView};
|
use gpui_native_editor::markdown::{ListMarker, MarkdownBlock, MarkdownViewState, TextView};
|
||||||
use gpui_native_icons::{IconAssets, IconRole, icon};
|
use gpui_native_icons::{IconAssets, IconRole, icon};
|
||||||
@@ -4163,7 +4163,7 @@ fn main() {
|
|||||||
.with_http_client(std::sync::Arc::new(reqwest_client::ReqwestClient::new()))
|
.with_http_client(std::sync::Arc::new(reqwest_client::ReqwestClient::new()))
|
||||||
.run(|cx: &mut App| {
|
.run(|cx: &mut App| {
|
||||||
gpui_native_core::init(cx);
|
gpui_native_core::init(cx);
|
||||||
gpui_native_editor::code_view::bind_code_view_keys(cx);
|
gpui_native_editor::code::bind_code_view_keys(cx);
|
||||||
gpui_native_editor::markdown::bind_text_view_keys(cx);
|
gpui_native_editor::markdown::bind_text_view_keys(cx);
|
||||||
|
|
||||||
cx.bind_keys([
|
cx.bind_keys([
|
||||||
|
|||||||
Reference in New Issue
Block a user