2929from prompt_toolkit .history import FileHistory
3030from prompt_toolkit .application .current import get_app
3131from prompt_toolkit .styles import Style
32+ from prompt_toolkit .key_binding import KeyBindings
3233from gitcommit .style import Ansi
3334from gitcommit .validators import (
3435 DescriptionValidator ,
5253 WINDOW_WIDTH = 80 # default
5354
5455
56+ bindings = KeyBindings ()
57+
58+
59+ @bindings .add ("s-down" )
60+ def emulate_submit (event ):
61+ "Emulate the enter key for text submission with Shift+Down"
62+ get_app ().current_buffer .validate_and_handle ()
63+
64+
5565class LineLengthPrompt :
5666 def __init__ (self , length_limit , session ):
5767 self .limit = length_limit
@@ -150,6 +160,7 @@ def add_type(commit_msg):
150160 completer = TypeCompleter (),
151161 validator = TypeValidator (valid_inputs ),
152162 history = FileHistory (history_file_path ),
163+ key_bindings = bindings ,
153164 )
154165
155166 # Convert from number back to proper type name
@@ -168,7 +179,9 @@ def add_scope(commit_msg):
168179 )
169180 text = Ansi .colour (Ansi .fg .bright_green , "Scope (optional): " )
170181 history_file_path = os .path .join (CONFIG_HOME_DIR , "scope_history" )
171- c_scope = prompt (ANSI (text ), history = FileHistory (history_file_path )).strip ()
182+ c_scope = prompt (
183+ ANSI (text ), history = FileHistory (history_file_path ), key_bindings = bindings
184+ ).strip ()
172185
173186 if c_scope != "" :
174187 commit_msg += "({})" .format (c_scope )
@@ -183,7 +196,11 @@ def check_if_breaking_change():
183196 while True :
184197 text = Ansi .b_yellow ("Does commit contain breaking change? (no) " )
185198 contains_break = (
186- prompt (ANSI (text ), validator = YesNoValidator (answer_required = False ))
199+ prompt (
200+ ANSI (text ),
201+ validator = YesNoValidator (answer_required = False ),
202+ key_bindings = bindings ,
203+ )
187204 .lower ()
188205 .strip ()
189206 )
@@ -219,7 +236,9 @@ def add_description(commit_msg):
219236 c_descr = ""
220237
221238 history_file_path = os .path .join (CONFIG_HOME_DIR , "description_history" )
222- session = PromptSession (history = FileHistory (history_file_path ))
239+ session = PromptSession (
240+ history = FileHistory (history_file_path ), key_bindings = bindings
241+ )
223242
224243 length_prompt = LineLengthPrompt (num_chars_remaining , session )
225244 while c_descr == "" :
@@ -254,6 +273,7 @@ def add_body(commit_msg):
254273 session = PromptSession (
255274 prompt_continuation = custom_prompt_continuation ,
256275 history = FileHistory (history_file_path ),
276+ key_bindings = bindings ,
257277 )
258278 body_validator = BodyValidator (session , IS_BREAKING_CHANGE )
259279
@@ -352,6 +372,7 @@ def add_footer(commit_msg):
352372 multiline = False ,
353373 prompt_continuation = custom_prompt_continuation ,
354374 history = FileHistory (history_file_path ),
375+ key_bindings = bindings ,
355376 )
356377 c_footer = session .prompt (ANSI (text ), validator = FooterValidator (session )).strip ()
357378
@@ -435,7 +456,10 @@ def run(args):
435456 text = Ansi .colour (Ansi .fg .bright_yellow , "Extra args for git commit: " )
436457 extra_args_file_path = os .path .join (CONFIG_HOME_DIR , "extra_args_history" )
437458 extra_args_str = prompt (
438- ANSI (text ), default = existing_args , history = FileHistory (extra_args_file_path )
459+ ANSI (text ),
460+ default = existing_args ,
461+ history = FileHistory (extra_args_file_path ),
462+ key_bindings = bindings ,
439463 )
440464 if extra_args_str != "" :
441465 argv_passthrough = extra_args_str .split (" " )
@@ -445,7 +469,9 @@ def run(args):
445469 # Ask for confirmation to commit
446470 confirmation_validator = YesNoValidator (answer_required = True )
447471 text = Ansi .b_yellow ("Do you want to make your commit? [y/n] " )
448- confirm = prompt (ANSI (text ), validator = confirmation_validator ).lower ()
472+ confirm = prompt (
473+ ANSI (text ), validator = confirmation_validator , key_bindings = bindings
474+ ).lower ()
449475
450476 if confirm in confirmation_validator .confirmations :
451477 commit_msg_history .store_string (commit_msg )
0 commit comments