### Links
Maybe we can do it in TextLayout in GPUI:
fda6eda3c2/crates/gpui/src/elements/text.rs (L309)
## Demo
https://github.com/user-attachments/assets/abbebee7-df8f-4067-86a7-15bc1a4c44cd
## Todo
- [x] Test for HTML View.
- [x] CodeBlock selection support.
- [x] Selection lines sometimes incorrect.
- [x] Listener Bounds changed to unselect.
33 lines
714 B
Rust
33 lines
714 B
Rust
use gpui::{App, Entity, Global};
|
|
|
|
use crate::text::TextViewState;
|
|
|
|
pub(crate) fn init(cx: &mut App) {
|
|
cx.set_global(GlobalState::new());
|
|
}
|
|
|
|
impl Global for GlobalState {}
|
|
|
|
pub(crate) struct GlobalState {
|
|
pub(crate) text_view_state_stack: Vec<Entity<TextViewState>>,
|
|
}
|
|
|
|
impl GlobalState {
|
|
pub(crate) fn new() -> Self {
|
|
Self {
|
|
text_view_state_stack: Vec::new(),
|
|
}
|
|
}
|
|
|
|
pub(crate) fn global(cx: &App) -> &Self {
|
|
cx.global::<Self>()
|
|
}
|
|
|
|
pub(crate) fn global_mut(cx: &mut App) -> &mut Self {
|
|
cx.global_mut::<Self>()
|
|
}
|
|
|
|
pub(crate) fn text_view_state(&self) -> Option<&Entity<TextViewState>> {
|
|
self.text_view_state_stack.last()
|
|
}
|
|
}
|