@@ -745,6 +745,28 @@ def _apply_history_query(self: QueryMixinHost, query: str) -> None:
745745 # Focus query input - this triggers on_descendant_focus which updates footer bindings
746746 self .query_input .focus ()
747747
748+ def _append_history_query (self : QueryMixinHost , query : str ) -> None :
749+ """Append a query to the end of the editor without replacing text."""
750+ if query is None :
751+ return
752+
753+ current_text = self .query_input .text
754+ if current_text :
755+ trimmed_current = current_text .rstrip ("\n " )
756+ separator = "\n " if trimmed_current else ""
757+ new_text = f"{ trimmed_current } { separator } { query } "
758+ else :
759+ new_text = query
760+
761+ self ._push_undo_state ()
762+ self .query_input .text = new_text
763+
764+ lines = new_text .split ("\n " )
765+ last_line = len (lines ) - 1
766+ last_col = len (lines [- 1 ]) if lines else 0
767+ self .query_input .cursor_location = (last_line , last_col )
768+ self .query_input .focus ()
769+
748770 def action_show_history (self : QueryMixinHost ) -> None :
749771 """Show query history for the current connection."""
750772 if not self .current_config :
@@ -772,6 +794,8 @@ def _handle_history_result(self: QueryMixinHost, result: Any) -> None:
772794 action , data = result
773795 if action == "select" :
774796 self ._apply_history_query (data )
797+ elif action == "append" :
798+ self ._append_history_query (data )
775799 elif action == "delete" :
776800 self ._delete_history_entry (data )
777801 self .action_show_history ()
@@ -843,6 +867,10 @@ def _handle_telescope_result(self: QueryMixinHost, result: Any) -> None:
843867 query = data .get ("query" , "" )
844868 connection_name = data .get ("connection_name" , "" )
845869 self ._run_telescope_query (connection_name , query )
870+ elif action == "append" :
871+ query = data .get ("query" , "" )
872+ if query :
873+ self ._append_history_query (query )
846874 elif action == "delete" :
847875 timestamp = data .get ("timestamp" , "" )
848876 connection_name = data .get ("connection_name" , "" )
0 commit comments