Skip to content

Additive InputMode / OutputMode enums for menu settings#1071

Open
kronberger-droid wants to merge 5 commits into
nushell:mainfrom
kronberger-droid:menu-modes
Open

Additive InputMode / OutputMode enums for menu settings#1071
kronberger-droid wants to merge 5 commits into
nushell:mainfrom
kronberger-droid:menu-modes

Conversation

@kronberger-droid
Copy link
Copy Markdown
Contributor

Adds InputMode and OutputMode enums to MenuSettings with their own builder methods.
When set, they override only_buffer_difference (kept for back-compat) and when unset, the bool path is preserved unchanged.
Decouples menu input (what the completer receives) from output (what range of the buffer gets replaced on selection) if needed, which is the structural coupling behind #1006.

#[non_exhaustive]
pub enum InputMode {
    Diff,            // ≡ only_buffer_difference: true
    CursorPrefix,    // ≡ only_buffer_difference: false
    FullBuffer,      // NEW — exposes post-cursor content to the completer
}

#[non_exhaustive]
pub enum OutputMode {
    SuggestedSpan,   // ≡ Suggestion::span as-is (default)
    FullBuffer,      // overwrite 0..buffer.len()
    ExtendToEnd,     // keep span.start, force end = buffer.len()
}

MenuSettings::effective_input_mode() resolves enum-over-bool precedence in one place and all four menu impls (Columnar/Description/Ide/ListMenu) go through it.
replace_in_buffer takes Option<OutputMode>, also None and Some(SuggestedSpan) are equivalent.

examples/demo.rs opts the history menu into OutputMode::FullBuffer, demonstrating the pattern that fixes #1006 once nushell exposes the corresponding config field.

Out of scope:

  • nushell config integration
  • migration of other built-in menus
  • HistoryCompleter::create_suggestion span update needed before HistoryMenu can use InputMode::FullBuffer (doc-comment warning added).

Tests: precedence table for effective_input_mode, FullBuffer case for completer_input, two cases for replace_in_buffer with explicit OutputMode variants.
Full suite passes (843 + 28 doctests).

Manually verified via cargo run --example demo: opened history menu mid-buffer, filtered, selected and the whole line replaced.

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 11, 2026

Yup, pretty much inline with what I was thinking based on our other conversation. Thanks!

@kronberger-droid kronberger-droid marked this pull request as ready for review May 11, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Selecting from a menu keeps text after the cursor

2 participants