@@ -134,7 +134,6 @@ class Buffer(object):
134134 current input line and implements all text manipulations on top of it. It 
135135 also implements the history, undo stack and the completion state. 
136136
137-  :param eventloop: :class:`~prompt_toolkit.eventloop.EventLoop` instance. 
138137 :param completer: :class:`~prompt_toolkit.completion.Completer` instance. 
139138 :param history: :class:`~prompt_toolkit.history.History` instance. 
140139 :param tempfile_suffix: The tempfile suffix (extension) to be used for the 
@@ -144,8 +143,14 @@ class Buffer(object):
144143 :param name: Name for this buffer. E.g. DEFAULT_BUFFER. This is mostly 
145144 useful for key bindings where we sometimes prefer to refer to a buffer 
146145 by their name instead of by reference. 
147-  :param accept_handler: Callback that takes this buffer as input. Called when 
148-  the buffer input is accepted. (Usually when the user presses `enter`.) 
146+  :param accept_handler: Called when the buffer input is accepted. (Usually 
147+  when the user presses `enter`.) The accept handler receives this 
148+  `Buffer` as input and should return True when the buffer text should be 
149+  kept instead of calling reset. 
150+ 
151+  In case of a `PromptSession` for instance, we want to keep the text, 
152+  because we will exit the application, and only reset it during the next 
153+  run. 
149154
150155 Events: 
151156
@@ -1608,10 +1613,16 @@ def validate_and_handle(self):
16081613
16091614 # When the validation succeeded, accept the input. 
16101615 if  valid :
1611-  if  self .accept_handler :
1612-  self .accept_handler (self )
16131616 self .append_to_history ()
16141617
1618+  if  self .accept_handler :
1619+  keep_text  =  self .accept_handler (self )
1620+  else :
1621+  keep_text  =  False 
1622+ 
1623+  if  not  keep_text :
1624+  self .reset ()
1625+ 
16151626
16161627def  _only_one_at_a_time (coroutine ):
16171628 """ 
0 commit comments