Skip to content

🚀 feat(query-history): append history queries without replacing#192

Open
Mrthnx wants to merge 1 commit intoMaxteabag:mainfrom
Mrthnx:feat/append_query
Open

🚀 feat(query-history): append history queries without replacing#192
Mrthnx wants to merge 1 commit intoMaxteabag:mainfrom
Mrthnx:feat/append_query

Conversation

@Mrthnx
Copy link
Copy Markdown

@Mrthnx Mrthnx commented May 6, 2026

Summary

This PR adds the ability to append a query from history to the editor without replacing the current text. Previously, selecting a query from history (via QueryHistoryScreen or Telescope) would overwrite whatever was in the editor. Now users can press a to append the selected query instead.

Motivation

When working with query history, it's common to want to reuse or combine previous queries. The existing behavior (<enter>) replaces the entire editor content, which is destructive if you're building a multi-statement query or referencing previous snippets. Appending provides a non-destructive alternative.

Changes

1. New _append_history_query() method

Added to QueryExecutionMixin (sqlit/domains/query/ui/mixins/query_execution.py):

  • Appends the selected query to the end of the current editor text
  • Adds a newline separator if the editor is not empty
  • Preserves undo state via _push_undo_state()
  • Moves cursor to the end of the appended text
  • Focuses the query input

2. New append action in QueryHistoryScreen

Added to sqlit/domains/query/ui/screens/query_history.py:

  • New key binding: aaction_append
  • Updated footer shortcuts to show Append (a) alongside existing actions
  • Returns ("append", entry) result to the caller

3. Handle append action in result handlers

Updated both _handle_history_result and _handle_telescope_result in QueryExecutionMixin to handle the new "append" action and delegate to _append_history_query().

How to test

  1. Open Query History (H) or Telescope (Ctrl+T)
  2. Write some text in the query editor (or leave it empty)
  3. Navigate to a history entry and press a
  4. The query should appear appended at the end of the editor, with proper newline separation

Keymap

Key Action
<enter> Select (replaces editor content)
a Append (adds to editor content)
* Toggle star
d Delete entry

@Mrthnx Mrthnx force-pushed the feat/append_query branch from c8a81a8 to e616763 Compare May 6, 2026 01:06
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.

1 participant