mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
fix(cli-rs): dispose session view keymap layers
LocationMissing, the scroll controls and the transcript dropped their Disposer handles, which keeps the layers registered. After a missing location session, Enter on home opened "Choose directory", and session commands stayed in the palette. Each view now disposes its layers when it replaces or drops them (carbon-2).
This commit is contained in:
parent
ccd8f2e17c
commit
1eece51bb1
3 changed files with 53 additions and 4 deletions
|
|
@ -6,7 +6,7 @@
|
|||
//! beside its prompt and hides the prompt while [`LocationMissing::active`].
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::rc::Rc;
|
||||
use std::rc::{Rc, Weak};
|
||||
use std::time::Duration;
|
||||
|
||||
use opencode_api::client::RequestOptions;
|
||||
|
|
@ -22,6 +22,7 @@ use crate::app::Tui;
|
|||
use crate::dialogs::worktrees::Selection;
|
||||
|
||||
pub struct LocationMissing {
|
||||
tui: Weak<Tui>,
|
||||
session: SessionID,
|
||||
root: View,
|
||||
active: Cell<bool>,
|
||||
|
|
@ -36,6 +37,7 @@ impl LocationMissing {
|
|||
.max_height(15)
|
||||
.visible(false);
|
||||
Self {
|
||||
tui: tui.weak(),
|
||||
session: session.clone(),
|
||||
root,
|
||||
active: Cell::new(false),
|
||||
|
|
@ -67,7 +69,7 @@ impl LocationMissing {
|
|||
}
|
||||
self.active.set(missing.is_some());
|
||||
self.root.clear();
|
||||
self.layer.take();
|
||||
dispose(tui, self.layer.take());
|
||||
let Some(directory) = missing else {
|
||||
self.root.visible(false);
|
||||
return;
|
||||
|
|
@ -97,6 +99,22 @@ impl LocationMissing {
|
|||
}
|
||||
}
|
||||
|
||||
impl Drop for LocationMissing {
|
||||
fn drop(&mut self) {
|
||||
if let Some(tui) = self.tui.upgrade() {
|
||||
dispose(&tui, self.layer.take());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Unregisters the `return` layer. A command may drop the view while the keymap runs it, so the layer goes
|
||||
/// afterwards; dropping a disposer does not unregister it.
|
||||
fn dispose(tui: &Tui, layer: Option<Disposer>) {
|
||||
if let Some(layer) = layer {
|
||||
tui.app.defer(move |_| layer.dispose());
|
||||
}
|
||||
}
|
||||
|
||||
/// `SessionLocationUnavailable`: `SessionQuestion` with the directory, the explanation, and one action.
|
||||
fn view(tui: &Tui, session: &SessionID, directory: &str) -> View {
|
||||
let app = &tui.app;
|
||||
|
|
|
|||
|
|
@ -80,6 +80,22 @@ struct Inner {
|
|||
layer: RefCell<Option<Disposer>>,
|
||||
}
|
||||
|
||||
impl Drop for Inner {
|
||||
fn drop(&mut self) {
|
||||
if let Some(tui) = self.tui.upgrade() {
|
||||
dispose(&tui, self.layer.take());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Unregisters the transcript's layer. A command may drop the view while the keymap runs it, so the layer goes
|
||||
/// afterwards; dropping a disposer does not unregister it.
|
||||
fn dispose(tui: &Tui, layer: Option<Disposer>) {
|
||||
if let Some(layer) = layer {
|
||||
tui.app.defer(move |_| layer.dispose());
|
||||
}
|
||||
}
|
||||
|
||||
/// The content height before rows mounted above, and the frame it is from.
|
||||
struct Pin {
|
||||
height: f32,
|
||||
|
|
@ -407,7 +423,7 @@ impl Inner {
|
|||
};
|
||||
inner.hide_thinking.set(!inner.hide_thinking.get());
|
||||
inner.render(&tui, |_| true);
|
||||
inner.layer.take();
|
||||
dispose(&tui, inner.layer.take());
|
||||
inner.register(&tui);
|
||||
tui.dialogs.clear();
|
||||
})
|
||||
|
|
|
|||
|
|
@ -75,6 +75,21 @@ impl Controls {
|
|||
}
|
||||
}
|
||||
|
||||
impl Drop for Inner {
|
||||
fn drop(&mut self) {
|
||||
if let Some(tui) = self.tui.upgrade() {
|
||||
dispose(&tui, std::mem::take(&mut *self.layers.borrow_mut()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Unregisters `layers`. A command may drop the view while the keymap runs it, so they go afterwards;
|
||||
/// dropping a disposer does not unregister its layer.
|
||||
fn dispose(tui: &Tui, layers: Vec<Disposer>) {
|
||||
tui.app
|
||||
.defer(move |_| layers.into_iter().for_each(Disposer::dispose));
|
||||
}
|
||||
|
||||
impl Inner {
|
||||
fn install(&self, tui: &Tui) {
|
||||
self.configure(&tui.settings.info());
|
||||
|
|
@ -166,7 +181,7 @@ impl Inner {
|
|||
/// the scroll keys in every mode, `session.first` and `session.last` also while no editor has
|
||||
/// focus, and the rest in the base mode.
|
||||
pub(super) fn register(&self, tui: &Tui) {
|
||||
self.layers.borrow_mut().clear();
|
||||
dispose(tui, std::mem::take(&mut *self.layers.borrow_mut()));
|
||||
let command = |id: &str, title: &str, run: fn(&Inner, &Tui)| {
|
||||
let weak = self.this.clone();
|
||||
TuiCommand::new(id, move |_, _| {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue