ratatui_toolkit/widgets/markdown_widget/extensions/toc/methods/entry_accessors.rs
1//! Entry accessor methods for TOC widget.
2
3use super::super::Toc;
4use crate::widgets::markdown_widget::state::toc_state::TocEntry;
5
6impl<'a> Toc<'a> {
7 /// Get the number of entries in the TOC.
8 ///
9 /// Delegates to the underlying TocState.
10 pub fn entry_count(&self) -> usize {
11 self.toc_state.entry_count()
12 }
13
14 /// Get all entries.
15 ///
16 /// Delegates to the underlying TocState.
17 pub fn entries(&self) -> &[TocEntry] {
18 self.toc_state.entries()
19 }
20
21 /// Get the target line number for a clicked entry.
22 ///
23 /// # Arguments
24 ///
25 /// * `entry_index` - The index of the clicked entry.
26 ///
27 /// # Returns
28 ///
29 /// The line number to scroll to, or None if the index is invalid.
30 pub fn click_to_line(&self, entry_index: usize) -> Option<usize> {
31 self.toc_state.get_entry(entry_index).map(|e| e.line_number)
32 }
33
34 /// Get the entry at a given index.
35 ///
36 /// # Arguments
37 ///
38 /// * `index` - The entry index.
39 ///
40 /// # Returns
41 ///
42 /// The entry, or None if the index is invalid.
43 pub fn get_entry(&self, index: usize) -> Option<&TocEntry> {
44 self.toc_state.get_entry(index)
45 }
46}