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
//! Operator-pending state for text object range communication.
//!
//! This module provides [`OperatorPendingState`], a session extension that
//! enables communication between text object commands and operator resolvers.
//!
//! # Design
//!
//! Text objects (like `iw`, `aw`, `i"`) calculate ranges directly instead of
//! moving the cursor. They need a way to communicate that range to the
//! operator resolver (like `VimDeleteResolver`).
//!
//! This is a **mechanism** (session driver) that enables **policy** (modules)
//! to communicate. The vim module's `VimSessionState` can delegate to this,
//! or modules can use it directly.
//!
//! # Example
//!
//! ```ignore
//! use reovim_driver_session::{OperatorPendingState, TextObjRange};
//! use reovim_kernel::api::v1::Position;
//!
//! // In a text object command:
//! let state = runtime.ext_mut::<OperatorPendingState>();
//! state.set_textobj_range(TextObjRange::characterwise(
//! Position::new(0, 0),
//! Position::new(0, 5),
//! ));
//!
//! // In an operator resolver's on_command_complete:
//! let state = extensions.get_mut::<OperatorPendingState>();
//! if let Some(range) = state.and_then(|s| s.take_textobj_range()) {
//! // Use the range for the operator
//! }
//! ```
use crate::;
/// Session extension for operator-pending state.
///
/// This provides a communication channel between text object commands
/// and operator resolvers. Text objects SET the range, operators CONSUME it.
///
/// # Thread Safety
///
/// This implements `Send + Sync` as required by `SessionExtension`.
/// Access should be synchronized at the session level.