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
//! Shared paste policy for single-line modal text fields.
//!
//! Every text-input modal (search/replace, command palette, save-copy
//! path, export-theme name, insert-table dimensions, theme/section
//! filters, settings field editor) holds a *single line* of text. A
//! bracketed paste, however, can carry newlines and arbitrarily large
//! content. [`sanitize_paste`] is the single source of truth that
//! flattens such a paste into something a one-line field can accept:
//! control characters (newlines, tabs, …) are dropped so a multi-line
//! clipboard collapses to one line, and the result is capped at
//! [`PASTE_CHAR_CAP`] characters so pasting a whole document can't blow
//! up a prompt.
//!
//! Field-specific filtering (e.g. the digits-only insert-table fields)
//! is layered on top by each state's own `paste` method — this helper
//! only owns the line-flattening and length cap that every field shares.
/// Maximum number of characters a single paste may contribute to a
/// field. Generous enough for long file paths (Linux `PATH_MAX` is
/// 4096) and long search/replace terms, while still guarding against
/// pasting an entire document into a one-line prompt.
pub const PASTE_CHAR_CAP: usize = 1024;
/// Flatten a bracketed paste for insertion into a single-line field:
/// drop every control character (so newlines/tabs can't break the
/// layout) and truncate to [`PASTE_CHAR_CAP`] characters.