@@ -413,78 +413,93 @@ def is_callable(text=""):
413413 return False
414414
415415 @Condition
416- def accot ():
416+ def auto_complete_commit_on_tab ():
417417 return settings .auto_complete_commit_on_tab
418418
419+ @Condition
420+ def auto_complete_commit_top_option_on_enter ():
421+ return settings .auto_complete_commit_top_option_on_enter
422+
423+ @Condition
424+ def auto_complete_commit_top_option_on_tab ():
425+ return settings .auto_complete_commit_top_option_on_tab
426+
427+ @Condition
428+ def auto_complete_commit_only_option_on_tab ():
429+ return settings .auto_complete_commit_only_option_on_tab
430+
419431 insert_mode = vi_insert_mode | emacs_insert_mode
420432 focused_insert = insert_mode & has_focus (DEFAULT_BUFFER )
421433 shown_not_selected = has_completions & ~ completion_is_selected
422434 alt_enter = [KeyPress (Keys .Escape ), KeyPress (Keys .Enter )]
423435
424- # apply selected completion
425- @handle ('c-j' , filter = focused_insert & completion_is_selected & accot )
426- @handle ("enter" , filter = focused_insert & completion_is_selected & accot )
436+ # apply selected completion option with enter
437+ @handle ('c-j' , filter = focused_insert & completion_is_selected )
438+ @handle ("enter" , filter = focused_insert & completion_is_selected )
427439 def _ (event ):
428440 b = event .current_buffer
429- text = b .text
430441 completion = b .complete_state .current_completion
431- if is_callable ( completion . text ) or is_callable ( b . document . get_word_under_cursor ()):
432- b . insert_text ( "()" )
433- b . cursor_left ()
434- if text == b . text :
435- event . cli . key_processor . feed_multiple ( alt_enter )
442+ b . apply_completion ( completion )
443+ if settings . auto_complete_function_parentheses :
444+ if is_callable ( completion . text ) or is_callable ( b . document . get_word_under_cursor ()):
445+ b . insert_text ( "()" )
446+ b . cursor_left ( )
436447
437- # apply first completion option when completion menu is showing
438- @handle ('c-j' , filter = focused_insert & shown_not_selected & accot )
439- @handle ("enter " , filter = focused_insert & shown_not_selected & accot )
448+ # apply selected completion option with tab
449+ @handle ("tab" , filter = focused_insert & completion_is_selected & auto_complete_commit_on_tab )
450+ @handle ("c-space " , filter = focused_insert & completion_is_selected & auto_complete_commit_on_tab )
440451 def _ (event ):
441452 b = event .current_buffer
442- text = b .text
443- b .complete_next ()
444453 completion = b .complete_state .current_completion
445- if is_callable ( completion . text ) or is_callable ( b . document . get_word_under_cursor ()):
446- b . insert_text ( "()" )
447- b . cursor_left ()
448- if text == b . text :
449- event . cli . key_processor . feed_multiple ( alt_enter )
454+ b . apply_completion ( completion )
455+ if settings . auto_complete_function_parentheses :
456+ if is_callable ( completion . text ) or is_callable ( b . document . get_word_under_cursor ()):
457+ b . insert_text ( "()" )
458+ b . cursor_left ( )
450459
451- # apply completion if there is only one option, otherwise start completion
452- @handle ("tab" , filter = focused_insert & ~ has_completions & accot )
453- @handle ("c-space " , filter = focused_insert & ~ has_completions & accot )
460+ # apply first completion option with enter when completion menu is showing
461+ @handle ('c-j' , filter = focused_insert & shown_not_selected & auto_complete_commit_top_option_on_enter )
462+ @handle ("enter " , filter = focused_insert & shown_not_selected & auto_complete_commit_top_option_on_enter )
454463 def _ (event ):
455464 b = event .current_buffer
456- complete_event = CompleteEvent (completion_requested = True )
457- completions = list (b .completer .get_completions (b .document , complete_event ))
458- if len (completions ) == 1 :
459- completion = completions [0 ]
460- b .apply_completion (completion )
465+ text = b .text
466+ completion = b .complete_state .completions [0 ]
467+ b .apply_completion (completion )
468+ if settings .auto_complete_function_parentheses :
461469 if is_callable (completion .text ) or is_callable (b .document .get_word_under_cursor ()):
462470 b .insert_text ("()" )
463471 b .cursor_left ()
464- else :
465- b . start_completion ( insert_common_part = True )
472+ if text == b . text :
473+ event . cli . key_processor . feed_multiple ( alt_enter )
466474
467- # apply first completion option if completion menu is showing
468- @handle ("tab" , filter = focused_insert & shown_not_selected & accot )
469- @handle ("c-space" , filter = focused_insert & shown_not_selected & accot )
475+ # apply first completion option with tab if completion menu is showing
476+ @handle ("tab" , filter = focused_insert & shown_not_selected & auto_complete_commit_top_option_on_tab )
477+ @handle ("c-space" , filter = focused_insert & shown_not_selected & auto_complete_commit_top_option_on_tab )
470478 def _ (event ):
471479 b = event .current_buffer
472- b .complete_next ()
473- completion = b .complete_state .current_completion
474- if is_callable (completion .text ) or is_callable (b .document .get_word_under_cursor ()):
475- b .insert_text ("()" )
476- b .cursor_left ()
480+ completion = b .complete_state .completions [0 ]
481+ b .apply_completion (completion )
482+ if settings .auto_complete_function_parentheses :
483+ if is_callable (completion .text ) or is_callable (b .document .get_word_under_cursor ()):
484+ b .insert_text ("()" )
485+ b .cursor_left ()
477486
478- # apply selected completion option
479- @handle ("tab" , filter = focused_insert & completion_is_selected & accot )
480- @handle ("c-space" , filter = focused_insert & completion_is_selected & accot )
487+ # apply completion if there is only one option, otherwise start completion
488+ @handle ("tab" , filter = focused_insert & ~ has_completions & auto_complete_commit_only_option_on_tab )
489+ @handle ("c-space" , filter = focused_insert & ~ has_completions & auto_complete_commit_only_option_on_tab )
481490 def _ (event ):
482491 b = event .current_buffer
483- completion = b .complete_state .current_completion
484- b .apply_completion (completion )
485- if is_callable (completion .text ) or is_callable (b .document .get_word_under_cursor ()):
486- b .insert_text ("()" )
487- b .cursor_left ()
492+ b .start_completion ()
493+ completions = b .complete_state .completions
494+ if len (completions ) == 1 :
495+ completion = completions [0 ]
496+ b .apply_completion (completion )
497+ if settings .auto_complete_function_parentheses :
498+ if is_callable (completion .text ) or is_callable (b .document .get_word_under_cursor ()):
499+ b .insert_text ("()" )
500+ b .cursor_left ()
501+ else :
502+ b .start_completion (insert_common_part = True )
488503
489504 # cancel completion
490505 @handle ('c-c' , filter = default_focused & has_completions )
0 commit comments