cydonia 0.1.16

Desktop workspace for the ACP agents you run, keeping what they produce as files on your disk
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
//! The article pane: one document, and the sidebar row that opens it.

use crate::{
    memory,
    model::{article, workspace::Showing},
    view::{
        leaf::Pane,
        root::{Cydonia, NewArticle},
        sidebar::{self, Row},
    },
};
use artifact::space::Member;
use bezel::ui::scroll as scrollbars;
use bezel::{
    gpui::{
        self, AnyElement, App, Context, CursorStyle, Div, Entity, Focusable as _, KeyBinding,
        MouseButton, ObjectFit, PathPromptOptions, SharedString, Window, actions, div, img,
        prelude::*, px,
    },
    motion::{Fade, Painter},
    theme::{ControlSize, Sizing as _, TextStyle, Theme, Typeset},
    ui::{
        icons,
        input::TextField,
        widgets::{ButtonStyle, Buttons as _, Status as _},
    },
};
use editor::Mode;
use markdown::HighlightColor;
use std::{
    path::{Path, PathBuf},
    sync::atomic::{AtomicUsize, Ordering},
};

actions!(cydonia_article, [LeaveTitle, TogglePlainText]);

/// `enter` and `down` in the title move to the content. Bound on the field's
/// own context, which is the only thing deep enough to beat the field itself.
///
/// [`TogglePlainText`] is not here: it is a command a person may move, so it
/// is bound from [`crate::view::keymap`] with the rest of them. What it does
/// to the editor is the same either way — the View menu carries it, so AppKit
/// takes the chord before the window is offered it and the editor's own `⌘E`,
/// inline code, is never reached. That is why the ribbon's code button
/// advertises no chord; see [`crate::view::component::ribbon::keystroke`].
pub fn bindings() -> Vec<KeyBinding> {
    let ctx = Some(article::TITLE_CONTEXT);
    vec![
        KeyBinding::new("enter", LeaveTitle, ctx),
        KeyBinding::new("down", LeaveTitle, ctx),
    ]
}

/// The column the document is set in, matching the transcript's. Off, for a
/// page that reads wide under [`article::Article::wide`], the pane's own width
/// is the measure — see [`column`].
const CONTENT_MAX_WIDTH: f32 = 720.;

/// How tall the cover band is, with a picture in it or without: half the 5:2 a
/// cover is cut at, taken at the column's width. The picture is centred in the
/// band, so what shows is the middle of it.
///
/// Fixed, and not re-derived from the measure a wide page is set to: the band
/// is the same height either way, so setting a page across the pane widens the
/// picture without moving a line of the document under it.
const COVER_HEIGHT: f32 = CONTENT_MAX_WIDTH / 5.;

/// How much empty page hangs below the last line, so the end of a document
/// scrolls clear of the bottom edge of the pane.
const TAIL: f32 = 120.;

/// How far the page holds its text off its own edge, in both measures: a page
/// set across the pane changes where the text stops, not how far in it starts.
///
/// What the title adds to it is the editor's [`editor::Layout::text_inset`],
/// read at paint like the theme — the editor holds its text that far inside
/// its box so a block's drag handle has somewhere to sit, and the title takes
/// the same measure to line up with the first paragraph. That allowance is the
/// handle's whole room, in either measure.
const COLUMN_INSET: f32 = 24.;

/// Plain-text styling, resolved against the active theme on every paint.
pub fn source_style(theme: &Theme) -> markdown::SourceStyle {
    markdown::SourceStyle {
        line_numbers: true,
        gutter_min_digits: 1,
        gutter_gap: 1.5,
        gutter_color: Some(theme.text_faint),
    }
}

/// The custom marks an article is read and written with: `==text==` is
/// [`editor::HIGHLIGHT_MARK`].
pub fn marks() -> markdown::Marks {
    markdown::Marks::new().with(editor::HIGHLIGHT_MARK, "==")
}

/// The colour [`mark_paint`] washes a highlight in, as an index into
/// [`HighlightColor::ALL`]. Global because a painter is a bare `fn`.
static HIGHLIGHT: AtomicUsize = AtomicUsize::new(0);

/// Paint every highlight in `color` from the next frame on.
pub fn set_highlight(color: HighlightColor) {
    let ix = HighlightColor::ALL
        .iter()
        .position(|c| *c == color)
        .unwrap_or(0);
    HIGHLIGHT.store(ix, Ordering::Relaxed);
}

/// How [`marks`] paint: every highlight in the colour [`set_highlight`] chose.
pub fn mark_paint(name: &str, theme: &Theme) -> Option<markdown::MarkPaint> {
    let color = HighlightColor::ALL[HIGHLIGHT.load(Ordering::Relaxed)];
    (name == editor::HIGHLIGHT_MARK).then(|| markdown::MarkPaint {
        background: Some(markdown::default_highlight(color, theme)),
        ..Default::default()
    })
}

fn source_offset(editor: &editor::Editor, cx: &App) -> f32 {
    if editor.mode() != Mode::Source {
        return 0.;
    }
    let style = markdown::SourceStyle::of(cx);
    let base = bezel::theme::base_text_size();
    let limits = editor::TextSize::of(cx);
    let size = ((editor.text_size().unwrap_or(base) + editor::text_size_adjustment(cx))
        .clamp(limits.min, limits.max)
        * 10.)
        .round()
        / 10.;
    let code_size = markdown::Typography::of(cx).scaled(size / base).code.size();
    let digits = editor
        .source()
        .split('\n')
        .count()
        .to_string()
        .len()
        .max(style.gutter_min_digits);
    // Cancel Bezel's code padding and full gutter so source text aligns with the title.
    12. + if style.line_numbers {
        (digits as f32 + style.gutter_gap.max(0.)) * code_size
    } else {
        0.
    }
}

/// The box the page is set in: the reading column, or the pane itself. The
/// title and the document both take it, since two boxes made conditional apart
/// drift apart the first time one of them is touched.
fn column(wide: bool) -> Div {
    let band = div().w_full();
    match wide {
        true => band,
        false => band.max_w(px(CONTENT_MAX_WIDTH)),
    }
}

impl Cydonia {
    // ── mutations ────────────────────────────────────────────────

    /// The menu's New Article. The sidebar's `+` names a project by the
    /// heading it sits under; the menu bar has only the one in front.
    pub(crate) fn new_article_action(
        &mut self,
        _: &NewArticle,
        window: &mut Window,
        cx: &mut Context<Self>,
    ) {
        let Some(project) = self.workspace.read(cx).active else {
            return;
        };
        self.new_article(project, window, cx);
    }

    pub(crate) fn new_article(
        &mut self,
        project: usize,
        window: &mut Window,
        cx: &mut Context<Self>,
    ) {
        self.select_project(project, cx);
        let ix = self
            .workspace
            .update(cx, |workspace, cx| workspace.new_article(cx));
        if let Some(ix) = ix {
            self.open_article(project, ix, window, cx);
        }
    }

    /// Show the article and put the caret in it — the pane is a document and
    /// nothing else, so there is nowhere else the focus could sensibly go.
    pub(crate) fn open_article(
        &mut self,
        project: usize,
        ix: usize,
        window: &mut Window,
        cx: &mut Context<Self>,
    ) {
        self.commit(cx);
        let member = self
            .workspace
            .read(cx)
            .member_of(project, Showing::Article(ix));
        if self.enter_member(member, window, cx) {
            return;
        }
        self.workspace
            .update(cx, |workspace, cx| workspace.open_article(project, ix, cx));
        self.leaf_mut().pane = Pane::Article;

        let (field, editor, unnamed) = {
            let article = self.pane_doc(cx);
            (
                article.and_then(|article| article.field.clone()),
                article.and_then(|article| article.editor.clone()),
                article.is_some_and(|article| article.title.is_empty()),
            )
        };
        // A page with no name is asking to be given one; a named one is asking
        // to be written in.
        match (unnamed, field, editor) {
            (true, Some(field), _) => window.focus(&field.focus_handle(cx), cx),
            (_, _, Some(editor)) => window.focus(&editor.focus_handle(cx), cx),
            _ => {}
        }
        cx.notify();
    }

    /// The article the focused pane is on. A window with no space open has no
    /// member to name, and falls back to what its project is pointed at.
    pub(crate) fn pane_doc<'a>(&self, cx: &'a App) -> Option<&'a crate::model::article::Article> {
        self.workspace
            .read(cx)
            .article_of(self.leaf().entry.as_ref())
    }

    /// The same by its file — the one address every write to an article is
    /// made through.
    pub(crate) fn pane_article(&self, cx: &App) -> Option<std::path::PathBuf> {
        self.pane_doc(cx).map(|article| article.path.clone())
    }

    /// Out of the title and into the document under it.
    fn leave_title(&mut self, _: &LeaveTitle, window: &mut Window, cx: &mut Context<Self>) {
        let editor = self.pane_doc(cx).and_then(|article| article.editor.clone());
        if let Some(editor) = editor {
            window.focus(&editor.focus_handle(cx), cx);
        }
    }

    /// Swap the document for the markdown it spells, and back — the header
    /// menu's Plain text and its ⌘E.
    ///
    /// The focus goes back to the document afterwards: the switch carries the
    /// caret across, and a caret in a surface nobody is typing in is a caret
    /// that has to be clicked back into.
    pub(crate) fn toggle_plain_text(
        &mut self,
        _: &TogglePlainText,
        window: &mut Window,
        cx: &mut Context<Self>,
    ) {
        let Some(mode) = self.plain_text(cx) else {
            return;
        };
        let mode = match mode {
            true => Mode::Blocks,
            false => Mode::Source,
        };
        let Some(on) = self.pane_article(cx) else {
            return;
        };
        self.workspace.update(cx, |workspace, cx| {
            workspace.set_article_mode(&on, mode, cx)
        });
        let editor = self.pane_doc(cx).and_then(|article| article.editor.clone());
        if let Some(editor) = editor {
            window.focus(&editor.focus_handle(cx), cx);
        }
        cx.notify();
    }

    /// Whether the open document is being edited as markdown, or `None` where
    /// there is no document to be in either form.
    pub(crate) fn plain_text(&self, cx: &App) -> Option<bool> {
        let article = self.pane_doc(cx)?;
        Some(article.mode(cx) == Mode::Source)
    }

    /// Set the open page across the pane, or back in the reading column — the
    /// header menu's Full width, and `None` for its Use default width. The
    /// open one, since that is the page the menu was asked from.
    pub(crate) fn set_full_width(&mut self, wide: Option<bool>, cx: &mut Context<Self>) {
        let Some(on) = self.pane_article(cx) else {
            return;
        };
        self.workspace
            .update(cx, |workspace, cx| workspace.set_full_width(&on, wide, cx));
        cx.notify();
    }

    /// Cut the open article a new cover. Adding the first one comes through
    /// here too — there is nothing to choose between, only a picture to get.
    pub(crate) fn shuffle_cover(&mut self, cx: &mut Context<Self>) {
        let Some(on) = self.pane_article(cx) else {
            return;
        };
        self.workspace
            .update(cx, |workspace, cx| workspace.shuffle_cover(&on, cx));
        cx.notify();
    }

    /// Swap the generated picture for one of the person's own.
    fn pick_cover(&mut self, cx: &mut Context<Self>) {
        // Taken before the dialog goes up: the page the cover was asked for is
        // the page it lands on, whatever the window is showing by the time a
        // file comes back.
        let Some(on) = self.pane_article(cx) else {
            return;
        };
        let picked = cx.prompt_for_paths(PathPromptOptions {
            files: true,
            directories: false,
            multiple: false,
            prompt: None,
        });
        cx.spawn(async move |this, cx| {
            let Ok(Ok(Some(paths))) = picked.await else {
                return;
            };
            let Some(path) = paths.into_iter().next() else {
                return;
            };
            let _ = this.update(cx, |this, cx| {
                this.workspace.update(cx, |workspace, cx| {
                    workspace.set_cover(&on, Some(&path), cx)
                });
                cx.notify();
            });
        })
        .detach();
    }

    fn remove_cover(&mut self, cx: &mut Context<Self>) {
        let Some(on) = self.pane_article(cx) else {
            return;
        };
        self.workspace
            .update(cx, |workspace, cx| workspace.set_cover(&on, None, cx));
        cx.notify();
    }

    /// Take the file over the buffer — the notice's Reload.
    fn revert_article(&mut self, path: &Path, window: &mut Window, cx: &mut Context<Self>) {
        self.workspace
            .update(cx, |workspace, cx| workspace.revert_article(path, cx));
        self.follow_article(window, cx);
        cx.notify();
    }

    /// Put the caret back in the open document after a re-read replaced it.
    /// The editor is a new entity, so whatever focus the old one held went with
    /// it — and focus on an element no frame draws is focus nowhere.
    ///
    /// Never off the title. That field survives a re-read that did not rebuild
    /// it, and dragging the caret out of a name somebody is typing is worse
    /// than one they have to click back into the body.
    pub(crate) fn follow_article(&self, window: &mut Window, cx: &mut Context<Self>) {
        if self.showing(cx) != Some(Pane::Article) {
            return;
        }
        let article = self.pane_doc(cx);
        let titling = article
            .and_then(|article| article.field.clone())
            .is_some_and(|field| field.focus_handle(cx).contains_focused(window, cx));
        let editor = article.and_then(|article| article.editor.clone());
        if let Some(editor) = editor.filter(|_| !titling) {
            window.focus(&editor.focus_handle(cx), cx);
        }
    }

    /// Keep the buffer and write it over the file — the notice's other answer.
    fn keep_article(&mut self, path: &Path, cx: &mut Context<Self>) {
        self.workspace
            .update(cx, |workspace, cx| workspace.keep_article(path, cx));
        cx.notify();
    }

    // ── chrome ───────────────────────────────────────────────────

    /// The document. Same frame as [`Cydonia::board`]: the body of the content
    /// card, with the composer stack still pinned under it.
    pub(crate) fn article(
        &self,
        project: usize,
        at: usize,
        on: Option<&Member>,
        window: &mut Window,
        cx: &mut Context<Self>,
    ) -> Option<AnyElement> {
        let article = self.workspace.read(cx).article_in(project, at)?;
        let field = article.field.clone()?;
        let editor = article.editor.clone()?;
        let cover = article.cover.clone();
        let wide = article.wide(self.workspace.read(cx).wide_pages);
        let source_offset = source_offset(editor.read(cx), cx);
        let stale = article.stale.then(|| article.path.clone());
        let document = div()
            .id("article")
            .on_action(cx.listener(Self::leave_title))
            // What the ribbon reads to keep out of a drag — see
            // [`crate::view::component::ribbon`]. Taken in the capture phase
            // and on the way out as well as in, so a release past the pane's
            // edge still ends the gesture.
            .capture_any_mouse_down(cx.listener(|this, _, _, cx| this.set_selecting(true, cx)))
            .capture_any_mouse_up(cx.listener(|this, _, _, cx| this.set_selecting(false, cx)))
            .on_mouse_up_out(
                MouseButton::Left,
                cx.listener(|this, _, _, cx| this.set_selecting(false, cx)),
            )
            .flex_1()
            .min_h_0()
            .w_full()
            .overflow_y_scroll()
            .track_scroll(&article.scroll)
            .flex()
            .flex_col()
            .child(self.header(cover, field, wide, cx))
            // Its own height, not the box's share of one: a long document
            // overflows and scrolls instead of being squashed and clipped,
            // and `min_h_full` is what leaves the band something to scroll
            // *under* when the document is short.
            .child(
                div()
                    .w_full()
                    .flex_none()
                    .min_h_full()
                    .flex()
                    .justify_center()
                    .cursor(CursorStyle::IBeam)
                    .on_mouse_down(MouseButton::Left, {
                        let editor = editor.clone();
                        move |event, window, cx| {
                            editor.update(cx, |editor, cx| {
                                editor.press(
                                    event.position,
                                    event.click_count,
                                    event.modifiers,
                                    window,
                                    cx,
                                )
                            })
                        }
                    })
                    .child(
                        // A page, not a paragraph. The editor's box is only
                        // as tall as the document, and a pane of dead space
                        // under a one-line note reads as something you
                        // cannot type in: the band around it is what makes
                        // a click down there or beside it land a caret, and
                        // the I-beam is what says so before the click.
                        column(wide)
                            .px(px(COLUMN_INSET))
                            .pt(px(20.))
                            .pb(px(TAIL))
                            .flex()
                            .child(
                                div()
                                    .flex_1()
                                    .min_w_0()
                                    .ml(px(-source_offset))
                                    .child(editor.clone()),
                            ),
                    ),
            );
        Some(
            div()
                .flex_1()
                .min_h_0()
                .w_full()
                .flex()
                .flex_col()
                // The editor paints its selection only while focused, and a
                // press on chrome with no focus of its own leaves focus where
                // it was.
                .on_mouse_down_out({
                    let editor = editor.clone();
                    move |_, window, cx| {
                        if editor.focus_handle(cx).is_focused(window) {
                            window.blur(cx);
                        }
                    }
                })
                // Above the scroll box rather than inside it: a document long
                // enough to scroll would carry the notice off the top of the
                // pane, and it is about the document as a whole.
                .children(stale.map(|path| self.stale_notice(path, cx)))
                .child(
                    div()
                        .relative()
                        .flex_1()
                        .min_h_0()
                        .flex()
                        .flex_col()
                        .child(document)
                        .child(scrollbars::Overlay::new(
                            "article-bar",
                            &article.scroll,
                            bezel::gpui::Axis::Vertical,
                        )),
                )
                // Last, and floated over the document from where the
                // selection ends — the bar is chrome the page runs under.
                .children(self.ribbon(on, window, cx))
                .into_any_element(),
        )
    }

    /// The file moved under a document that had edits of its own — see
    /// [`article::Article::adopt`]. Both are somebody's work, so the pane says
    /// so and offers the two ways out rather than picking one.
    fn stale_notice(&self, path: PathBuf, cx: &Context<Self>) -> impl IntoElement + use<> {
        let theme = Theme::of(cx).clone();
        let painter = Painter::of(cx);
        let chip = |id: &'static str, label: &'static str| {
            theme
                .button(label, ButtonStyle::Ghost, Some(Fade::new(painter, id)))
                .control_size(ControlSize::Small)
                .id(id)
        };
        let keep = path.clone();
        theme
            .warning_strip("This file changed on disk while you were editing it.")
            .mx(px(COLUMN_INSET))
            .flex_none()
            .items_center()
            .child(
                theme
                    .control_group()
                    .ml_auto()
                    .flex_none()
                    .child(chip("article-revert", "Reload").on_click(cx.listener(
                        move |this, _, window, cx| this.revert_article(&path, window, cx),
                    )))
                    .child(
                        chip("article-keep", "Keep mine").on_click(
                            cx.listener(move |this, _, _, cx| this.keep_article(&keep, cx)),
                        ),
                    ),
            )
    }

    /// The page's furniture: its picture, and the name under it. Both belong to
    /// the page rather than to the document, so neither is anything the editor
    /// below knows about.
    fn header(
        &self,
        cover: Option<PathBuf>,
        field: Entity<TextField>,
        wide: bool,
        cx: &Context<Self>,
    ) -> impl IntoElement + use<> {
        // The band only where there is a picture in it. A page with no cover
        // starts at its title; `Add cover` is in the band's `···`, which is on
        // screen either way and costs the page no room — see
        // `sidebar::entry_menu`.
        div()
            .w_full()
            .flex_none()
            .flex()
            .flex_col()
            .children(cover.map(|cover| self.cover_band(cover, cx)))
            .child(
                div().w_full().flex().justify_center().child(
                    column(wide)
                        .pl(px(COLUMN_INSET + editor::Layout::of(cx).text_inset))
                        .pr(px(COLUMN_INSET))
                        .pt(px(20.))
                        .child(field),
                ),
            )
    }

    /// The picture across the top of a page that has one.
    fn cover_band(&self, cover: PathBuf, cx: &Context<Self>) -> impl IntoElement + use<> {
        div()
            .group("cover")
            .relative()
            .w_full()
            .flex_none()
            .h(px(COVER_HEIGHT))
            .overflow_hidden()
            .child(
                img(cover)
                    .size_full()
                    .object_fit(ObjectFit::Cover)
                    // Off gpui's own asset cache, which never lets a decoded
                    // cover go. See [`crate::memory`].
                    .image_cache(&memory::covers(cx)),
            )
            .child(self.cover_controls(cx))
    }

    /// The cover's own controls, kept off the page until the pointer is on it.
    ///
    /// Absolute, so neither showing them nor taking the cover away moves a line
    /// of the document — a row that sat in flow would shunt the first paragraph
    /// down the moment the mouse crossed the pane.
    fn cover_controls(&self, cx: &Context<Self>) -> impl IntoElement + use<> {
        let theme = Theme::of(cx).clone();
        let painter = Painter::of(cx);
        let chip = |id: &'static str, label: &'static str| {
            theme
                .button(label, ButtonStyle::Ghost, Some(Fade::new(painter, id)))
                .control_size(ControlSize::Small)
                .id(id)
        };

        theme
            .control_group()
            .absolute()
            .bottom(px(10.))
            .right(px(10.))
            .invisible()
            .group_hover("cover", |row| row.visible())
            .child(
                chip("cover-shuffle", "Shuffle")
                    .on_click(cx.listener(|this, _, _, cx| this.shuffle_cover(cx))),
            )
            .child(
                chip("cover-change", "Change")
                    .on_click(cx.listener(|this, _, _, cx| this.pick_cover(cx))),
            )
            .child(
                chip("cover-remove", "Remove")
                    .on_click(cx.listener(|this, _, _, cx| this.remove_cover(cx))),
            )
    }

    /// One article in the sidebar, under the project that holds it.
    pub(crate) fn article_row(
        &self,
        project: usize,
        ix: usize,
        title: String,
        window: &mut Window,
        cx: &mut Context<Self>,
    ) -> impl IntoElement + use<> {
        let theme = Theme::of(cx).clone();
        let workspace = self.workspace.read(cx);
        let selected = !self.arranged(cx)
            && self.showing(cx) == Some(Pane::Article)
            && workspace.active == Some(project)
            && workspace
                .projects
                .get(project)
                .is_some_and(|open| open.article == Some(ix));
        let entry = Row::Article { project, ix };
        let article = workspace
            .projects
            .get(project)
            .and_then(|open| open.articles.get(ix));
        let archived = article.is_some_and(|article| article.archived);
        let tint = sidebar::tint(selected, archived, &theme);
        let id = SharedString::from(format!("article-{project}-{ix}"));

        sidebar::row(
            id,
            "article-row",
            selected,
            self.indent_of(entry, cx),
            &theme,
        )
        .child(
            icons::icon(icons::files::FileText)
                .size(px(14.))
                .flex_none()
                .text_color(tint),
        )
        // Display-only: the title is written at the head of the page, and
        // this row is never a second field for it.
        .child(
            div()
                .flex_1()
                .min_w_0()
                .truncate()
                .text_style(TextStyle::Body)
                .text_color(tint)
                .child(title),
        )
        .child(self.archive_button(
            format!("article-archive-{ix}"),
            "article-row",
            entry,
            archived,
            window,
            cx,
        ))
        .on_click(cx.listener(move |this, _, window, cx| {
            this.open_article(project, ix, window, cx);
        }))
    }
}