Skip to content

Commit 93ef0ac

Browse files
liliwilsonoz-agent
andauthored
Escape vim insert mode before leaving ampersand handoff (#11083)
## Description Fixes an issue with vim escaping in the ampersand handoff view so that you can escape into normal mode before you escape handoff setup. Copies the same logic we use for doing this when the inline history menu is open. ## Testing Unit test and I tested locally! ## Agent Mode - [x] Warp Agent Mode - This PR was created via Warp's AI Agent Mode _Conversation: https://staging.warp.dev/conversation/2b3ae6bd-0e53-4ecb-bbc7-581dd80e84b6_ _Run: https://oz.staging.warp.dev/runs/019e2df1-c5c2-7394-a922-0324d06cd929_ _This PR was generated with [Oz](https://warp.dev/oz)._ Co-authored-by: Oz <oz-agent@warp.dev>
1 parent c46846f commit 93ef0ac

2 files changed

Lines changed: 67 additions & 3 deletions

File tree

app/src/terminal/input.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8501,13 +8501,16 @@ impl Input {
85018501
!context_model.pending_context_block_ids().is_empty()
85028502
|| context_model.pending_context_selected_text().is_some()
85038503
};
8504-
if vim_mode == Some(VimMode::Insert)
8504+
let should_escape_vim_before_dismissing = (vim_mode == Some(VimMode::Insert)
85058505
&& (self.suggestions_mode_model.as_ref(ctx).is_history_up()
85068506
|| self
85078507
.suggestions_mode_model
85088508
.as_ref(ctx)
8509-
.is_inline_history_menu())
8510-
{
8509+
.is_inline_history_menu()))
8510+
|| (vim_mode == Some(VimMode::Insert)
8511+
&& self.prefix_mode(ctx) == InputPrefixMode::CloudHandoff);
8512+
8513+
if should_escape_vim_before_dismissing {
85118514
self.editor.update(ctx, |editor, editor_ctx| {
85128515
editor.handle_action(&EditorAction::VimEscape, editor_ctx);
85138516
});

app/src/terminal/input_tests.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6031,6 +6031,67 @@ fn test_cloud_handoff_prefix_activates_in_powershell_when_nld_disabled() {
60316031
});
60326032
}
60336033
#[test]
6034+
fn test_cloud_handoff_prefix_vim_escape_exits_insert_before_handoff_mode() {
6035+
App::test((), |mut app| async move {
6036+
let _agent_view_flag = FeatureFlag::AgentView.override_enabled(true);
6037+
let _oz_handoff_flag = FeatureFlag::OzHandoff.override_enabled(true);
6038+
let _handoff_local_cloud_flag = FeatureFlag::HandoffLocalCloud.override_enabled(true);
6039+
6040+
initialize_app(&mut app);
6041+
enable_vim_mode(&mut app);
6042+
AISettings::handle(&app).update(&mut app, |ai_settings, ctx| {
6043+
let _ = ai_settings
6044+
.ai_autodetection_enabled_internal
6045+
.set_value(false, ctx);
6046+
});
6047+
let terminal = add_window_with_bootstrapped_terminal(&mut app, None, None).await;
6048+
let (input, editor) = terminal.read(&app, |terminal, ctx| {
6049+
let input = terminal.input().clone();
6050+
let editor = input.as_ref(ctx).editor().clone();
6051+
(input, editor)
6052+
});
6053+
enter_fullscreen_agent_view_for_test(&terminal, &mut app);
6054+
6055+
input.update(&mut app, |input, ctx| {
6056+
input.activate_cloud_handoff_compose(HandoffEntryPoint::Ampersand, ctx);
6057+
input.user_insert("fix tests", ctx);
6058+
});
6059+
6060+
editor.read(&app, |editor, ctx| {
6061+
assert_eq!(editor.vim_mode(ctx), Some(VimMode::Insert));
6062+
});
6063+
input.read(&app, |input, ctx| {
6064+
assert_eq!(input.buffer_text(ctx), "fix tests");
6065+
assert_eq!(input.prefix_mode(ctx), InputPrefixMode::CloudHandoff);
6066+
});
6067+
6068+
editor.update(&mut app, |editor, ctx| {
6069+
editor.escape(ctx);
6070+
});
6071+
6072+
editor.read(&app, |editor, ctx| {
6073+
assert_eq!(editor.vim_mode(ctx), Some(VimMode::Normal));
6074+
});
6075+
input.read(&app, |input, ctx| {
6076+
assert_eq!(input.buffer_text(ctx), "fix tests");
6077+
assert_eq!(input.prefix_mode(ctx), InputPrefixMode::CloudHandoff);
6078+
});
6079+
6080+
editor.update(&mut app, |editor, ctx| {
6081+
editor.escape(ctx);
6082+
});
6083+
6084+
editor.read(&app, |editor, ctx| {
6085+
assert_eq!(editor.vim_mode(ctx), Some(VimMode::Normal));
6086+
});
6087+
input.read(&app, |input, ctx| {
6088+
assert_eq!(input.buffer_text(ctx), "fix tests");
6089+
assert_eq!(input.prefix_mode(ctx), InputPrefixMode::None);
6090+
assert!(!input.handoff_compose_state.as_ref(ctx).is_active());
6091+
});
6092+
});
6093+
}
6094+
#[test]
60346095
fn test_cloud_handoff_prefix_ignores_terminal_input_mode_toggle() {
60356096
App::test((), |mut app| async move {
60366097
let _agent_view_flag = FeatureFlag::AgentView.override_enabled(true);

0 commit comments

Comments
 (0)