Skip to repository content57 lines · 1.7 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T02:34:44.329Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
markdown_actions.rs
1use super::*;
2
3impl Editor {
4 pub fn toggle_markdown_block_quote(
5 &mut self,
6 _: &ToggleBlockQuote,
7 window: &mut Window,
8 cx: &mut Context<Self>,
9 ) {
10 self.manipulate_mutable_lines_in_markdown(window, cx, |lines| {
11 let all_lines_quoted = lines.iter().all(|line| line.starts_with('>'));
12
13 for line in lines.iter_mut() {
14 let stripped_line = match line.strip_prefix("> ").or_else(|| line.strip_prefix('>'))
15 {
16 Some(rest) => rest.to_string(),
17 None => line.to_string(),
18 };
19
20 *line = if all_lines_quoted {
21 Cow::Owned(stripped_line)
22 } else if stripped_line.trim().is_empty() {
23 Cow::Borrowed(">")
24 } else {
25 Cow::Owned(format!("> {stripped_line}"))
26 };
27 }
28 });
29 }
30
31 fn manipulate_mutable_lines_in_markdown<Fn>(
32 &mut self,
33 window: &mut Window,
34 cx: &mut Context<Self>,
35 callback: Fn,
36 ) where
37 Fn: FnMut(&mut Vec<Cow<'_, str>>),
38 {
39 if !self.is_in_markdown_language(cx) {
40 return;
41 }
42
43 self.manipulate_mutable_lines(window, cx, callback);
44 }
45
46 fn is_in_markdown_language(&self, cx: &mut App) -> bool {
47 let snapshot = self.buffer.read(cx).snapshot(cx);
48 let head = self
49 .selections
50 .newest::<MultiBufferOffset>(&self.display_snapshot(cx))
51 .head();
52 snapshot
53 .language_at(head)
54 .is_some_and(|language| language.name() == "Markdown")
55 }
56}
57