BlueGit

ict rusty-teams

fix(composer): fourth review round

- Shift+Enter inside a quote keeps both halves quoted
- Backspace joins later quote lines, only the first line un-quotes
- typing and deleting runs merge only where the previous step ended
- undo and redo restore the caret where the edit happened
- undo and redo apply a minimal edit: scroll kept, IME range cleared
- undo marks the value so a taken-back smiley is not re-converted
- line indent without hanging marker wraps rows at the indent

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-10-08 · 7 weeks ago

Hash
06303dc89921a5c8808d4fc0f8fd8c373cf944cb
Parent
dbe591f9
6 files changed +169 −30
crates/app/src/views/composer.rs +112 −24
@@ -21,8 +21,8 @@ use gpui_kit::prelude::FluentBuilder as _;
21 21 use gpui_kit::*;
22 22 use teams_core::{
23 23 Draft, DraftLine, Edit, FileReference, FormatState, HostedImage, LineKind, MarkKind,
24 MentionCandidate, MentionInput, MessageExtras, TypingStyle, UploadedFile, has_markdown,
25 link_url, map_offset, reverse_edits,
24 MentionCandidate, MentionInput, MessageExtras, TypingStyle, UploadedFile, changed_span,
25 has_markdown, link_url, map_offset, reverse_edits,
26 26 };
27 27
28 28 use super::attachment_tray::{
@@ -186,8 +186,8 @@ struct Conversion {
186 186
187 187 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
188 188 enum StepKind {
189 Typing { after_space: bool },
190 Deleting,
189 Typing { at: usize, after_space: bool },
190 Deleting { start: usize, end: usize },
191 191 Other,
192 192 }
193 193
@@ -308,6 +308,7 @@ fn candidate_subtitle(candidate: &MentionCandidate) -> String {
308 308 fn step_kind(previous: &str, value: &str, cursor: usize) -> StepKind {
309 309 if let Some(typed) = emoji::typed_char(previous, value, cursor).filter(|typed| *typed != '\n') {
310 310 return StepKind::Typing {
311 at: cursor - typed.len_utf8(),
311 312 after_space: typed.is_whitespace(),
312 313 };
313 314 }
@@ -320,12 +321,32 @@ fn step_kind(previous: &str, value: &str, cursor: usize) -> StepKind {
320 321 && previous.get(..cursor) == value.get(..cursor)
321 322 && previous.get(cursor + removed..) == value.get(cursor..);
322 323 if one_char_removed {
323 StepKind::Deleting
324 StepKind::Deleting {
325 start: cursor,
326 end: cursor + removed,
327 }
324 328 } else {
325 329 StepKind::Other
326 330 }
327 331 }
328 332
333 fn continues(last: &HistoryStep, kind: StepKind) -> bool {
334 let caret = &last.selection;
335 match (last.kind, kind) {
336 (
337 StepKind::Typing { after_space, .. },
338 StepKind::Typing {
339 at,
340 after_space: space,
341 },
342 ) => (!after_space || space) && caret.is_empty() && caret.start == at,
343 (StepKind::Deleting { .. }, StepKind::Deleting { start, end }) => {
344 caret.is_empty() && (caret.start == end || caret.start == start)
345 }
346 _ => false,
347 }
348 }
349
329 350 fn looks_like_url(text: &str) -> bool {
330 351 ["https://", "http://", "www."]
331 352 .iter()
@@ -624,15 +645,10 @@ impl Composer {
624 645 };
625 646 let at_end = self.history_index + 1 == self.history.len();
626 647 let merges = at_end
627 && match (self.history.last().map(|last| last.kind), kind) {
628 (Some(StepKind::Typing { after_space: false }), StepKind::Typing { .. }) => true,
629 (
630 Some(StepKind::Typing { after_space: true }),
631 StepKind::Typing { after_space },
632 ) => after_space,
633 (Some(StepKind::Deleting), StepKind::Deleting) => true,
634 _ => false,
635 };
648 && self
649 .history
650 .last()
651 .is_some_and(|last| continues(last, kind));
636 652 if merges {
637 653 if let Some(last) = self.history.last_mut() {
638 654 *last = step;
@@ -657,21 +673,38 @@ impl Composer {
657 673 let Some(target) = target else {
658 674 return;
659 675 };
676 let source_selection = self.history[self.history_index].selection.clone();
660 677 self.history_index = target;
661 678 let step = &self.history[target];
662 let mut content = InputContent::new(step.draft.text().to_owned());
663 for (range, token) in &step.tokens {
664 if let Ok(next) = content.clone().with_token(range.clone(), token.clone()) {
665 content = next;
666 }
667 }
668 let (draft, selection) = (step.draft.clone(), step.selection.clone());
679 let (draft, tokens) = (step.draft.clone(), step.tokens.clone());
680 let current = self.input.read(cx).value().to_string();
681 let (start, old_end, new_end) = changed_span(&current, draft.text());
682 let selection = match (start == old_end && start == new_end, back) {
683 (false, _) => new_end..new_end,
684 (true, true) => source_selection,
685 (true, false) => step.selection.clone(),
686 };
687 self.draft = draft.clone();
688 self.previous_value = draft.text().to_owned();
669 689 self.input.update(cx, |state, cx| {
670 state.set_value(content, window, cx);
690 if start != old_end || start != new_end {
691 state.apply_edits(
692 &[(start..old_end, draft.text()[start..new_end].to_owned())],
693 window,
694 cx,
695 );
696 }
697 for (range, token) in tokens {
698 let present = state.tokens().iter().any(|span| span.range() == range);
699 if !present && range.start >= start && range.end <= new_end {
700 state
701 .replace_range_with_token(range, token, window, cx)
702 .ok();
703 }
704 }
671 705 state.set_selected_range(selection, cx);
672 706 });
673 self.previous_value = draft.text().to_owned();
674 self.draft = draft;
707 self.undone_value = Some(self.input.read(cx).value().to_string());
675 708 self.pending_style = None;
676 709 self.conversion = None;
677 710 self.paste_hint = None;
@@ -2657,6 +2690,61 @@ mod tests {
2657 2690 assert_eq!(typist.draft().state(0..5, &MarkKind::Bold), FormatState::On);
2658 2691 }
2659 2692
2693 fn cursor(typist: &mut Typist<'_>) -> usize {
2694 let composer = typist.composer.clone();
2695 typist
2696 .cx
2697 .update(|cx| composer.read(cx).input.read(cx).cursor())
2698 }
2699
2700 #[gpui_kit::test]
2701 fn typing_elsewhere_is_its_own_undo_step_and_undo_puts_the_caret_there(
2702 cx: &mut TestAppContext,
2703 ) {
2704 let mut typist = typist(cx);
2705 typist.type_text("hello");
2706 typist.press("home");
2707 typist.type_text("X");
2708 typist.press("end ctrl-z");
2709 assert_eq!(typist.value(), "hello");
2710 assert_eq!(cursor(&mut typist), 0);
2711 typist.press("ctrl-y");
2712 assert_eq!(typist.value(), "Xhello");
2713 assert_eq!(cursor(&mut typist), 1);
2714 }
2715
2716 #[gpui_kit::test]
2717 fn undo_keeps_the_scroll_position(cx: &mut TestAppContext) {
2718 let mut typist = typist(cx);
2719 for line in 0..14 {
2720 typist.type_text(&format!("line {line}"));
2721 typist.press("shift-enter");
2722 }
2723 typist.type_text("end");
2724 let composer = typist.composer.clone();
2725 let scroll = |typist: &mut Typist<'_>| {
2726 typist
2727 .cx
2728 .update(|cx| composer.read(cx).input.read(cx).scroll_offset().y)
2729 };
2730 typist.act(|window, cx| window.render_frame(cx));
2731 let before = scroll(&mut typist);
2732 assert!(before < gpui_kit::px(0.));
2733 typist.press("ctrl-z");
2734 typist.act(|window, cx| window.render_frame(cx));
2735 assert_eq!(scroll(&mut typist), before);
2736 }
2737
2738 #[gpui_kit::test]
2739 fn a_smiley_taken_back_with_ctrl_z_is_sent_as_typed(cx: &mut TestAppContext) {
2740 let mut typist = typist(cx);
2741 typist.type_text("ok :) ");
2742 assert!(typist.value().contains('🙂'));
2743 typist.press("ctrl-z");
2744 assert_eq!(typist.value(), "ok :) ");
2745 assert_eq!(typist.outgoing().text(), "ok :)");
2746 }
2747
2660 2748 #[gpui_kit::test]
2661 2749 fn an_undo_with_nothing_to_undo_leaves_conversions_working(cx: &mut TestAppContext) {
2662 2750 let mut typist = typist(cx);
@@ -21,8 +21,8 @@ use gpui_kit::prelude::FluentBuilder as _;
21use gpui_kit::*;
21use gpui_kit::*;
22use teams_core::{
22use teams_core::{
23 Draft, DraftLine, Edit, FileReference, FormatState, HostedImage, LineKind, MarkKind,
23 Draft, DraftLine, Edit, FileReference, FormatState, HostedImage, LineKind, MarkKind,
24 MentionCandidate, MentionInput, MessageExtras, TypingStyle, UploadedFile, has_markdown,
24 MentionCandidate, MentionInput, MessageExtras, TypingStyle, UploadedFile, changed_span,
25 link_url, map_offset, reverse_edits,
25 has_markdown, link_url, map_offset, reverse_edits,
26};
26};
27
27
28use super::attachment_tray::{
28use super::attachment_tray::{
@@ -186,8 +186,8 @@ struct Conversion {
186
186
187#[derive(Debug, Clone, Copy, PartialEq, Eq)]
187#[derive(Debug, Clone, Copy, PartialEq, Eq)]
188enum StepKind {
188enum StepKind {
189 Typing { after_space: bool },
189 Typing { at: usize, after_space: bool },
190 Deleting,
190 Deleting { start: usize, end: usize },
191 Other,
191 Other,
192}
192}
193
193
@@ -308,6 +308,7 @@ fn candidate_subtitle(candidate: &MentionCandidate) -> String {
308fn step_kind(previous: &str, value: &str, cursor: usize) -> StepKind {
308fn step_kind(previous: &str, value: &str, cursor: usize) -> StepKind {
309 if let Some(typed) = emoji::typed_char(previous, value, cursor).filter(|typed| *typed != '\n') {
309 if let Some(typed) = emoji::typed_char(previous, value, cursor).filter(|typed| *typed != '\n') {
310 return StepKind::Typing {
310 return StepKind::Typing {
311 at: cursor - typed.len_utf8(),
311 after_space: typed.is_whitespace(),
312 after_space: typed.is_whitespace(),
312 };
313 };
313 }
314 }
@@ -320,12 +321,32 @@ fn step_kind(previous: &str, value: &str, cursor: usize) -> StepKind {
320 && previous.get(..cursor) == value.get(..cursor)
321 && previous.get(..cursor) == value.get(..cursor)
321 && previous.get(cursor + removed..) == value.get(cursor..);
322 && previous.get(cursor + removed..) == value.get(cursor..);
322 if one_char_removed {
323 if one_char_removed {
323 StepKind::Deleting
324 StepKind::Deleting {
325 start: cursor,
326 end: cursor + removed,
327 }
324 } else {
328 } else {
325 StepKind::Other
329 StepKind::Other
326 }
330 }
327}
331}
328
332
333fn continues(last: &HistoryStep, kind: StepKind) -> bool {
334 let caret = &last.selection;
335 match (last.kind, kind) {
336 (
337 StepKind::Typing { after_space, .. },
338 StepKind::Typing {
339 at,
340 after_space: space,
341 },
342 ) => (!after_space || space) && caret.is_empty() && caret.start == at,
343 (StepKind::Deleting { .. }, StepKind::Deleting { start, end }) => {
344 caret.is_empty() && (caret.start == end || caret.start == start)
345 }
346 _ => false,
347 }
348}
349
329fn looks_like_url(text: &str) -> bool {
350fn looks_like_url(text: &str) -> bool {
330 ["https://", "http://", "www."]
351 ["https://", "http://", "www."]
331 .iter()
352 .iter()
@@ -624,15 +645,10 @@ impl Composer {
624 };
645 };
625 let at_end = self.history_index + 1 == self.history.len();
646 let at_end = self.history_index + 1 == self.history.len();
626 let merges = at_end
647 let merges = at_end
627 && match (self.history.last().map(|last| last.kind), kind) {
648 && self
628 (Some(StepKind::Typing { after_space: false }), StepKind::Typing { .. }) => true,
649 .history
629 (
650 .last()
630 Some(StepKind::Typing { after_space: true }),
651 .is_some_and(|last| continues(last, kind));
631 StepKind::Typing { after_space },
632 ) => after_space,
633 (Some(StepKind::Deleting), StepKind::Deleting) => true,
634 _ => false,
635 };
636 if merges {
652 if merges {
637 if let Some(last) = self.history.last_mut() {
653 if let Some(last) = self.history.last_mut() {
638 *last = step;
654 *last = step;
@@ -657,21 +673,38 @@ impl Composer {
657 let Some(target) = target else {
673 let Some(target) = target else {
658 return;
674 return;
659 };
675 };
676 let source_selection = self.history[self.history_index].selection.clone();
660 self.history_index = target;
677 self.history_index = target;
661 let step = &self.history[target];
678 let step = &self.history[target];
662 let mut content = InputContent::new(step.draft.text().to_owned());
679 let (draft, tokens) = (step.draft.clone(), step.tokens.clone());
663 for (range, token) in &step.tokens {
680 let current = self.input.read(cx).value().to_string();
664 if let Ok(next) = content.clone().with_token(range.clone(), token.clone()) {
681 let (start, old_end, new_end) = changed_span(&current, draft.text());
665 content = next;
682 let selection = match (start == old_end && start == new_end, back) {
666 }
683 (false, _) => new_end..new_end,
667 }
684 (true, true) => source_selection,
668 let (draft, selection) = (step.draft.clone(), step.selection.clone());
685 (true, false) => step.selection.clone(),
686 };
687 self.draft = draft.clone();
688 self.previous_value = draft.text().to_owned();
669 self.input.update(cx, |state, cx| {
689 self.input.update(cx, |state, cx| {
670 state.set_value(content, window, cx);
690 if start != old_end || start != new_end {
691 state.apply_edits(
692 &[(start..old_end, draft.text()[start..new_end].to_owned())],
693 window,
694 cx,
695 );
696 }
697 for (range, token) in tokens {
698 let present = state.tokens().iter().any(|span| span.range() == range);
699 if !present && range.start >= start && range.end <= new_end {
700 state
701 .replace_range_with_token(range, token, window, cx)
702 .ok();
703 }
704 }
671 state.set_selected_range(selection, cx);
705 state.set_selected_range(selection, cx);
672 });
706 });
673 self.previous_value = draft.text().to_owned();
707 self.undone_value = Some(self.input.read(cx).value().to_string());
674 self.draft = draft;
675 self.pending_style = None;
708 self.pending_style = None;
676 self.conversion = None;
709 self.conversion = None;
677 self.paste_hint = None;
710 self.paste_hint = None;
@@ -2657,6 +2690,61 @@ mod tests {
2657 assert_eq!(typist.draft().state(0..5, &MarkKind::Bold), FormatState::On);
2690 assert_eq!(typist.draft().state(0..5, &MarkKind::Bold), FormatState::On);
2658 }
2691 }
2659
2692
2693 fn cursor(typist: &mut Typist<'_>) -> usize {
2694 let composer = typist.composer.clone();
2695 typist
2696 .cx
2697 .update(|cx| composer.read(cx).input.read(cx).cursor())
2698 }
2699
2700 #[gpui_kit::test]
2701 fn typing_elsewhere_is_its_own_undo_step_and_undo_puts_the_caret_there(
2702 cx: &mut TestAppContext,
2703 ) {
2704 let mut typist = typist(cx);
2705 typist.type_text("hello");
2706 typist.press("home");
2707 typist.type_text("X");
2708 typist.press("end ctrl-z");
2709 assert_eq!(typist.value(), "hello");
2710 assert_eq!(cursor(&mut typist), 0);
2711 typist.press("ctrl-y");
2712 assert_eq!(typist.value(), "Xhello");
2713 assert_eq!(cursor(&mut typist), 1);
2714 }
2715
2716 #[gpui_kit::test]
2717 fn undo_keeps_the_scroll_position(cx: &mut TestAppContext) {
2718 let mut typist = typist(cx);
2719 for line in 0..14 {
2720 typist.type_text(&format!("line {line}"));
2721 typist.press("shift-enter");
2722 }
2723 typist.type_text("end");
2724 let composer = typist.composer.clone();
2725 let scroll = |typist: &mut Typist<'_>| {
2726 typist
2727 .cx
2728 .update(|cx| composer.read(cx).input.read(cx).scroll_offset().y)
2729 };
2730 typist.act(|window, cx| window.render_frame(cx));
2731 let before = scroll(&mut typist);
2732 assert!(before < gpui_kit::px(0.));
2733 typist.press("ctrl-z");
2734 typist.act(|window, cx| window.render_frame(cx));
2735 assert_eq!(scroll(&mut typist), before);
2736 }
2737
2738 #[gpui_kit::test]
2739 fn a_smiley_taken_back_with_ctrl_z_is_sent_as_typed(cx: &mut TestAppContext) {
2740 let mut typist = typist(cx);
2741 typist.type_text("ok :) ");
2742 assert!(typist.value().contains('🙂'));
2743 typist.press("ctrl-z");
2744 assert_eq!(typist.value(), "ok :) ");
2745 assert_eq!(typist.outgoing().text(), "ok :)");
2746 }
2747
2660 #[gpui_kit::test]
2748 #[gpui_kit::test]
2661 fn an_undo_with_nothing_to_undo_leaves_conversions_working(cx: &mut TestAppContext) {
2749 fn an_undo_with_nothing_to_undo_leaves_conversions_working(cx: &mut TestAppContext) {
2662 let mut typist = typist(cx);
2750 let mut typist = typist(cx);
crates/core/src/draft.rs +30 −3
@@ -618,6 +618,7 @@ impl Draft {
618 618 LineKind::Quote if !shift => None,
619 619 LineKind::Quote => {
620 620 self.splice(cursor..cursor, "\n", &[]);
621 self.lines[index] = LineKind::Quote;
621 622 self.lines[index + 1] = LineKind::Quote;
622 623 Some(cursor + 1)
623 624 }
@@ -699,10 +700,12 @@ impl Draft {
699 700 cursor
700 701 })
701 702 }
702 LineKind::Quote => (cursor == line.start).then(|| {
703 LineKind::Quote
704 if cursor == line.start && (index == 0 || self.lines[index - 1] != kind) =>
705 {
703 706 self.lines[index] = LineKind::Text;
704 cursor
705 }),
707 Some(cursor)
708 }
706 709 _ if cursor == line.start && index > 0 => {
707 710 self.splice(line.start - 1..content.start, "", &[]);
708 711 Some(self.repair(line.start - 1))
@@ -1318,6 +1321,10 @@ fn typed_inline(before: &str) -> Option<(Range<usize>, Range<usize>, MarkKind)>
1318 1321 None
1319 1322 }
1320 1323
1324 pub fn changed_span(old: &str, new: &str) -> (usize, usize, usize) {
1325 edit_span(old, new, new.len())
1326 }
1327
1321 1328 fn edit_span(old: &str, new: &str, cursor: usize) -> (usize, usize, usize) {
1322 1329 let prefix = old
1323 1330 .char_indices()
@@ -2190,6 +2197,26 @@ mod tests {
2190 2197 assert_eq!(link_url("tel:0123456"), None);
2191 2198 }
2192 2199
2200 #[test]
2201 fn a_quote_stays_a_quote_when_split_or_joined() {
2202 let mut draft = Draft::from_markdown("> a\n> b");
2203 let second = draft.line_ranges()[1].start;
2204 assert_eq!(draft.break_line(second, true), Some(second + 1));
2205 assert_eq!(
2206 draft.lines(),
2207 [LineKind::Quote, LineKind::Quote, LineKind::Quote]
2208 );
2209 let mut joined = Draft::from_markdown("> a\n> b");
2210 let second = joined.line_ranges()[1].start;
2211 assert_eq!(joined.backspace_at_start(second), Some(second - 1));
2212 assert_eq!(
2213 (joined.text(), joined.lines()),
2214 ("ab", &[LineKind::Quote][..])
2215 );
2216 assert_eq!(joined.backspace_at_start(0), Some(0));
2217 assert_eq!(joined.lines(), [LineKind::Text]);
2218 }
2219
2193 2220 #[test]
2194 2221 fn journal_merges_edits_into_ranges_of_the_old_text() {
2195 2222 let mut draft = Draft::plain("a **b** c");
@@ -618,6 +618,7 @@ impl Draft {
618 LineKind::Quote if !shift => None,
618 LineKind::Quote if !shift => None,
619 LineKind::Quote => {
619 LineKind::Quote => {
620 self.splice(cursor..cursor, "\n", &[]);
620 self.splice(cursor..cursor, "\n", &[]);
621 self.lines[index] = LineKind::Quote;
621 self.lines[index + 1] = LineKind::Quote;
622 self.lines[index + 1] = LineKind::Quote;
622 Some(cursor + 1)
623 Some(cursor + 1)
623 }
624 }
@@ -699,10 +700,12 @@ impl Draft {
699 cursor
700 cursor
700 })
701 })
701 }
702 }
702 LineKind::Quote => (cursor == line.start).then(|| {
703 LineKind::Quote
704 if cursor == line.start && (index == 0 || self.lines[index - 1] != kind) =>
705 {
703 self.lines[index] = LineKind::Text;
706 self.lines[index] = LineKind::Text;
704 cursor
707 Some(cursor)
705 }),
708 }
706 _ if cursor == line.start && index > 0 => {
709 _ if cursor == line.start && index > 0 => {
707 self.splice(line.start - 1..content.start, "", &[]);
710 self.splice(line.start - 1..content.start, "", &[]);
708 Some(self.repair(line.start - 1))
711 Some(self.repair(line.start - 1))
@@ -1318,6 +1321,10 @@ fn typed_inline(before: &str) -> Option<(Range<usize>, Range<usize>, MarkKind)>
1318 None
1321 None
1319}
1322}
1320
1323
1324pub fn changed_span(old: &str, new: &str) -> (usize, usize, usize) {
1325 edit_span(old, new, new.len())
1326}
1327
1321fn edit_span(old: &str, new: &str, cursor: usize) -> (usize, usize, usize) {
1328fn edit_span(old: &str, new: &str, cursor: usize) -> (usize, usize, usize) {
1322 let prefix = old
1329 let prefix = old
1323 .char_indices()
1330 .char_indices()
@@ -2190,6 +2197,26 @@ mod tests {
2190 assert_eq!(link_url("tel:0123456"), None);
2197 assert_eq!(link_url("tel:0123456"), None);
2191 }
2198 }
2192
2199
2200 #[test]
2201 fn a_quote_stays_a_quote_when_split_or_joined() {
2202 let mut draft = Draft::from_markdown("> a\n> b");
2203 let second = draft.line_ranges()[1].start;
2204 assert_eq!(draft.break_line(second, true), Some(second + 1));
2205 assert_eq!(
2206 draft.lines(),
2207 [LineKind::Quote, LineKind::Quote, LineKind::Quote]
2208 );
2209 let mut joined = Draft::from_markdown("> a\n> b");
2210 let second = joined.line_ranges()[1].start;
2211 assert_eq!(joined.backspace_at_start(second), Some(second - 1));
2212 assert_eq!(
2213 (joined.text(), joined.lines()),
2214 ("ab", &[LineKind::Quote][..])
2215 );
2216 assert_eq!(joined.backspace_at_start(0), Some(0));
2217 assert_eq!(joined.lines(), [LineKind::Text]);
2218 }
2219
2193 #[test]
2220 #[test]
2194 fn journal_merges_edits_into_ranges_of_the_old_text() {
2221 fn journal_merges_edits_into_ranges_of_the_old_text() {
2195 let mut draft = Draft::plain("a **b** c");
2222 let mut draft = Draft::plain("a **b** c");
crates/core/src/lib.rs +1 −1
@@ -27,7 +27,7 @@ pub use avatars::Avatar;
27 27 pub use card::card_content_text;
28 28 pub use draft::{
29 29 Draft, DraftLine, Edit, FormatState, LineKind, MAX_DEPTH, Mark, MarkKind, TypingStyle,
30 has_markdown, link_url, map_offset, reverse_edits,
30 changed_span, has_markdown, link_url, map_offset, reverse_edits,
31 31 };
32 32 pub use engine::{Delta, Me, SidebarSummary, SyncConfig, SyncEngine};
33 33 pub use error::{Error, Result};
@@ -27,7 +27,7 @@ pub use avatars::Avatar;
27pub use card::card_content_text;
27pub use card::card_content_text;
28pub use draft::{
28pub use draft::{
29 Draft, DraftLine, Edit, FormatState, LineKind, MAX_DEPTH, Mark, MarkKind, TypingStyle,
29 Draft, DraftLine, Edit, FormatState, LineKind, MAX_DEPTH, Mark, MarkKind, TypingStyle,
30 has_markdown, link_url, map_offset, reverse_edits,
30 changed_span, has_markdown, link_url, map_offset, reverse_edits,
31};
31};
32pub use engine::{Delta, Me, SidebarSummary, SyncConfig, SyncEngine};
32pub use engine::{Delta, Me, SidebarSummary, SyncConfig, SyncEngine};
33pub use error::{Error, Result};
33pub use error::{Error, Result};
vendor/gpui-base/PATCH.md +1 −1
@@ -18,7 +18,7 @@ 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/base/state.rs`, `src/input/editor/display_map/*`, `src/input/base/element.rs` | `set_line_indents(Vec<(line start, Pixels)>)`: every row of a line starts at its indent and wraps that much earlier; `LineLayout.first_indent` feeds caret, selection, hit testing and up/down; combines with a hanging indent | nested list levels, quote gap and code padding without padding characters in the text |
21 | `src/input/base/state.rs`, `src/input/editor/display_map/*`, `src/input/base/element.rs` | `set_line_indents(Vec<(line start, Pixels)>)`: every row of a line starts at its indent and wraps that much earlier; `LineLayout.first_indent` feeds caret, selection, hit testing and up/down; combines with a hanging indent; without one, continuation rows start at the line indent, not under leading spaces | nested list levels, quote gap and code padding without padding characters in the text |
22 22 | `src/input/editor/decorations.rs` | `RangeDecorationStyle::{Pill, Block, Bar}`, `RangeDecoration::with_border()` / `with_radius()`; Block and Bar keep empty ranges (`TrackedDecoration::keeps_empty`) and the index finds them | rounded inline code pills, full-width code block fill, quote bar; a block over one empty line |
23 23 | `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 |
24 24 | `src/input/base/state.rs` | `apply_edits(&[(Range, String)])` on all states | several edits in one undo step without touching inline tokens between them |
@@ -18,7 +18,7 @@ Upstream: crates.io `gpui-base 0.7.1` (git `87d10ae5`, `crates/base`). Wired in
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 |
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/base/state.rs`, `src/input/editor/display_map/*`, `src/input/base/element.rs` | `set_line_indents(Vec<(line start, Pixels)>)`: every row of a line starts at its indent and wraps that much earlier; `LineLayout.first_indent` feeds caret, selection, hit testing and up/down; combines with a hanging indent | nested list levels, quote gap and code padding without padding characters in the text |
21| `src/input/base/state.rs`, `src/input/editor/display_map/*`, `src/input/base/element.rs` | `set_line_indents(Vec<(line start, Pixels)>)`: every row of a line starts at its indent and wraps that much earlier; `LineLayout.first_indent` feeds caret, selection, hit testing and up/down; combines with a hanging indent; without one, continuation rows start at the line indent, not under leading spaces | nested list levels, quote gap and code padding without padding characters in the text |
22| `src/input/editor/decorations.rs` | `RangeDecorationStyle::{Pill, Block, Bar}`, `RangeDecoration::with_border()` / `with_radius()`; Block and Bar keep empty ranges (`TrackedDecoration::keeps_empty`) and the index finds them | rounded inline code pills, full-width code block fill, quote bar; a block over one empty line |
22| `src/input/editor/decorations.rs` | `RangeDecorationStyle::{Pill, Block, Bar}`, `RangeDecoration::with_border()` / `with_radius()`; Block and Bar keep empty ranges (`TrackedDecoration::keeps_empty`) and the index finds them | rounded inline code pills, full-width code block fill, quote bar; a block over one empty line |
23| `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/element.rs` | `layout_range_decoration_quads()` paints pills, blocks and bars as quads below the fills | rounded corners and borders, which paths cannot draw |
24| `src/input/base/state.rs` | `apply_edits(&[(Range, String)])` on all states | several edits in one undo step without touching inline tokens between them |
24| `src/input/base/state.rs` | `apply_edits(&[(Range, String)])` on all states | several edits in one undo step without touching inline tokens between them |
vendor/gpui-base/src/input/base/state.rs +22 −0
@@ -8821,6 +8821,28 @@ mod tests {
8821 8821 });
8822 8822 }
8823 8823
8824 #[gpui::test]
8825 fn test_line_indent_without_marker_wraps_rows_at_the_indent_not_at_leading_spaces(
8826 cx: &mut TestAppContext,
8827 ) {
8828 cx.update(crate::init);
8829 let text = format!(" {}", "word ".repeat(200));
8830 let view = InputView::build_textarea(cx, move |state| state.rows(4).default_value(text));
8831 let mut visual = VisualTestContext::from_window(view.window_handle.into(), cx);
8832 visual.update(|_, cx| {
8833 view.input
8834 .update(cx, |state, cx| state.set_line_indents(vec![(0, px(10.))], cx))
8835 });
8836 visual.update(|window, cx| window.draw(cx).clear(cx));
8837 view.input.read_with(&visual, |state, _| {
8838 let line = &state.last_layout.as_ref().unwrap().lines[0];
8839 assert!(line.wrapped_lines.len() > 1);
8840 assert_eq!(line.wrap_indent, px(0.));
8841 assert_eq!(line.line_indent(1), px(10.));
8842 assert!(line.wrapped_lines[1].len > 20);
8843 });
8844 }
8845
8824 8846 #[gpui::test]
8825 8847 fn test_editor_decorations_follow_typing(cx: &mut TestAppContext) {
8826 8848 let view = InputView::<EditorMode>::new(cx);
@@ -8821,6 +8821,28 @@ mod tests {
8821 });
8821 });
8822 }
8822 }
8823
8823
8824 #[gpui::test]
8825 fn test_line_indent_without_marker_wraps_rows_at_the_indent_not_at_leading_spaces(
8826 cx: &mut TestAppContext,
8827 ) {
8828 cx.update(crate::init);
8829 let text = format!(" {}", "word ".repeat(200));
8830 let view = InputView::build_textarea(cx, move |state| state.rows(4).default_value(text));
8831 let mut visual = VisualTestContext::from_window(view.window_handle.into(), cx);
8832 visual.update(|_, cx| {
8833 view.input
8834 .update(cx, |state, cx| state.set_line_indents(vec![(0, px(10.))], cx))
8835 });
8836 visual.update(|window, cx| window.draw(cx).clear(cx));
8837 view.input.read_with(&visual, |state, _| {
8838 let line = &state.last_layout.as_ref().unwrap().lines[0];
8839 assert!(line.wrapped_lines.len() > 1);
8840 assert_eq!(line.wrap_indent, px(0.));
8841 assert_eq!(line.line_indent(1), px(10.));
8842 assert!(line.wrapped_lines[1].len > 20);
8843 });
8844 }
8845
8824 #[gpui::test]
8846 #[gpui::test]
8825 fn test_editor_decorations_follow_typing(cx: &mut TestAppContext) {
8847 fn test_editor_decorations_follow_typing(cx: &mut TestAppContext) {
8826 let view = InputView::<EditorMode>::new(cx);
8848 let view = InputView::<EditorMode>::new(cx);
vendor/gpui-base/src/input/editor/display_map/text_wrapper.rs +3 −1
@@ -547,11 +547,13 @@ impl TextWrapper {
547 547 let token_ranges: Vec<_> = tokens.iter().map(|(range, _)| range.clone()).collect();
548 548 let wrap_width =
549 549 (wrap_width - line_indent_at(&line_indents, line_start)).max(px(1.));
550 let line_indented = line_indent_at(&line_indents, line_start) > px(0.);
550 551 measured_wrap_boundaries(
551 552 line_str,
552 553 wrap_width,
553 554 wrapping_indent,
554 hanging_indent_at(&hanging_indents, line_start, line_str.len()),
555 hanging_indent_at(&hanging_indents, line_start, line_str.len())
556 .or(line_indented.then_some(0)),
555 557 &token_ranges,
556 558 |range| {
557 559 let mut width = px(0.);
@@ -547,11 +547,13 @@ impl TextWrapper {
547 let token_ranges: Vec<_> = tokens.iter().map(|(range, _)| range.clone()).collect();
547 let token_ranges: Vec<_> = tokens.iter().map(|(range, _)| range.clone()).collect();
548 let wrap_width =
548 let wrap_width =
549 (wrap_width - line_indent_at(&line_indents, line_start)).max(px(1.));
549 (wrap_width - line_indent_at(&line_indents, line_start)).max(px(1.));
550 let line_indented = line_indent_at(&line_indents, line_start) > px(0.);
550 measured_wrap_boundaries(
551 measured_wrap_boundaries(
551 line_str,
552 line_str,
552 wrap_width,
553 wrap_width,
553 wrapping_indent,
554 wrapping_indent,
554 hanging_indent_at(&hanging_indents, line_start, line_str.len()),
555 hanging_indent_at(&hanging_indents, line_start, line_str.len())
556 .or(line_indented.then_some(0)),
555 &token_ranges,
557 &token_ranges,
556 |range| {
558 |range| {
557 let mut width = px(0.);
559 let mut width = px(0.);