code: def create_operator_decorator(
      key_bindings: KeyBindings,
  ) -> Callable[..., Callable[[_OF], _OF]]:
      """
      Create a decorator that can be used for registering Vi operators.
      """
  
      def operator_decorator(
          *keys: Keys | str,
          filter: Filter = Always(),
          eager: bool = False,
      ) -> Callable[[_OF], _OF]:
          """
          Register a Vi operator.
  
          Usage::
  
              @operator('d', filter=...)
              def handler(event, text_object):
                  # Do something with the text object here.
          """
  
          def decorator(operator_func: _OF) -> _OF:
              @key_bindings.add(
                  *keys,
                  filter=~vi_waiting_for_text_object_mode
                  & filter
                  & vi_navigation_mode,
                  eager=eager,
              )
              def _operator_in_navigation(event: E) -> None:
                  """
                  Handle operator in navigation mode.
                  """
                  # When this key binding is matched, only set the operator
                  # function in the ViState. We should execute it after a text
                  # object has been received.
                  event.app.vi_state.operator_func = operator_func
                  event.app.vi_state.operator_arg = event.arg
  
              @key_bindings.add(
                  *keys,
                  filter=~vi_waiting_for_text_object_mode
                  & filter
                  & vi_selection_mode,
                  eager=eager,
              )
              def _operator_in_selection(event: E) -> None:
                  """
                  Handle operator in selection mode.
                  """
                  buff = event.current_buffer
                  selection_state = buff.selection_state
  
                  if selection_state is not None:
                      # Create text object from selection.
                      if selection_state.type == SelectionType.LINES:
                          text_obj_type = TextObjectType.LINEWISE
                      elif selection_state.type == SelectionType.BLOCK:
                          text_obj_type = TextObjectType.BLOCK
                      else:
                          text_obj_type = TextObjectType.INCLUSIVE
  
                      text_object = TextObject(
                          selection_state.original_cursor_position
                          - buff.cursor_position,
                          type=text_obj_type,
                      )
  
                      # Execute operator.
                      operator_func(event, text_object)
  
                      # Quit selection mode.
                      buff.selection_state = None
  
              return operator_func
  
          return decorator
  
      return operator_decorator
  
imports: from __future__ import annotations
  import codecs
  import string
  from enum import Enum
  from itertools import accumulate
  from typing import Callable, Iterable, Tuple, TypeVar
  from prompt_toolkit.application.current import get_app
  from prompt_toolkit.buffer import Buffer, indent, reshape_text, unindent
  from prompt_toolkit.clipboard import ClipboardData
  from prompt_toolkit.document import Document
  from prompt_toolkit.filters import Always, Condition, Filter, has_arg, is_read_only, is_searching
  from prompt_toolkit.filters.app import in_paste_mode, is_multiline, vi_digraph_mode, vi_insert_mode, vi_insert_multiple_mode, vi_mode, vi_navigation_mode, vi_recording_macro, vi_replace_mode, vi_replace_single_mode, vi_search_direction_reversed, vi_selection_mode, vi_waiting_for_text_object_mode
  from prompt_toolkit.input.vt100_parser import Vt100Parser
  from prompt_toolkit.key_binding.digraphs import DIGRAPHS
  from prompt_toolkit.key_binding.key_processor import KeyPress, KeyPressEvent
  from prompt_toolkit.key_binding.vi_state import CharacterFind, InputMode
  from prompt_toolkit.keys import Keys
  from prompt_toolkit.search import SearchDirection
  from prompt_toolkit.selection import PasteMode, SelectionState, SelectionType
  from ..key_bindings import ConditionalKeyBindings, KeyBindings, KeyBindingsBase
  from .named_commands import get_by_name
label_desc: Use image node_id 2 for calling a global function with example usage: create_operator_decorator(key_bindings) and returns: operator_decorator, decorator, operator_func