mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Add a one-time composer starfield for new Astra tasks (#46096)
## What changed Show a brief starfield in the empty composer when a new task starts with Astra or the user selects Astra through `/model` before entering ordinary prompt content. - Respect `tui.animations`, `tui.whimsy`, and true-color support; protect the placeholder and cursor and fade out by 15 seconds. - Preserve eligibility through recognized slash commands, but permanently dismiss it after ordinary draft content, attachments, or work. Carry draft eligibility through startup and disconnected editing. - Exclude resumed and forked tasks, and verify model-picker changes against the originating task and effective model when applied. - Hide the effect during overlays or focus loss without restarting its deadline or scheduling hidden animation frames. ## Testing Add regression tests and snapshots for task eligibility, model-picker transitions, draft and paste handling, history search, overlays, submissions, rendering protection, and animation expiry. GitOrigin-RevId: 832705543e9cae1d561125ece853a16c4eefe627
This commit is contained in:
1 parent
787823cf95
commit
f3da3861c5
45 files changed
+3251
-178
No files matched your search
@@ -16,7 +16,8 @@
|
||||
//! latest history entry by itself. Typing or pasting a query restarts traversal from newest to oldest,
|
||||
//! repeated Ctrl+R/Up and Ctrl+S/Down move between unique matches, `Enter` accepts the current
|
||||
//! preview as an editable draft, and `Esc` or Ctrl+C restores the exact draft that existed before
|
||||
//! search started.
|
||||
//! search started. Buffered keys are integrated before that snapshot without reclassifying them as
|
||||
//! an explicit paste. Only accepting a nonempty preview dismisses any unused Astra sparkle opportunity.
|
||||
|
||||
use std::ops::Range;
|
||||
|
||||
@@ -110,14 +111,14 @@ impl ChatComposer {
|
||||
|
||||
/// Opens footer-owned reverse history search without previewing history yet.
|
||||
///
|
||||
/// Entering search mode first flushes pending paste-burst text, then snapshots the full
|
||||
/// composer draft, clears any file/search popup state, and resets history traversal. The first
|
||||
/// visible match is produced only after the footer query becomes non-empty, which keeps Ctrl+R
|
||||
/// from replacing an empty composer with the latest prompt before the user has searched for
|
||||
/// anything.
|
||||
/// Entering search mode first integrates already-classified paste-burst text with
|
||||
/// [`Self::apply_paste`], then snapshots the full composer draft, clears any file/search popup
|
||||
/// state, and resets history traversal. The first visible match is produced only after the
|
||||
/// footer query becomes non-empty, which keeps Ctrl+R from replacing an empty composer with
|
||||
/// the latest prompt before the user has searched for anything.
|
||||
pub(super) fn begin_history_search(&mut self) -> (InputResult, bool) {
|
||||
if let Some(pasted) = self.draft.paste_burst.flush_before_modified_input() {
|
||||
self.handle_paste(pasted);
|
||||
self.apply_paste(pasted);
|
||||
}
|
||||
self.draft.paste_burst.clear_window_after_non_char();
|
||||
|
||||
@@ -206,6 +207,9 @@ impl ChatComposer {
|
||||
.is_some_and(|search| matches!(search.status, HistorySearchStatus::Match))
|
||||
{
|
||||
self.history_search = None;
|
||||
if !self.is_empty() {
|
||||
self.dismiss_sparkle();
|
||||
}
|
||||
self.history.reset_search();
|
||||
self.footer.mode = reset_mode_after_activity(self.footer.mode);
|
||||
self.move_cursor_to_end();
|
||||
@@ -259,7 +263,7 @@ impl ChatComposer {
|
||||
if let Some(search) = self.history_search.as_mut() {
|
||||
search.status = HistorySearchStatus::Idle;
|
||||
}
|
||||
self.restore_draft(original_draft);
|
||||
self.with_sparkle_history_preview(|composer| composer.restore_draft(original_draft));
|
||||
return InputResult::None;
|
||||
}
|
||||
let result = self.history.search(
|
||||
@@ -282,7 +286,7 @@ impl ChatComposer {
|
||||
search.status = HistorySearchStatus::Searching;
|
||||
let query = search.query.clone();
|
||||
let original_draft = search.original_draft.clone();
|
||||
self.restore_draft(original_draft);
|
||||
self.with_sparkle_history_preview(|composer| composer.restore_draft(original_draft));
|
||||
if query.is_empty() {
|
||||
self.history.reset_search();
|
||||
if let Some(search) = self.history_search.as_mut() {
|
||||
@@ -311,7 +315,7 @@ impl ChatComposer {
|
||||
};
|
||||
self.history.reset_navigation();
|
||||
self.footer.mode = reset_mode_after_activity(self.footer.mode);
|
||||
self.restore_draft(search.original_draft);
|
||||
self.with_sparkle_history_preview(|composer| composer.restore_draft(search.original_draft));
|
||||
self.vim_history = search.original_vim_history;
|
||||
self.draft
|
||||
.textarea
|
||||
@@ -333,7 +337,7 @@ impl ChatComposer {
|
||||
if let Some(search) = self.history_search.as_mut() {
|
||||
search.status = HistorySearchStatus::Match;
|
||||
}
|
||||
self.apply_history_entry(entry);
|
||||
self.with_sparkle_history_preview(|composer| composer.apply_history_entry(entry));
|
||||
}
|
||||
HistorySearchResult::Pending => {
|
||||
if let Some(search) = self.history_search.as_mut() {
|
||||
@@ -358,12 +362,21 @@ impl ChatComposer {
|
||||
};
|
||||
}
|
||||
if let Some(original_draft) = original_draft {
|
||||
self.restore_draft(original_draft);
|
||||
self.with_sparkle_history_preview(|composer| {
|
||||
composer.restore_draft(original_draft)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn with_sparkle_history_preview(&mut self, preview: impl FnOnce(&mut Self)) {
|
||||
let previous = self.sparkle.history_preview;
|
||||
self.sparkle.history_preview = true;
|
||||
preview(self);
|
||||
self.sparkle.history_preview = previous;
|
||||
}
|
||||
|
||||
/// Builds the footer line shown while reverse history search is active.
|
||||
///
|
||||
/// The footer displays the query as the editable field and uses the status to decide whether
|
||||
|
||||
@@ -66,10 +66,10 @@ impl ChatComposer {
|
||||
|| self.vim_normal_keymap.move_down.is_pressed(key)))
|
||||
}
|
||||
|
||||
/// Finish buffered typing before another answer takes over this editor.
|
||||
/// Integrate already-classified buffered typing before another answer takes over this editor.
|
||||
pub(crate) fn flush_pending_input(&mut self) {
|
||||
if let Some(text) = self.draft.paste_burst.flush_before_modified_input() {
|
||||
self.handle_paste(text);
|
||||
self.apply_paste(text);
|
||||
}
|
||||
self.draft.paste_burst.clear_after_explicit_paste();
|
||||
}
|
||||
|
||||
@@ -1,8 +1,124 @@
|
||||
//! Capture raw paste tabs before completion and submission shortcuts see them.
|
||||
//! Classify and integrate composer pastes and capture raw paste tabs before completion or submission.
|
||||
|
||||
use super::*;
|
||||
use crate::bottom_pane::paste_burst::FlushResult;
|
||||
|
||||
impl ChatComposer {
|
||||
/// Classify an explicit paste before integrating text shared with the buffered key path.
|
||||
pub fn handle_paste(&mut self, pasted: String) -> bool {
|
||||
self.note_sparkle_paste(&pasted);
|
||||
self.apply_paste(pasted)
|
||||
}
|
||||
|
||||
/// Enable or disable paste-burst handling.
|
||||
///
|
||||
/// `disable_paste_burst` is an escape hatch for terminals/platforms where the burst heuristic
|
||||
/// is unwanted or has already been handled elsewhere.
|
||||
///
|
||||
/// When transitioning from enabled → disabled, we "defuse" any in-flight burst state so it
|
||||
/// cannot affect subsequent normal typing:
|
||||
///
|
||||
/// - First, flush held/buffered text via [`PasteBurst::flush_before_modified_input`] and
|
||||
/// integrate it with [`Self::apply_paste`]. Its key events have already been classified;
|
||||
/// [`Self::handle_paste`] classifies explicit terminal pastes before using the same
|
||||
/// integration path (large-paste placeholders, image-path detection, and popup sync).
|
||||
/// - Then clear the burst timing and Enter-suppression window via
|
||||
/// [`PasteBurst::clear_after_explicit_paste`].
|
||||
///
|
||||
/// We intentionally do not use `clear_window_after_non_char()` here: it clears timing state
|
||||
/// without emitting any buffered text, which can leave a non-empty buffer unable to flush
|
||||
/// later (because `flush_if_due()` relies on `last_plain_char_time` to time out).
|
||||
pub(crate) fn set_disable_paste_burst(&mut self, disabled: bool) {
|
||||
let was_disabled = self.draft.disable_paste_burst;
|
||||
self.draft.disable_paste_burst = disabled;
|
||||
if disabled && !was_disabled {
|
||||
if let Some(pasted) = self.draft.paste_burst.flush_before_modified_input() {
|
||||
self.apply_paste(pasted);
|
||||
}
|
||||
self.draft.paste_burst.clear_after_explicit_paste();
|
||||
}
|
||||
}
|
||||
|
||||
/// Applies any due `PasteBurst` flush at time `now`.
|
||||
///
|
||||
/// Converts [`PasteBurst::flush_if_due`] results into concrete textarea mutations.
|
||||
/// Buffered keys have already been classified; paste results use [`Self::apply_paste`].
|
||||
///
|
||||
/// Callers:
|
||||
///
|
||||
/// - UI ticks via [`ChatComposer::flush_paste_burst_if_due`], so held first-chars can render.
|
||||
/// - Input handling via [`ChatComposer::handle_input_basic`], so a due burst does not lag.
|
||||
pub(super) fn handle_paste_burst_flush(&mut self, now: Instant) -> bool {
|
||||
match self.draft.paste_burst.flush_if_due(now) {
|
||||
FlushResult::Paste(pasted) => {
|
||||
self.apply_paste(pasted);
|
||||
true
|
||||
}
|
||||
FlushResult::Typed(ch) => {
|
||||
self.insert_str(ch.to_string().as_str());
|
||||
true
|
||||
}
|
||||
FlushResult::None => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Integrate pasted text into the composer.
|
||||
///
|
||||
/// Both input paths integrate their text here:
|
||||
///
|
||||
/// - Real/explicit paste events surfaced by the terminal, and
|
||||
/// - Non-bracketed "paste bursts" that
|
||||
/// [`PasteBurst`](crate::bottom_pane::paste_burst::PasteBurst) buffers and later flushes here.
|
||||
///
|
||||
/// Behavior:
|
||||
///
|
||||
/// - If history search is active, inserts nonempty text into its query and ignores empty pastes.
|
||||
/// - If Vim search is active, inserts text into its query.
|
||||
/// - Otherwise, if the paste is larger than `LARGE_PASTE_CHAR_THRESHOLD` chars, inserts a
|
||||
/// placeholder element (expanded on submit) and stores the full text in `pending_pastes`.
|
||||
/// - Otherwise, if the paste looks like an image path, attaches the image and inserts a
|
||||
/// trailing space so the user can keep typing naturally.
|
||||
/// - Otherwise, inserts the pasted text directly into the textarea.
|
||||
///
|
||||
/// Composer edits clear paste-burst Enter suppression and sync popups.
|
||||
pub(super) fn apply_paste(&mut self, pasted: String) -> bool {
|
||||
let pasted = pasted.replace("\r\n", "\n").replace('\r', "\n");
|
||||
let pasted = sanitize_user_text(pasted.into());
|
||||
if self.history_search.is_some() {
|
||||
if !pasted.is_empty() {
|
||||
self.update_history_search_query(|query| query.push_str(&pasted));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if let Some(query) = self.draft.textarea.vim_query_mut() {
|
||||
query.editor.insert_str(&pasted);
|
||||
return true;
|
||||
}
|
||||
let started_vim_edit = self.begin_direct_vim_edit();
|
||||
let char_count = pasted.chars().count();
|
||||
if char_count > LARGE_PASTE_CHAR_THRESHOLD {
|
||||
let placeholder = self.next_large_paste_placeholder(char_count);
|
||||
self.draft.textarea.insert_element(&placeholder);
|
||||
self.draft
|
||||
.pending_pastes
|
||||
.push((placeholder, pasted.into_owned()));
|
||||
} else if char_count > 1
|
||||
&& self.image_paste_enabled()
|
||||
&& self.handle_paste_image_path(&pasted)
|
||||
{
|
||||
let cursor = self.draft.textarea.cursor();
|
||||
self.draft.textarea.insert_str_at(cursor, " ");
|
||||
} else {
|
||||
self.insert_str(&pasted);
|
||||
}
|
||||
self.draft.paste_burst.clear_after_explicit_paste();
|
||||
self.sync_popups();
|
||||
if started_vim_edit {
|
||||
self.finish_vim_edit();
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
pub(super) fn handle_paste_tab(&mut self, key: KeyEvent, now: Instant) -> bool {
|
||||
if key.code != KeyCode::Tab
|
||||
|| !key.modifiers.is_empty()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Offline editing retains the draft in place.
|
||||
//! Paste Enter handling is shared with normal submission so buffered newlines survive both paths.
|
||||
//! Offline draft edits also consume the Astra sparkle opportunity before rendering.
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -66,7 +67,14 @@ impl ChatComposer {
|
||||
if !matches!(key.code, KeyCode::Enter | KeyCode::Tab)
|
||||
&& matches!(key.kind, KeyEventKind::Press | KeyEventKind::Repeat)
|
||||
{
|
||||
self.handle_input_basic(key);
|
||||
// Null is sent internally to clean up on disconnect or expand a paste; it isn't an edit.
|
||||
let before = if key.code == KeyCode::Null {
|
||||
None
|
||||
} else {
|
||||
self.before_sparkle_editor_key(key)
|
||||
};
|
||||
let (result, _) = self.handle_input_basic(key);
|
||||
self.after_sparkle_key(before, &result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
---
|
||||
source: tui/src/bottom_pane/chat_composer/sparkle_tests.rs
|
||||
expression: "format!(\"command during startup:\\n{}\\n\\nafter command:\\n{}\", text(&pending),\ntext(&completed))"
|
||||
---
|
||||
command during startup:
|
||||
|
||||
› /status
|
||||
|
||||
/status show current session configuration and token usage
|
||||
/statusline configure which items appear in the status line
|
||||
|
||||
after command:
|
||||
⠈ ⢀ ⠁ ⠂
|
||||
›⠁Ask Codex to do anything ⠈ ⠁
|
||||
⢀ ⠠ ⠄ ⠠ ⢀ ⠠ ⡀
|
||||
? for shortcuts 100% context left
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
---
|
||||
source: tui/src/bottom_pane/chat_composer/sparkle_tests.rs
|
||||
expression: "snapshots.join(\"\\n\\n\")"
|
||||
---
|
||||
expires while open: false
|
||||
initial:
|
||||
⠈ ⢀ ⠁ ⠂
|
||||
›⠁Ask Codex to do anything ⠈ ⠁
|
||||
⢀ ⠠ ⠄ ⠠ ⢀ ⠠ ⡀
|
||||
? for shortcuts 100% context left
|
||||
searching:
|
||||
|
||||
› stored draft
|
||||
|
||||
reverse-i-search: stored enter accept · esc cancel
|
||||
after escape:
|
||||
⠁ ⡀ ⠄ ⠄ ⠄
|
||||
› Ask Codex to do anything ⠈
|
||||
⠠ ⠠ ⢀ ⢀ ⡀ ⠄
|
||||
? for shortcuts 100% context left
|
||||
|
||||
expires while open: true
|
||||
initial:
|
||||
⠈ ⢀ ⠁ ⠂
|
||||
›⠁Ask Codex to do anything ⠈ ⠁
|
||||
⢀ ⠠ ⠄ ⠠ ⢀ ⠠ ⡀
|
||||
? for shortcuts 100% context left
|
||||
searching:
|
||||
|
||||
› stored draft
|
||||
|
||||
reverse-i-search: stored enter accept · esc cancel
|
||||
after escape:
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
? for shortcuts 100% context left
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
---
|
||||
source: tui/src/bottom_pane/chat_composer/sparkle_tests.rs
|
||||
expression: "snapshots.join(\"\\n\\n\")"
|
||||
---
|
||||
gpt-6-astra
|
||||
before disconnect:
|
||||
⠈ ⢀ ⠁ ⠂
|
||||
›⠁Ask Codex to do anything ⠈ ⠁
|
||||
⢀ ⠠ ⠄ ⠠ ⢀ ⠠ ⡀
|
||||
? for shortcuts 100% context left
|
||||
after typing and erasing without rendering:
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
? for shortcuts 100% context left
|
||||
|
||||
gpt-5.5
|
||||
before disconnect:
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
? for shortcuts 100% context left
|
||||
after typing and erasing without rendering:
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
? for shortcuts 100% context left
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
---
|
||||
source: tui/src/bottom_pane/chat_composer/sparkle_tests.rs
|
||||
expression: "snapshots.join(\"\\n\\n\")"
|
||||
---
|
||||
accept:
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
? for shortcuts 100% context left
|
||||
|
||||
escape:
|
||||
⠈ ⢀ ⠁ ⠂
|
||||
›⠁Ask Codex to do anything ⠈ ⠁
|
||||
⢀ ⠠ ⠄ ⠠ ⢀ ⠠ ⡀
|
||||
? for shortcuts 100% context left
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
---
|
||||
source: tui/src/bottom_pane/chat_composer/sparkle_tests.rs
|
||||
expression: "snapshots.join(\"\\n\\n\")"
|
||||
---
|
||||
gpt-6-astra
|
||||
searching with an explicit pasted query:
|
||||
|
||||
› history prompt
|
||||
|
||||
reverse-i-search: history enter accept · esc cancel
|
||||
after canceling and erasing the slash:
|
||||
⠁ ⡀ ⠄ ⠄ ⠄
|
||||
› Ask Codex to do anything ⠈
|
||||
⠠ ⠠ ⢀ ⢀ ⡀ ⠄
|
||||
? for shortcuts 100% context left
|
||||
after /model selects Astra:
|
||||
⠁ ⡀ ⠄ ⠄ ⠄
|
||||
› Ask Codex to do anything ⠈
|
||||
⠠ ⠠ ⢀ ⢀ ⡀ ⠄
|
||||
? for shortcuts 100% context left
|
||||
|
||||
gpt-5.5
|
||||
searching with an explicit pasted query:
|
||||
|
||||
› history prompt
|
||||
|
||||
reverse-i-search: history enter accept · esc cancel
|
||||
after canceling and erasing the slash:
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
? for shortcuts 100% context left
|
||||
after /model selects Astra:
|
||||
⠈ ⢀ ⠁ ⠂
|
||||
›⠁Ask Codex to do anything ⠈ ⠁
|
||||
⢀ ⠠ ⠄ ⠠ ⢀ ⠠ ⡀
|
||||
? for shortcuts 100% context left
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
---
|
||||
source: tui/src/bottom_pane/chat_composer/sparkle_tests.rs
|
||||
expression: "snapshots.join(\"\\n\\n\")"
|
||||
---
|
||||
gpt-6-astra
|
||||
after immediately canceling the held slash:
|
||||
⠈ ⢀ ⠁ ⠂
|
||||
›⠁Ask Codex to do anything ⠈ ⠁
|
||||
⢀ ⠠ ⠄ ⠠ ⢀ ⠠ ⡀
|
||||
? for shortcuts 100% context left
|
||||
after /model:
|
||||
⠈ ⢀ ⠁ ⠂
|
||||
›⠁Ask Codex to do anything ⠈ ⠁
|
||||
⢀ ⠠ ⠄ ⠠ ⢀ ⠠ ⡀
|
||||
? for shortcuts 100% context left
|
||||
|
||||
gpt-5.5
|
||||
after immediately canceling the held slash:
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
? for shortcuts 100% context left
|
||||
after /model:
|
||||
⠈ ⢀ ⠁ ⠂
|
||||
›⠁Ask Codex to do anything ⠈ ⠁
|
||||
⢀ ⠠ ⠄ ⠠ ⢀ ⠠ ⡀
|
||||
? for shortcuts 100% context left
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
---
|
||||
source: tui/src/bottom_pane/chat_composer/sparkle_tests.rs
|
||||
expression: "snapshots.join(\"\\n\\n\")"
|
||||
---
|
||||
expires during help: false
|
||||
initial:
|
||||
⠈ ⢀ ⠁ ⠂
|
||||
›⠁Ask Codex to do anything ⠈ ⠁
|
||||
⢀ ⠠ ⠄ ⠠ ⢀ ⠠ ⡀
|
||||
? for shortcuts 100% context left
|
||||
shortcut help:
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
/ for commands ! for shell commands
|
||||
ctrl + j for newline tab to submit message
|
||||
@ for file paths ctrl + v to paste images
|
||||
ctrl + g to edit in external editor esc esc to edit previous message
|
||||
ctrl + r search history ctrl + c to exit
|
||||
⌥ + , reasoning down ⌥ + . reasoning up
|
||||
ctrl + t to view transcript
|
||||
|
||||
customize shortcuts with /keymap
|
||||
after closing:
|
||||
⠁ ⡀ ⠄ ⠄ ⠄
|
||||
› Ask Codex to do anything ⠈
|
||||
⠠ ⠠ ⢀ ⢀ ⡀ ⠄
|
||||
? for shortcuts 100% context left
|
||||
|
||||
expires during help: true
|
||||
initial:
|
||||
⠈ ⢀ ⠁ ⠂
|
||||
›⠁Ask Codex to do anything ⠈ ⠁
|
||||
⢀ ⠠ ⠄ ⠠ ⢀ ⠠ ⡀
|
||||
? for shortcuts 100% context left
|
||||
shortcut help:
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
/ for commands ! for shell commands
|
||||
ctrl + j for newline tab to submit message
|
||||
@ for file paths ctrl + v to paste images
|
||||
ctrl + g to edit in external editor esc esc to edit previous message
|
||||
ctrl + r search history ctrl + c to exit
|
||||
⌥ + , reasoning down ⌥ + . reasoning up
|
||||
ctrl + t to view transcript
|
||||
|
||||
customize shortcuts with /keymap
|
||||
after closing:
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
? for shortcuts 100% context left
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
---
|
||||
source: tui/src/bottom_pane/chat_composer/sparkle_tests.rs
|
||||
expression: "snapshots.join(\"\\n\\n\")"
|
||||
---
|
||||
shortcut help:
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
/ for commands ! for shell commands
|
||||
ctrl + j for newline tab to submit message
|
||||
@ for file paths ctrl + v to paste images
|
||||
ctrl + g to edit in external editor esc esc to edit previous message
|
||||
ctrl + r search history ctrl + c to exit
|
||||
⌥ + , reasoning down ⌥ + . reasoning up
|
||||
ctrl + t to view transcript
|
||||
|
||||
customize shortcuts with /keymap
|
||||
|
||||
after /model selects Astra:
|
||||
⠈ ⢀ ⠁ ⠂
|
||||
›⠁Ask Codex to do anything ⠈ ⠁
|
||||
⢀ ⠠ ⠄ ⠠ ⢀ ⠠ ⡀
|
||||
? for shortcuts 100% context left
|
||||
|
||||
literal pasted question mark:
|
||||
|
||||
› ?
|
||||
|
||||
100% context left
|
||||
|
||||
after clearing and selecting Astra:
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
? for shortcuts 100% context left
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
---
|
||||
source: tui/src/bottom_pane/chat_composer/sparkle_tests.rs
|
||||
expression: "format!(\"before fade:\\n{}\\nfading:\\n{}\\nfinished:\\n{}\", text(&last),\ntext(&fading), text(&finished))"
|
||||
---
|
||||
before fade:
|
||||
⠁ ⠄ ⢀ ⠈ ⠁ ⡀ ⠂ ⠄
|
||||
› Ask Codex to do anything ⠈ ⠈ ⠂ ⠁ ⠂
|
||||
⢀⠐ ⠄ ⠄ ⢀ ⠠ ⠄
|
||||
? for shortcuts 100% context left
|
||||
fading:
|
||||
⠁ ⠄ ⢀ ⠈ ⠁ ⡀ ⠂ ⠄
|
||||
› Ask Codex to do anything ⠈ ⠈ ⠂ ⠁
|
||||
⠐ ⠄ ⠄ ⢀ ⠠ ⠄
|
||||
? for shortcuts 100% context left
|
||||
finished:
|
||||
|
||||
› Ask Codex to do anything
|
||||
|
||||
? for shortcuts 100% context left
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
---
|
||||
source: tui/src/bottom_pane/chat_composer/sparkle_tests.rs
|
||||
expression: "snapshots.join(\"\\n\\n\")"
|
||||
---
|
||||
40 columns, cursor Some((2, 1))
|
||||
⠈ ⢀
|
||||
›⠁Ask Codex to do anything ⠈
|
||||
⢀ ⠠ ⠄ ⠠
|
||||
? for shortcuts 100% context left
|
||||
first input:
|
||||
|
||||
› x
|
||||
|
||||
100% context left
|
||||
|
||||
80 columns, cursor Some((2, 1))
|
||||
⠈ ⢀ ⠁ ⠂
|
||||
›⠁Ask Codex to do anything ⠈ ⠁
|
||||
⢀ ⠠ ⠄ ⠠ ⢀ ⠠ ⡀
|
||||
? for shortcuts 100% context left
|
||||
first input:
|
||||
|
||||
› x
|
||||
|
||||
100% context left
|
||||
@@ -0,0 +1,426 @@
|
||||
//! One short Astra flourish for a confirmed new task with an untouched prompt.
|
||||
//!
|
||||
//! Ordinary draft content ends the opportunity permanently; slash commands can still select Astra
|
||||
//! if the flourish has never started. The original field fills blank composer cells without drawing
|
||||
//! over the placeholder or normal terminal cursor, and hidden frames do not schedule work. The
|
||||
//! separate field renderer only paints its buffer and has no input or scheduling state. History
|
||||
//! search hides an active field while its original deadline continues; its query and previews do
|
||||
//! not count as input before acceptance. Shortcut help on an empty composer also hides an active
|
||||
//! field without restarting its deadline and leaves an unused opportunity intact. The disconnected
|
||||
//! editor shares draft tracking but treats composer-only shortcuts as ordinary editor input. A key
|
||||
//! that finishes a paste burst reconciles the draft even if it removes a held slash in the same edit.
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::cell::RefCell;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
use codex_config::types::Tui;
|
||||
use crossterm::event::KeyCode;
|
||||
use crossterm::event::KeyEvent;
|
||||
use crossterm::event::KeyModifiers;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::layout::Rect;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
use super::ChatComposer;
|
||||
use super::FooterMode;
|
||||
use super::InputResult;
|
||||
use crate::bottom_pane::BottomPane;
|
||||
use crate::terminal_palette::StdoutColorLevel;
|
||||
use crate::terminal_palette::default_fg;
|
||||
use crate::terminal_palette::effective_stdout_color_level;
|
||||
|
||||
#[path = "sparkle_field.rs"]
|
||||
mod field;
|
||||
|
||||
const FRAME_TICK: Duration = Duration::from_millis(/*millis*/ 150);
|
||||
const IDLE_TIMEOUT: Duration = Duration::from_secs(/*secs*/ 15);
|
||||
const IDLE_FADE: Duration = Duration::from_secs(/*secs*/ 1);
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub(crate) enum SparkleDraft {
|
||||
#[default]
|
||||
Untouched,
|
||||
Command,
|
||||
Dismissed,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Default, PartialEq, Eq)]
|
||||
enum Phase {
|
||||
#[default]
|
||||
Unarmed,
|
||||
Waiting,
|
||||
Visible(Instant),
|
||||
Finished,
|
||||
}
|
||||
|
||||
pub(super) struct SparkleEditorState {
|
||||
text: String,
|
||||
paste_burst_active: bool,
|
||||
}
|
||||
|
||||
pub(super) struct Sparkle {
|
||||
pub(super) draft: Cell<SparkleDraft>,
|
||||
/// Scoped to history's own replacements; other draft changes still count while search is open.
|
||||
pub(super) history_preview: bool,
|
||||
command_input: RefCell<String>,
|
||||
phase: Cell<Phase>,
|
||||
fresh: bool,
|
||||
terminal_focused: bool,
|
||||
}
|
||||
|
||||
impl Default for Sparkle {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
draft: Cell::new(SparkleDraft::Untouched),
|
||||
history_preview: false,
|
||||
command_input: RefCell::new(String::new()),
|
||||
phase: Cell::new(Phase::Unarmed),
|
||||
fresh: false,
|
||||
terminal_focused: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BottomPane {
|
||||
pub(crate) fn is_sparkle_model(model: &str) -> bool {
|
||||
model
|
||||
.split(|ch: char| !ch.is_alphanumeric() && ch != '_')
|
||||
.any(|part| part.eq_ignore_ascii_case("astra"))
|
||||
}
|
||||
|
||||
pub(crate) fn mark_fresh_task_for_sparkle(&mut self, model: &str, settings: &Tui) {
|
||||
self.composer.sparkle.fresh = true;
|
||||
if matches!(
|
||||
self.composer.sparkle.draft.get(),
|
||||
SparkleDraft::Untouched | SparkleDraft::Command
|
||||
) && self.composer.sparkle.phase.get() == Phase::Unarmed
|
||||
&& settings.animations
|
||||
&& settings.whimsy
|
||||
&& Self::is_sparkle_model(model)
|
||||
{
|
||||
self.composer.sparkle.phase.set(Phase::Waiting);
|
||||
self.request_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn select_sparkle_model(&mut self, model: &str, settings: &Tui) {
|
||||
if self.composer.sparkle.fresh {
|
||||
self.mark_fresh_task_for_sparkle(model, settings);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn stop_ineligible_sparkle(&self, model: &str, settings: &Tui) {
|
||||
if !settings.animations || !settings.whimsy || !Self::is_sparkle_model(model) {
|
||||
self.composer.stop_visible_sparkle();
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn dismiss_composer_sparkle(&self) {
|
||||
self.composer.dismiss_sparkle();
|
||||
}
|
||||
|
||||
pub(crate) fn prepare_composer_sparkle_key(&self, key: KeyEvent) {
|
||||
if !self.has_active_view() {
|
||||
self.composer.prepare_sparkle_key(key);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn inherit_startup_sparkle(&self, draft: SparkleDraft) {
|
||||
if self.composer.sparkle.draft.get() == SparkleDraft::Untouched
|
||||
&& draft != SparkleDraft::Untouched
|
||||
{
|
||||
self.composer.sparkle.draft.set(draft);
|
||||
if draft == SparkleDraft::Dismissed {
|
||||
self.composer.stop_visible_sparkle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn set_sparkle_terminal_focus(&mut self, focused: bool) {
|
||||
if self.composer.sparkle.terminal_focused != focused {
|
||||
self.composer.sparkle.terminal_focused = focused;
|
||||
self.request_redraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ChatComposer {
|
||||
fn prepare_sparkle_key(&self, key: KeyEvent) {
|
||||
if self.sparkle.draft.get() != SparkleDraft::Command
|
||||
&& !(key.code == KeyCode::Char('/')
|
||||
&& crate::key_hint::is_plain_text_key_event(key)
|
||||
&& self.is_empty()
|
||||
&& self.slash_commands_enabled())
|
||||
{
|
||||
self.stop_visible_sparkle();
|
||||
}
|
||||
}
|
||||
|
||||
fn stop_visible_sparkle(&self) {
|
||||
if matches!(self.sparkle.phase.get(), Phase::Waiting | Phase::Visible(_)) {
|
||||
self.sparkle.phase.set(Phase::Finished);
|
||||
if let Some(requester) = &self.frame_requester {
|
||||
requester.schedule_frame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn dismiss_sparkle(&self) {
|
||||
self.sparkle.draft.set(SparkleDraft::Dismissed);
|
||||
self.sparkle.command_input.borrow_mut().clear();
|
||||
self.stop_visible_sparkle();
|
||||
}
|
||||
|
||||
pub(super) fn before_sparkle_key(&self, key: KeyEvent) -> Option<SparkleEditorState> {
|
||||
if self.history_search.is_some()
|
||||
|| (Self::is_history_search_key(&key, &self.history_search_previous_keys)
|
||||
&& (self.popups.active() || !self.draft.textarea.wants_vim_search_key(key))
|
||||
&& !self.wants_vim_history_key(key))
|
||||
|| self.empty_prompt_shortcut_toggle(&key).is_some()
|
||||
{
|
||||
return None;
|
||||
}
|
||||
self.before_sparkle_editor_key(key)
|
||||
}
|
||||
|
||||
pub(super) fn before_sparkle_editor_key(&self, key: KeyEvent) -> Option<SparkleEditorState> {
|
||||
self.prepare_sparkle_key(key);
|
||||
if self.draft.textarea.vim_query().is_some() {
|
||||
return None;
|
||||
}
|
||||
if let KeyCode::Char(ch) = key.code
|
||||
&& crate::key_hint::is_plain_text_key_event(key)
|
||||
&& !key
|
||||
.modifiers
|
||||
.intersects(KeyModifiers::SUPER | KeyModifiers::HYPER | KeyModifiers::META)
|
||||
&& !self.draft.textarea.is_vim_normal_mode()
|
||||
{
|
||||
match self.sparkle.draft.get() {
|
||||
SparkleDraft::Untouched
|
||||
if ch == '/' && self.is_empty() && self.slash_commands_enabled() =>
|
||||
{
|
||||
self.sparkle.draft.set(SparkleDraft::Command);
|
||||
self.sparkle.command_input.replace(ch.to_string());
|
||||
}
|
||||
SparkleDraft::Command => {
|
||||
let actual = self.current_text();
|
||||
let mut projected = self.sparkle.command_input.borrow().clone();
|
||||
let cursor = if actual == projected {
|
||||
self.current_cursor()
|
||||
} else {
|
||||
projected.len()
|
||||
};
|
||||
projected.insert(cursor, ch);
|
||||
if self.is_sparkle_command(&projected) {
|
||||
self.sparkle.command_input.replace(projected);
|
||||
} else {
|
||||
self.dismiss_sparkle();
|
||||
}
|
||||
}
|
||||
SparkleDraft::Untouched => self.dismiss_sparkle(),
|
||||
SparkleDraft::Dismissed => {}
|
||||
}
|
||||
None
|
||||
} else {
|
||||
Some(SparkleEditorState {
|
||||
text: self.current_text(),
|
||||
paste_burst_active: self.is_in_paste_burst(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn after_sparkle_key(
|
||||
&self,
|
||||
before: Option<SparkleEditorState>,
|
||||
result: &InputResult,
|
||||
) {
|
||||
match result {
|
||||
InputResult::Command(_) | InputResult::ServiceTierCommand(_) => {
|
||||
if self.sparkle.draft.get() == SparkleDraft::Command {
|
||||
self.sparkle.draft.set(SparkleDraft::Untouched);
|
||||
self.sparkle.command_input.borrow_mut().clear();
|
||||
}
|
||||
}
|
||||
InputResult::Submitted { .. }
|
||||
| InputResult::Queued { .. }
|
||||
| InputResult::ParentOwnedInputBlocked => self.dismiss_sparkle(),
|
||||
InputResult::CommandWithArgs(_, _, _) | InputResult::None => {
|
||||
if self.history_search.is_none() && self.draft.textarea.vim_query().is_none() {
|
||||
let draft = self.current_text();
|
||||
if before.is_some_and(|before| {
|
||||
before.text != draft
|
||||
|| (before.paste_burst_active && !self.is_in_paste_burst())
|
||||
}) {
|
||||
self.note_sparkle_replaced_text(&draft);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn note_sparkle_paste(&self, text: &str) {
|
||||
if self.history_search.is_some() {
|
||||
return;
|
||||
}
|
||||
if self.sparkle.draft.get() != SparkleDraft::Command
|
||||
&& !(self.is_empty() && self.is_sparkle_command(text))
|
||||
{
|
||||
self.stop_visible_sparkle();
|
||||
}
|
||||
if !text.is_empty() && self.draft.textarea.vim_query().is_none() {
|
||||
match self.sparkle.draft.get() {
|
||||
SparkleDraft::Untouched if self.is_empty() && self.is_sparkle_command(text) => {
|
||||
self.sparkle.draft.set(SparkleDraft::Command);
|
||||
self.sparkle.command_input.replace(text.to_string());
|
||||
}
|
||||
SparkleDraft::Command => {
|
||||
let mut projected = self.sparkle.command_input.borrow().clone();
|
||||
let actual = self.current_text();
|
||||
let cursor = if actual == projected {
|
||||
self.current_cursor()
|
||||
} else {
|
||||
projected.len()
|
||||
};
|
||||
projected.insert_str(cursor, text);
|
||||
if self.is_sparkle_command(&projected) {
|
||||
self.sparkle.command_input.replace(projected);
|
||||
} else {
|
||||
self.dismiss_sparkle();
|
||||
}
|
||||
}
|
||||
SparkleDraft::Untouched => self.dismiss_sparkle(),
|
||||
SparkleDraft::Dismissed => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn note_sparkle_replaced_text(&self, text: &str) {
|
||||
match self.sparkle.draft.get() {
|
||||
SparkleDraft::Command if text.is_empty() => {
|
||||
self.sparkle.draft.set(SparkleDraft::Untouched);
|
||||
self.sparkle.command_input.borrow_mut().clear();
|
||||
}
|
||||
SparkleDraft::Command if self.is_sparkle_command(text) => {
|
||||
self.sparkle.command_input.replace(text.to_string());
|
||||
}
|
||||
SparkleDraft::Untouched if text.is_empty() => {}
|
||||
SparkleDraft::Untouched | SparkleDraft::Command => self.dismiss_sparkle(),
|
||||
SparkleDraft::Dismissed => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn is_sparkle_command(&self, text: &str) -> bool {
|
||||
let Some(body) = text.strip_prefix('/') else {
|
||||
return false;
|
||||
};
|
||||
if !self.slash_commands_enabled() || self.draft.is_bash_mode || text.contains(['\n', '\r'])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let split = body.find(char::is_whitespace).unwrap_or(body.len());
|
||||
let (name, rest) = body.split_at(split);
|
||||
if rest.is_empty() {
|
||||
self.slash_input().is_editing_command_name(text, text.len())
|
||||
|| self.slash_input().command(name).is_some()
|
||||
} else {
|
||||
self.slash_input()
|
||||
.command(name)
|
||||
.is_some_and(|command| rest.trim().is_empty() || command.supports_inline_args())
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn render_sparkle(
|
||||
&self,
|
||||
area: Rect,
|
||||
textarea: Rect,
|
||||
cursor: Option<(u16, u16)>,
|
||||
buf: &mut Buffer,
|
||||
) {
|
||||
self.render_sparkle_at(area, textarea, cursor, Instant::now(), buf);
|
||||
}
|
||||
|
||||
fn render_sparkle_at(
|
||||
&self,
|
||||
area: Rect,
|
||||
textarea: Rect,
|
||||
cursor: Option<(u16, u16)>,
|
||||
now: Instant,
|
||||
buf: &mut Buffer,
|
||||
) {
|
||||
if self.history_search.is_none()
|
||||
&& self.draft.textarea.vim_query().is_none()
|
||||
&& !self.is_empty()
|
||||
{
|
||||
let is_command = self.sparkle.draft.get() == SparkleDraft::Command
|
||||
&& self.is_sparkle_command(&self.current_text())
|
||||
&& self.attachments.is_empty();
|
||||
if !is_command {
|
||||
self.dismiss_sparkle();
|
||||
}
|
||||
}
|
||||
let since = match self.sparkle.phase.get() {
|
||||
Phase::Visible(since) => Some(since),
|
||||
Phase::Waiting => None,
|
||||
Phase::Unarmed | Phase::Finished => return,
|
||||
};
|
||||
let elapsed = since.map_or(Duration::ZERO, |since| now.saturating_duration_since(since));
|
||||
if elapsed >= IDLE_TIMEOUT {
|
||||
self.stop_visible_sparkle();
|
||||
return;
|
||||
}
|
||||
if !self.has_focus
|
||||
|| !self.sparkle.terminal_focused
|
||||
|| !self.is_empty()
|
||||
|| self.sparkle.draft.get() == SparkleDraft::Command
|
||||
|| self.draft.paste_burst.is_active()
|
||||
|| !self.draft.input_enabled
|
||||
|| self.is_task_running
|
||||
|| self.voice_strip.is_some()
|
||||
|| self.popup_active()
|
||||
|| self.footer_mode() == FooterMode::ShortcutOverlay
|
||||
|| area.height < 3
|
||||
|| textarea.is_empty()
|
||||
|| effective_stdout_color_level() != StdoutColorLevel::TrueColor
|
||||
{
|
||||
return;
|
||||
}
|
||||
let Some(foreground) = default_fg() else {
|
||||
return;
|
||||
};
|
||||
if since.is_none() {
|
||||
self.sparkle.phase.set(Phase::Visible(now));
|
||||
}
|
||||
let fade_start = IDLE_TIMEOUT - IDLE_FADE;
|
||||
let visibility = if elapsed > fade_start {
|
||||
(IDLE_TIMEOUT - elapsed).as_secs_f32() / IDLE_FADE.as_secs_f32()
|
||||
} else {
|
||||
1.0
|
||||
};
|
||||
let protected = Rect::new(
|
||||
textarea.x,
|
||||
textarea.y,
|
||||
self.placeholder_text
|
||||
.width()
|
||||
.min(usize::from(textarea.width)) as u16,
|
||||
/*height*/ 1,
|
||||
);
|
||||
field::render_stars(
|
||||
area,
|
||||
cursor,
|
||||
Some(protected),
|
||||
elapsed.min(fade_start),
|
||||
foreground,
|
||||
visibility,
|
||||
buf,
|
||||
);
|
||||
if let Some(requester) = &self.frame_requester {
|
||||
requester.schedule_frame_in(FRAME_TICK.min(IDLE_TIMEOUT - elapsed));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "sparkle_tests.rs"]
|
||||
mod tests;
|
||||
@@ -0,0 +1,70 @@
|
||||
//! Paint the deterministic Astra starfield without owning its eligibility, timer, or redraws.
|
||||
//!
|
||||
//! Only blank, unstyled true-color cells outside protected content and the terminal cursor can be
|
||||
//! decorated. The caller supplies elapsed time and visibility to preserve the original appearance.
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::buffer::CellDiffOption;
|
||||
use ratatui::layout::Position;
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui::style::Color;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
use crate::color::blend;
|
||||
use crate::terminal_palette::rgb_color;
|
||||
|
||||
pub(super) const DOTS: [&str; 8] = ["⠁", "⠂", "⠄", "⠈", "⠐", "⠠", "⡀", "⢀"];
|
||||
|
||||
pub(super) fn render_stars(
|
||||
area: Rect,
|
||||
cursor: Option<(u16, u16)>,
|
||||
protected_area: Option<Rect>,
|
||||
elapsed: Duration,
|
||||
foreground: (u8, u8, u8),
|
||||
visibility: f32,
|
||||
buf: &mut Buffer,
|
||||
) {
|
||||
let time = elapsed.as_secs_f32();
|
||||
for y in area.y..area.bottom() {
|
||||
let mut occupied_until = area.x;
|
||||
for x in area.x..area.right() {
|
||||
let cell = &buf[(x, y)];
|
||||
if x < occupied_until {
|
||||
continue;
|
||||
}
|
||||
if cell.symbol() != " " {
|
||||
occupied_until = x.saturating_add(cell.symbol().width() as u16);
|
||||
continue;
|
||||
}
|
||||
if cursor == Some((x, y))
|
||||
|| protected_area.is_some_and(|protected| protected.contains(Position::new(x, y)))
|
||||
|| !cell.modifier.is_empty()
|
||||
|| cell.diff_option != CellDiffOption::None
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let Color::Rgb(r, g, b) = cell.bg else {
|
||||
continue;
|
||||
};
|
||||
let mut hash = u64::from(y - area.y) * 65537 + u64::from(x - area.x);
|
||||
hash = (hash ^ (hash >> 16)).wrapping_mul(/*rhs*/ 0x45d9f3b);
|
||||
hash = (hash ^ (hash >> 16)).wrapping_mul(/*rhs*/ 0x45d9f3b);
|
||||
hash ^= hash >> 16;
|
||||
if hash % 5 != 0 {
|
||||
continue;
|
||||
}
|
||||
let phase =
|
||||
(time / (4.0 + (hash % 31) as f32 / 10.0) + (hash % 997) as f32 / 997.0).fract();
|
||||
let brightness =
|
||||
(phase * std::f32::consts::PI).sin().powi(/*n*/ 12) * 0.55 * visibility;
|
||||
if brightness < 0.04 {
|
||||
continue;
|
||||
}
|
||||
buf[(x, y)]
|
||||
.set_symbol(DOTS[(hash / 161 % 8) as usize])
|
||||
.set_fg(rgb_color(blend(foreground, (r, g, b), brightness)));
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -64,21 +64,21 @@ impl VimHistory {
|
||||
}
|
||||
|
||||
impl ChatComposer {
|
||||
pub(super) fn wants_vim_history_key(&self, event: KeyEvent) -> bool {
|
||||
self.draft.textarea.is_vim_normal_mode()
|
||||
&& !self.draft.textarea.is_vim_operator_pending()
|
||||
&& !self.popups.active()
|
||||
&& (self.vim_normal_keymap.redo.is_pressed(event)
|
||||
|| self.vim_normal_keymap.undo.is_pressed(event))
|
||||
}
|
||||
|
||||
/// Consume undo and redo before normal-mode commands, even when their history is empty.
|
||||
pub(super) fn handle_vim_history_key(&mut self, event: KeyEvent) -> bool {
|
||||
if !self.draft.textarea.is_vim_normal_mode()
|
||||
|| self.draft.textarea.is_vim_operator_pending()
|
||||
|| self.popups.active()
|
||||
{
|
||||
if !self.wants_vim_history_key(event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let redo = self.vim_normal_keymap.redo.is_pressed(event);
|
||||
let undo = self.vim_normal_keymap.undo.is_pressed(event);
|
||||
if !undo && !redo {
|
||||
return false;
|
||||
}
|
||||
|
||||
let snapshot = if redo {
|
||||
self.vim_history.redo.pop_back()
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user