fresh/model/buffer/file_kind.rs
1//! File-kind classification for a `TextBuffer`.
2//!
3//! Owns the three flags that describe "what sort of file is this":
4//! large-file mode (lazy chunked loading), whether the line-feed scan
5//! has run over it, and whether the content is binary (read-only,
6//! rendered as code points). Composed inside `TextBuffer` as the
7//! `file_kind` field.
8
9/// File-kind flags for a `TextBuffer`.
10#[derive(Debug, Clone, Copy, Default)]
11pub struct BufferFileKind {
12 /// Is this a large file (no line indexing, lazy loading enabled)?
13 large_file: bool,
14
15 /// Has a line-feed scan been performed on this large file?
16 ///
17 /// When true, piece-tree leaves have accurate `line_feed_cnt`
18 /// values, and edits will ensure the relevant chunk is loaded
19 /// before splitting so that `compute_line_feeds_static` can
20 /// recount accurately.
21 line_feeds_scanned: bool,
22
23 /// Is this a binary file? Binary files are opened read-only and
24 /// render unprintable characters as code points.
25 is_binary: bool,
26}
27
28impl BufferFileKind {
29 pub fn new(large_file: bool, is_binary: bool) -> Self {
30 Self {
31 large_file,
32 line_feeds_scanned: false,
33 is_binary,
34 }
35 }
36
37 pub fn is_large_file(&self) -> bool {
38 self.large_file
39 }
40
41 pub fn has_line_feed_scan(&self) -> bool {
42 self.line_feeds_scanned
43 }
44
45 pub fn is_binary(&self) -> bool {
46 self.is_binary
47 }
48
49 pub(super) fn set_large_file(&mut self, v: bool) {
50 self.large_file = v;
51 }
52
53 pub(super) fn mark_line_feed_scan_complete(&mut self) {
54 self.line_feeds_scanned = true;
55 }
56
57 pub(super) fn set_binary(&mut self, v: bool) {
58 self.is_binary = v;
59 }
60}