feat(input): pill, block and bar range decorations, batch edits
- RangeDecorationStyle Pill, Block and Bar with border and radius, painted as quads below the fills - apply_edits puts several edits into one undo step - PATCH.md lists the new changes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -18,6 +18,9 @@ Upstream: crates.io `gpui-base 0.7.1` (git `87d10ae5`, `crates/base`). Wired in
18
18
| `src/input/editor/decorations.rs` | `TextDecorationCollection<M = EditorMode>`, `RangeDecorationCollection<M = EditorMode>`, `create_*_collection` on `impl<M: DecoratedMode>`; `DecorationCollections` / `TrackedDecoration` `pub` + `#[doc(hidden)]` | same API on textarea and editor; default type param keeps editor code unchanged |
19
19
| `src/input/editor/mod.rs`, `src/input/mod.rs` | doc no longer says decorations are editor-only; export `DecoratedMode`, `TextareaExtras` | docs, API |
20
20
| `src/input/editor/display_map/text_wrapper.rs` | lines with inline tokens wrap through `measured_wrap_boundaries` too (`atomic` token ranges, token width + shaped text segments) instead of gpui's `LineWrapper` | mention lines honour font overrides and hanging indent |
21
| `src/input/editor/decorations.rs` | `RangeDecorationStyle::{Pill, Block, Bar}`, `RangeDecoration::with_border()` / `with_radius()` | rounded inline code pills, full-width code block fill, quote bar |
22
| `src/input/base/element.rs` | `layout_range_decoration_quads()` paints pills, blocks and bars as quads below the fills | rounded corners and borders, which paths cannot draw |
23
| `src/input/base/state.rs` | `apply_edits(&[(Range, String)])` on all states | several edits in one undo step without touching inline tokens between them |
21
24
22
25
## Limits
23
26
@@ -18,6 +18,9 @@ Upstream: crates.io `gpui-base 0.7.1` (git `87d10ae5`, `crates/base`). Wired in18
| `src/input/editor/decorations.rs` | `TextDecorationCollection<M = EditorMode>`, `RangeDecorationCollection<M = EditorMode>`, `create_*_collection` on `impl<M: DecoratedMode>`; `DecorationCollections` / `TrackedDecoration` `pub` + `#[doc(hidden)]` | same API on textarea and editor; default type param keeps editor code unchanged |18
| `src/input/editor/decorations.rs` | `TextDecorationCollection<M = EditorMode>`, `RangeDecorationCollection<M = EditorMode>`, `create_*_collection` on `impl<M: DecoratedMode>`; `DecorationCollections` / `TrackedDecoration` `pub` + `#[doc(hidden)]` | same API on textarea and editor; default type param keeps editor code unchanged |19
| `src/input/editor/mod.rs`, `src/input/mod.rs` | doc no longer says decorations are editor-only; export `DecoratedMode`, `TextareaExtras` | docs, API |19
| `src/input/editor/mod.rs`, `src/input/mod.rs` | doc no longer says decorations are editor-only; export `DecoratedMode`, `TextareaExtras` | docs, API |20
| `src/input/editor/display_map/text_wrapper.rs` | lines with inline tokens wrap through `measured_wrap_boundaries` too (`atomic` token ranges, token width + shaped text segments) instead of gpui's `LineWrapper` | mention lines honour font overrides and hanging indent |20
| `src/input/editor/display_map/text_wrapper.rs` | lines with inline tokens wrap through `measured_wrap_boundaries` too (`atomic` token ranges, token width + shaped text segments) instead of gpui's `LineWrapper` | mention lines honour font overrides and hanging indent |21
| `src/input/editor/decorations.rs` | `RangeDecorationStyle::{Pill, Block, Bar}`, `RangeDecoration::with_border()` / `with_radius()` | rounded inline code pills, full-width code block fill, quote bar |22
| `src/input/base/element.rs` | `layout_range_decoration_quads()` paints pills, blocks and bars as quads below the fills | rounded corners and borders, which paths cannot draw |23
| `src/input/base/state.rs` | `apply_edits(&[(Range, String)])` on all states | several edits in one undo step without touching inline tokens between them |21
24
22
## Limits25
## Limits23
26
@@ -7,9 +7,10 @@ use gpui::{
7
7
};
8
8
use gpui::{
9
9
HighlightStyle, Hitbox, HitboxBehavior, Hsla, InteractiveElement, IntoElement, LayoutId,
10
LongPressEvent, MouseButton, MouseMoveEvent, MouseUpEvent, ParentElement as _, Path, Pixels,
11
Point, Position, ShapedLine, SharedString, Size, Style, Styled as _, TextAlign, TextRun,
12
TextStyle, TouchDragEvent, TouchPhase, UnderlineStyle, Window, fill, point, px, relative, size,
10
LongPressEvent, MouseButton, MouseMoveEvent, MouseUpEvent, PaintQuad, ParentElement as _, Path,
11
Pixels, Point, Position, ShapedLine, SharedString, Size, Style, Styled as _, TextAlign,
12
TextRun, TextStyle, TouchDragEvent, TouchPhase, UnderlineStyle, Window, fill, point, px,
13
relative, size,
13
14
};
14
15
use ropey::Rope;
15
16
use smallvec::SmallVec;
@@ -830,6 +831,9 @@ impl<M: InputModeKind> TextElement<M> {
830
831
}
831
832
for decoration in state.extras.range_decorations(&visible_spans) {
832
833
match decoration.style() {
834
RangeDecorationStyle::Pill
835
| RangeDecorationStyle::Block
836
| RangeDecorationStyle::Bar => {}
833
837
RangeDecorationStyle::Fill => {
834
838
let color = decoration
835
839
.color()
@@ -873,6 +877,92 @@ impl<M: InputModeKind> TextElement<M> {
873
877
(fills, frames)
874
878
}
875
879
880
/// Rounded pills, blocks and bars, painted as quads with the fills.
881
fn layout_range_decoration_quads(
882
&self,
883
last_layout: &LastLayout,
884
bounds: &Bounds<Pixels>,
885
cx: &App,
886
) -> Vec<PaintQuad> {
887
let state = self.state.read(cx);
888
let origin = bounds.origin + point(last_layout.line_number_width, px(0.));
889
let text_end = state.text.len();
890
let mut visible_spans: Vec<Range<usize>> = Vec::new();
891
for (&offset, line) in last_layout
892
.visible_line_byte_offsets
893
.iter()
894
.zip(last_layout.lines.iter())
895
{
896
let end = (offset + line.len() + 1).min(last_layout.visible_range_offset.end);
897
if let Some(previous) = visible_spans.last_mut().filter(|span| span.end == offset) {
898
previous.end = end;
899
} else if offset < end {
900
visible_spans.push(offset..end);
901
}
902
}
903
let mut quads = Vec::new();
904
for decoration in state.extras.range_decorations(&visible_spans) {
905
let color = decoration
906
.color()
907
.unwrap_or(state.editor_style.foreground.opacity(0.12));
908
let border = decoration.border();
909
let radius = decoration.radius();
910
let range = decoration.range().clone();
911
match decoration.style() {
912
RangeDecorationStyle::Pill => {
913
let Some(corners) = Self::layout_range_corners(&range, last_layout) else {
914
continue;
915
};
916
for row in corners {
917
let row_bounds = Bounds::from_corners(
918
origin + row.top_left + point(-PILL_PADDING, px(1.)),
919
origin + row.bottom_right + point(PILL_PADDING, px(-1.)),
920
);
921
quads.push(rounded_quad(row_bounds, radius, color, border));
922
}
923
}
924
RangeDecorationStyle::Block | RangeDecorationStyle::Bar => {
925
let mut top: Option<Pixels> = None;
926
let mut bottom = px(0.);
927
let mut y = last_layout.visible_top;
928
for (&line_start, line) in last_layout
929
.visible_line_byte_offsets
930
.iter()
931
.zip(last_layout.lines.iter())
932
{
933
let height =
934
last_layout.line_height * line.wrapped_lines.len().max(1) as f32;
935
let covered = range.contains(&line_start)
936
|| (line_start == range.end && range.end == text_end);
937
if covered {
938
top.get_or_insert(y);
939
bottom = y + height;
940
}
941
y += height;
942
}
943
let Some(top) = top else {
944
continue;
945
};
946
let width = match decoration.style() {
947
RangeDecorationStyle::Bar => radius.max(px(1.)),
948
_ => last_layout.content_width - last_layout.line_number_width,
949
};
950
let block_bounds = Bounds::from_corners(
951
origin + point(px(0.), top),
952
origin + point(width, bottom),
953
);
954
let corner = match decoration.style() {
955
RangeDecorationStyle::Bar => px(0.),
956
_ => radius,
957
};
958
quads.push(rounded_quad(block_bounds, corner, color, border));
959
}
960
RangeDecorationStyle::Fill | RangeDecorationStyle::Frame => {}
961
}
962
}
963
quads
964
}
965
876
966
fn layout_search_matches(
877
967
&self,
878
968
last_layout: &LastLayout,
@@ -2303,6 +2393,7 @@ pub(super) struct PrepaintState {
2303
2393
document_color_paths: Vec<(Path<Pixels>, Hsla)>,
2304
2394
range_decoration_fills: Vec<(Path<Pixels>, Hsla)>,
2305
2395
range_decoration_frames: Vec<(Path<Pixels>, Hsla)>,
2396
range_decoration_quads: Vec<PaintQuad>,
2306
2397
hover_definition_hitbox: Option<Hitbox>,
2307
2398
indent_guides_path: Option<Path<Pixels>>,
2308
2399
/// The whole input, for deciding whether a long press started in it.
@@ -2375,6 +2466,24 @@ fn print_points_as_svg_path(
2375
2466
}
2376
2467
}
2377
2468
2469
const PILL_PADDING: Pixels = px(2.);
2470
2471
fn rounded_quad(
2472
bounds: Bounds<Pixels>,
2473
radius: Pixels,
2474
color: Hsla,
2475
border: Option<Hsla>,
2476
) -> PaintQuad {
2477
gpui::quad(
2478
bounds,
2479
radius,
2480
color,
2481
if border.is_some() { px(1.) } else { px(0.) },
2482
border.unwrap_or(gpui::transparent_black()),
2483
gpui::BorderStyle::default(),
2484
)
2485
}
2486
2378
2487
fn frame_outline_points(corners: &[Corners<Point<Pixels>>]) -> Vec<Point<Pixels>> {
2379
2488
let rects = corners
2380
2489
.iter()
@@ -2895,6 +3004,7 @@ impl<M: InputModeKind> Element for TextElement<M> {
2895
3004
window.content_mask().bounds,
2896
3005
cx,
2897
3006
);
3007
let range_decoration_quads = self.layout_range_decoration_quads(&last_layout, &bounds, cx);
2898
3008
2899
3009
let state = self.state.read(cx);
2900
3010
let line_numbers = if state.mode.line_number() {
@@ -2985,6 +3095,7 @@ impl<M: InputModeKind> Element for TextElement<M> {
2985
3095
document_color_paths,
2986
3096
range_decoration_fills,
2987
3097
range_decoration_frames,
3098
range_decoration_quads,
2988
3099
indent_guides_path,
2989
3100
fold_icon_layout,
2990
3101
ghost_first_line,
@@ -3115,6 +3226,9 @@ impl<M: InputModeKind> Element for TextElement<M> {
3115
3226
}
3116
3227
3117
3228
// Application decorations sit below the user's selection.
3229
for quad in &prepaint.range_decoration_quads {
3230
window.paint_quad(quad.clone());
3231
}
3118
3232
for (path, color) in &prepaint.range_decoration_fills {
3119
3233
window.paint_path(path.clone(), *color);
3120
3234
}
@@ -3714,6 +3828,64 @@ mod tests {
3714
3828
}
3715
3829
}
3716
3830
3831
#[cfg(target_os = "linux")]
3832
#[test]
3833
fn pills_blocks_and_bars_paint_as_quads_only() {
3834
let platform = gpui_platform::current_platform(true);
3835
let mut cx = TestAppContext::build_with_text_system(
3836
gpui::TestDispatcher::new(0),
3837
None,
3838
platform.text_system(),
3839
);
3840
cx.update(crate::init);
3841
let mut textarea = None;
3842
let window = cx.open_window(size(px(240.), px(140.)), |window, cx| {
3843
let state = cx.new(|cx| {
3844
crate::input::TextareaState::new(window, cx)
3845
.rows(4)
3846
.default_value("ab\ncd\nef\n")
3847
});
3848
textarea = Some(state.clone());
3849
TextareaHarness(state)
3850
});
3851
let textarea = textarea.unwrap();
3852
let mut cx = VisualTestContext::from_window(window.into(), &mut cx);
3853
cx.update(|window, cx| {
3854
textarea.update(cx, |state, cx| {
3855
state.create_range_decorations_collection(
3856
vec![
3857
RangeDecoration::new(0..1)
3858
.with_style(RangeDecorationStyle::Pill)
3859
.with_radius(px(4.)),
3860
RangeDecoration::new(3..8).with_style(RangeDecorationStyle::Block),
3861
RangeDecoration::new(8..9)
3862
.with_style(RangeDecorationStyle::Bar)
3863
.with_radius(px(3.)),
3864
],
3865
cx,
3866
);
3867
});
3868
window.draw(cx).clear(cx);
3869
let state = textarea.read(cx);
3870
let layout = state.last_layout.as_ref().unwrap();
3871
let element = TextElement::new(textarea.clone());
3872
let (fills, frames) = element.layout_range_decorations(
3873
layout,
3874
&state.input_bounds,
3875
window,
3876
state.input_bounds,
3877
cx,
3878
);
3879
assert!(fills.is_empty() && frames.is_empty());
3880
let quads = element.layout_range_decoration_quads(layout, &state.input_bounds, cx);
3881
assert_eq!(quads.len(), 3);
3882
let line_height = layout.line_height;
3883
assert_eq!(quads[1].bounds.size.height, line_height * 2.);
3884
assert_eq!(quads[2].bounds.size.width, px(3.));
3885
assert_eq!(quads[2].bounds.size.height, line_height);
3886
});
3887
}
3888
3717
3889
#[cfg(target_os = "linux")]
3718
3890
#[test]
3719
3891
fn textarea_decorations_render_fill_and_wrap_like_the_editor() {
@@ -7,9 +7,10 @@ use gpui::{7
};7
};8
use gpui::{8
use gpui::{9
HighlightStyle, Hitbox, HitboxBehavior, Hsla, InteractiveElement, IntoElement, LayoutId,9
HighlightStyle, Hitbox, HitboxBehavior, Hsla, InteractiveElement, IntoElement, LayoutId,10
LongPressEvent, MouseButton, MouseMoveEvent, MouseUpEvent, ParentElement as _, Path, Pixels,10
LongPressEvent, MouseButton, MouseMoveEvent, MouseUpEvent, PaintQuad, ParentElement as _, Path,11
Point, Position, ShapedLine, SharedString, Size, Style, Styled as _, TextAlign, TextRun,11
Pixels, Point, Position, ShapedLine, SharedString, Size, Style, Styled as _, TextAlign,12
TextStyle, TouchDragEvent, TouchPhase, UnderlineStyle, Window, fill, point, px, relative, size,12
TextRun, TextStyle, TouchDragEvent, TouchPhase, UnderlineStyle, Window, fill, point, px,13
relative, size,13
};14
};14
use ropey::Rope;15
use ropey::Rope;15
use smallvec::SmallVec;16
use smallvec::SmallVec;@@ -830,6 +831,9 @@ impl<M: InputModeKind> TextElement<M> {830
}831
}831
for decoration in state.extras.range_decorations(&visible_spans) {832
for decoration in state.extras.range_decorations(&visible_spans) {832
match decoration.style() {833
match decoration.style() {834
RangeDecorationStyle::Pill835
| RangeDecorationStyle::Block836
| RangeDecorationStyle::Bar => {}833
RangeDecorationStyle::Fill => {837
RangeDecorationStyle::Fill => {834
let color = decoration838
let color = decoration835
.color()839
.color()@@ -873,6 +877,92 @@ impl<M: InputModeKind> TextElement<M> {873
(fills, frames)877
(fills, frames)874
}878
}875
879
880
/// Rounded pills, blocks and bars, painted as quads with the fills.881
fn layout_range_decoration_quads(882
&self,883
last_layout: &LastLayout,884
bounds: &Bounds<Pixels>,885
cx: &App,886
) -> Vec<PaintQuad> {887
let state = self.state.read(cx);888
let origin = bounds.origin + point(last_layout.line_number_width, px(0.));889
let text_end = state.text.len();890
let mut visible_spans: Vec<Range<usize>> = Vec::new();891
for (&offset, line) in last_layout892
.visible_line_byte_offsets893
.iter()894
.zip(last_layout.lines.iter())895
{896
let end = (offset + line.len() + 1).min(last_layout.visible_range_offset.end);897
if let Some(previous) = visible_spans.last_mut().filter(|span| span.end == offset) {898
previous.end = end;899
} else if offset < end {900
visible_spans.push(offset..end);901
}902
}903
let mut quads = Vec::new();904
for decoration in state.extras.range_decorations(&visible_spans) {905
let color = decoration906
.color()907
.unwrap_or(state.editor_style.foreground.opacity(0.12));908
let border = decoration.border();909
let radius = decoration.radius();910
let range = decoration.range().clone();911
match decoration.style() {912
RangeDecorationStyle::Pill => {913
let Some(corners) = Self::layout_range_corners(&range, last_layout) else {914
continue;915
};916
for row in corners {917
let row_bounds = Bounds::from_corners(918
origin + row.top_left + point(-PILL_PADDING, px(1.)),919
origin + row.bottom_right + point(PILL_PADDING, px(-1.)),920
);921
quads.push(rounded_quad(row_bounds, radius, color, border));922
}923
}924
RangeDecorationStyle::Block | RangeDecorationStyle::Bar => {925
let mut top: Option<Pixels> = None;926
let mut bottom = px(0.);927
let mut y = last_layout.visible_top;928
for (&line_start, line) in last_layout929
.visible_line_byte_offsets930
.iter()931
.zip(last_layout.lines.iter())932
{933
let height =934
last_layout.line_height * line.wrapped_lines.len().max(1) as f32;935
let covered = range.contains(&line_start)936
|| (line_start == range.end && range.end == text_end);937
if covered {938
top.get_or_insert(y);939
bottom = y + height;940
}941
y += height;942
}943
let Some(top) = top else {944
continue;945
};946
let width = match decoration.style() {947
RangeDecorationStyle::Bar => radius.max(px(1.)),948
_ => last_layout.content_width - last_layout.line_number_width,949
};950
let block_bounds = Bounds::from_corners(951
origin + point(px(0.), top),952
origin + point(width, bottom),953
);954
let corner = match decoration.style() {955
RangeDecorationStyle::Bar => px(0.),956
_ => radius,957
};958
quads.push(rounded_quad(block_bounds, corner, color, border));959
}960
RangeDecorationStyle::Fill | RangeDecorationStyle::Frame => {}961
}962
}963
quads964
}965
876
fn layout_search_matches(966
fn layout_search_matches(877
&self,967
&self,878
last_layout: &LastLayout,968
last_layout: &LastLayout,@@ -2303,6 +2393,7 @@ pub(super) struct PrepaintState {2303
document_color_paths: Vec<(Path<Pixels>, Hsla)>,2393
document_color_paths: Vec<(Path<Pixels>, Hsla)>,2304
range_decoration_fills: Vec<(Path<Pixels>, Hsla)>,2394
range_decoration_fills: Vec<(Path<Pixels>, Hsla)>,2305
range_decoration_frames: Vec<(Path<Pixels>, Hsla)>,2395
range_decoration_frames: Vec<(Path<Pixels>, Hsla)>,2396
range_decoration_quads: Vec<PaintQuad>,2306
hover_definition_hitbox: Option<Hitbox>,2397
hover_definition_hitbox: Option<Hitbox>,2307
indent_guides_path: Option<Path<Pixels>>,2398
indent_guides_path: Option<Path<Pixels>>,2308
/// The whole input, for deciding whether a long press started in it.2399
/// The whole input, for deciding whether a long press started in it.@@ -2375,6 +2466,24 @@ fn print_points_as_svg_path(2375
}2466
}2376
}2467
}2377
2468
2469
const PILL_PADDING: Pixels = px(2.);2470
2471
fn rounded_quad(2472
bounds: Bounds<Pixels>,2473
radius: Pixels,2474
color: Hsla,2475
border: Option<Hsla>,2476
) -> PaintQuad {2477
gpui::quad(2478
bounds,2479
radius,2480
color,2481
if border.is_some() { px(1.) } else { px(0.) },2482
border.unwrap_or(gpui::transparent_black()),2483
gpui::BorderStyle::default(),2484
)2485
}2486
2378
fn frame_outline_points(corners: &[Corners<Point<Pixels>>]) -> Vec<Point<Pixels>> {2487
fn frame_outline_points(corners: &[Corners<Point<Pixels>>]) -> Vec<Point<Pixels>> {2379
let rects = corners2488
let rects = corners2380
.iter()2489
.iter()@@ -2895,6 +3004,7 @@ impl<M: InputModeKind> Element for TextElement<M> {2895
window.content_mask().bounds,3004
window.content_mask().bounds,2896
cx,3005
cx,2897
);3006
);3007
let range_decoration_quads = self.layout_range_decoration_quads(&last_layout, &bounds, cx);2898
3008
2899
let state = self.state.read(cx);3009
let state = self.state.read(cx);2900
let line_numbers = if state.mode.line_number() {3010
let line_numbers = if state.mode.line_number() {@@ -2985,6 +3095,7 @@ impl<M: InputModeKind> Element for TextElement<M> {2985
document_color_paths,3095
document_color_paths,2986
range_decoration_fills,3096
range_decoration_fills,2987
range_decoration_frames,3097
range_decoration_frames,3098
range_decoration_quads,2988
indent_guides_path,3099
indent_guides_path,2989
fold_icon_layout,3100
fold_icon_layout,2990
ghost_first_line,3101
ghost_first_line,@@ -3115,6 +3226,9 @@ impl<M: InputModeKind> Element for TextElement<M> {3115
}3226
}3116
3227
3117
// Application decorations sit below the user's selection.3228
// Application decorations sit below the user's selection.3229
for quad in &prepaint.range_decoration_quads {3230
window.paint_quad(quad.clone());3231
}3118
for (path, color) in &prepaint.range_decoration_fills {3232
for (path, color) in &prepaint.range_decoration_fills {3119
window.paint_path(path.clone(), *color);3233
window.paint_path(path.clone(), *color);3120
}3234
}@@ -3714,6 +3828,64 @@ mod tests {3714
}3828
}3715
}3829
}3716
3830
3831
#[cfg(target_os = "linux")]3832
#[test]3833
fn pills_blocks_and_bars_paint_as_quads_only() {3834
let platform = gpui_platform::current_platform(true);3835
let mut cx = TestAppContext::build_with_text_system(3836
gpui::TestDispatcher::new(0),3837
None,3838
platform.text_system(),3839
);3840
cx.update(crate::init);3841
let mut textarea = None;3842
let window = cx.open_window(size(px(240.), px(140.)), |window, cx| {3843
let state = cx.new(|cx| {3844
crate::input::TextareaState::new(window, cx)3845
.rows(4)3846
.default_value("ab\ncd\nef\n")3847
});3848
textarea = Some(state.clone());3849
TextareaHarness(state)3850
});3851
let textarea = textarea.unwrap();3852
let mut cx = VisualTestContext::from_window(window.into(), &mut cx);3853
cx.update(|window, cx| {3854
textarea.update(cx, |state, cx| {3855
state.create_range_decorations_collection(3856
vec![3857
RangeDecoration::new(0..1)3858
.with_style(RangeDecorationStyle::Pill)3859
.with_radius(px(4.)),3860
RangeDecoration::new(3..8).with_style(RangeDecorationStyle::Block),3861
RangeDecoration::new(8..9)3862
.with_style(RangeDecorationStyle::Bar)3863
.with_radius(px(3.)),3864
],3865
cx,3866
);3867
});3868
window.draw(cx).clear(cx);3869
let state = textarea.read(cx);3870
let layout = state.last_layout.as_ref().unwrap();3871
let element = TextElement::new(textarea.clone());3872
let (fills, frames) = element.layout_range_decorations(3873
layout,3874
&state.input_bounds,3875
window,3876
state.input_bounds,3877
cx,3878
);3879
assert!(fills.is_empty() && frames.is_empty());3880
let quads = element.layout_range_decoration_quads(layout, &state.input_bounds, cx);3881
assert_eq!(quads.len(), 3);3882
let line_height = layout.line_height;3883
assert_eq!(quads[1].bounds.size.height, line_height * 2.);3884
assert_eq!(quads[2].bounds.size.width, px(3.));3885
assert_eq!(quads[2].bounds.size.height, line_height);3886
});3887
}3888
3717
#[cfg(target_os = "linux")]3889
#[cfg(target_os = "linux")]3718
#[test]3890
#[test]3719
fn textarea_decorations_render_fill_and_wrap_like_the_editor() {3891
fn textarea_decorations_render_fill_and_wrap_like_the_editor() {@@ -1021,6 +1021,19 @@ impl<M: InputModeKind> InputBaseState<M> {
1021
1021
});
1022
1022
}
1023
1023
1024
/// Apply `(byte range in the current text, replacement)` edits as one undo step.
1025
pub fn apply_edits(
1026
&mut self,
1027
edits: &[(Range<usize>, String)],
1028
window: &mut Window,
1029
cx: &mut Context<Self>,
1030
) {
1031
self.with_edits_allowed(|this| {
1032
this.undo_manager.set_pending_intent(EditIntent::Atomic);
1033
this.replace_text_in_ranges(edits, window, cx);
1034
});
1035
}
1036
1024
1037
/// Replace text at the current cursor position.
1025
1038
///
1026
1039
/// And the cursor will be moved to the end of replaced text.
@@ -1021,6 +1021,19 @@ impl<M: InputModeKind> InputBaseState<M> {1021
});1021
});1022
}1022
}1023
1023
1024
/// Apply `(byte range in the current text, replacement)` edits as one undo step.1025
pub fn apply_edits(1026
&mut self,1027
edits: &[(Range<usize>, String)],1028
window: &mut Window,1029
cx: &mut Context<Self>,1030
) {1031
self.with_edits_allowed(|this| {1032
this.undo_manager.set_pending_intent(EditIntent::Atomic);1033
this.replace_text_in_ranges(edits, window, cx);1034
});1035
}1036
1024
/// Replace text at the current cursor position.1037
/// Replace text at the current cursor position.1025
///1038
///1026
/// And the cursor will be moved to the end of replaced text.1039
/// And the cursor will be moved to the end of replaced text.@@ -2,7 +2,8 @@ use crate::input::{DecoratedMode, EditorMode};
2
2
use std::{collections::BTreeMap, ops::Range};
3
3
4
4
use gpui::{
5
App, Context, Font, FontStyle, FontWeight, HighlightStyle, Hsla, SharedString, WeakEntity,
5
App, Context, Font, FontStyle, FontWeight, HighlightStyle, Hsla, Pixels, SharedString,
6
WeakEntity, px,
6
7
};
7
8
use ropey::Rope;
8
9
use sum_tree::Bias;
@@ -18,6 +19,13 @@ pub enum RangeDecorationStyle {
18
19
/// Draw a continuous one-pixel frame around the visual range.
19
20
#[default]
20
21
Frame,
22
/// A rounded box per visual row around the glyphs, e.g. an inline code pill.
23
Pill,
24
/// One rounded box across the full text width of every line whose start lies in
25
/// `range.start..=range.end`, e.g. a code block background.
26
Block,
27
/// A bar at the left edge of the lines a [`Self::Block`] would cover, e.g. a quote.
28
Bar,
21
29
}
22
30
23
31
/// A geometric decoration over a UTF-8 byte range.
@@ -26,6 +34,8 @@ pub struct RangeDecoration {
26
34
range: Range<usize>,
27
35
style: RangeDecorationStyle,
28
36
color: Option<Hsla>,
37
border: Option<Hsla>,
38
radius: Pixels,
29
39
}
30
40
31
41
impl RangeDecoration {
@@ -35,6 +45,8 @@ impl RangeDecoration {
35
45
range,
36
46
style: RangeDecorationStyle::default(),
37
47
color: None,
48
border: None,
49
radius: px(0.),
38
50
}
39
51
}
40
52
@@ -64,6 +76,26 @@ impl RangeDecoration {
64
76
self.color = Some(color);
65
77
self
66
78
}
79
80
/// A one-pixel border for [`RangeDecorationStyle::Pill`] and [`RangeDecorationStyle::Block`].
81
pub fn with_border(mut self, color: Hsla) -> Self {
82
self.border = Some(color);
83
self
84
}
85
86
/// Corner radius for pills and blocks; the width of a [`RangeDecorationStyle::Bar`].
87
pub fn with_radius(mut self, radius: Pixels) -> Self {
88
self.radius = radius;
89
self
90
}
91
92
pub fn border(&self) -> Option<Hsla> {
93
self.border
94
}
95
96
pub fn radius(&self) -> Pixels {
97
self.radius
98
}
67
99
}
68
100
69
101
/// A presentation style applied to a UTF-8 byte range in an input.
@@ -2,7 +2,8 @@ use crate::input::{DecoratedMode, EditorMode};2
use std::{collections::BTreeMap, ops::Range};2
use std::{collections::BTreeMap, ops::Range};3
3
4
use gpui::{4
use gpui::{5
App, Context, Font, FontStyle, FontWeight, HighlightStyle, Hsla, SharedString, WeakEntity,5
App, Context, Font, FontStyle, FontWeight, HighlightStyle, Hsla, Pixels, SharedString,6
WeakEntity, px,6
};7
};7
use ropey::Rope;8
use ropey::Rope;8
use sum_tree::Bias;9
use sum_tree::Bias;@@ -18,6 +19,13 @@ pub enum RangeDecorationStyle {18
/// Draw a continuous one-pixel frame around the visual range.19
/// Draw a continuous one-pixel frame around the visual range.19
#[default]20
#[default]20
Frame,21
Frame,22
/// A rounded box per visual row around the glyphs, e.g. an inline code pill.23
Pill,24
/// One rounded box across the full text width of every line whose start lies in25
/// `range.start..=range.end`, e.g. a code block background.26
Block,27
/// A bar at the left edge of the lines a [`Self::Block`] would cover, e.g. a quote.28
Bar,21
}29
}22
30
23
/// A geometric decoration over a UTF-8 byte range.31
/// A geometric decoration over a UTF-8 byte range.@@ -26,6 +34,8 @@ pub struct RangeDecoration {26
range: Range<usize>,34
range: Range<usize>,27
style: RangeDecorationStyle,35
style: RangeDecorationStyle,28
color: Option<Hsla>,36
color: Option<Hsla>,37
border: Option<Hsla>,38
radius: Pixels,29
}39
}30
40
31
impl RangeDecoration {41
impl RangeDecoration {@@ -35,6 +45,8 @@ impl RangeDecoration {35
range,45
range,36
style: RangeDecorationStyle::default(),46
style: RangeDecorationStyle::default(),37
color: None,47
color: None,48
border: None,49
radius: px(0.),38
}50
}39
}51
}40
52
@@ -64,6 +76,26 @@ impl RangeDecoration {64
self.color = Some(color);76
self.color = Some(color);65
self77
self66
}78
}79
80
/// A one-pixel border for [`RangeDecorationStyle::Pill`] and [`RangeDecorationStyle::Block`].81
pub fn with_border(mut self, color: Hsla) -> Self {82
self.border = Some(color);83
self84
}85
86
/// Corner radius for pills and blocks; the width of a [`RangeDecorationStyle::Bar`].87
pub fn with_radius(mut self, radius: Pixels) -> Self {88
self.radius = radius;89
self90
}91
92
pub fn border(&self) -> Option<Hsla> {93
self.border94
}95
96
pub fn radius(&self) -> Pixels {97
self.radius98
}67
}99
}68
100
69
/// A presentation style applied to a UTF-8 byte range in an input.101
/// A presentation style applied to a UTF-8 byte range in an input.