class_docstr: Control for visualising the content of a `Buffer`.
  
  :param input_processors: list of :class:`~prompt_toolkit.layout.processors.Processor`.
  :param lexer: :class:`~prompt_toolkit.layout.lexers.Lexer` instance for syntax highlighting.
  :param preview_search: `bool` or `CLIFilter`: Show search while typing.
  :param get_search_state: Callable that takes a CommandLineInterface and
      returns the SearchState to be used. (If not CommandLineInterface.search_state.)
  :param buffer_name: String representing the name of the buffer to display.
  :param default_char: :class:`.Char` instance to use to fill the background. This is
      transparent by default.
  :param focus_on_click: Focus this buffer when it's click, but not yet focussed.
class_docstr_tok: ["Control","for","visualising","the","content","of","a","`","Buffer","`",".",":","param","input_processors",":","list","of",":","class",":","`","~prompt_toolkit.layout.processors.Processor","`",".",":","param","lexer",":",":","class",":","`","~prompt_toolkit.layout.lexers.Lexer","`","instance","for","syntax","highlighting",".",":","param","preview_search",":","`","bool","`","or","`","CLIFilter","`",":","Show","search","while","typing",".",":","param","get_search_state",":","Callable","that","takes","a","CommandLineInterface","and","returns","the","SearchState","to","be","used",".","(","If","not","CommandLineInterface.search_state",".",")",":","param","buffer_name",":","String","representing","the","name","of","the","buffer","to","display",".",":","param","default_char",":",":","class",":","`",".Char","`","instance","to","use","to","fill","the","background",".","This","is","transparent","by","default",".",":","param","focus_on_click",":","Focus","this","buffer","when","it","'s","click",",","but","not","yet","focussed","."]
docstr: Mouse handler for this control.
docstr_tok: ["Mouse","handler","for","this","control","."]
code: def mouse_handler(self, cli, mouse_event):
      """
      Mouse handler for this control.
      """
      buffer = self._buffer(cli)
      position = mouse_event.position
  
      # Focus buffer when clicked.
      if self.has_focus(cli):
          if self._last_get_processed_line:
              processed_line = self._last_get_processed_line(position.y)
  
              # Translate coordinates back to the cursor position of the
              # original input.
              xpos = processed_line.display_to_source(position.x)
              index = buffer.document.translate_row_col_to_index(
                  position.y, xpos
              )
  
              # Set the cursor position.
              if mouse_event.event_type == MouseEventType.MOUSE_DOWN:
                  buffer.exit_selection()
                  buffer.cursor_position = index
  
              elif mouse_event.event_type == MouseEventType.MOUSE_UP:
                  # When the cursor was moved to another place, select the text.
                  # (The >1 is actually a small but acceptable workaround for
                  # selecting text in Vi navigation mode. In navigation mode,
                  # the cursor can never be after the text, so the cursor
                  # will be repositioned automatically.)
                  if abs(buffer.cursor_position - index) > 1:
                      buffer.start_selection(
                          selection_type=SelectionType.CHARACTERS
                      )
                      buffer.cursor_position = index
  
                  # Select word around cursor on double click.
                  # Two MOUSE_UP events in a short timespan are considered a double click.
                  double_click = (
                      self._last_click_timestamp
                      and time.time() - self._last_click_timestamp < 0.3
                  )
                  self._last_click_timestamp = time.time()
  
                  if double_click:
                      (
                          start,
                          end,
                      ) = (
                          buffer.document.find_boundaries_of_current_word()
                      )
                      buffer.cursor_position += start
                      buffer.start_selection(
                          selection_type=SelectionType.CHARACTERS
                      )
                      buffer.cursor_position += end - start
              else:
                  # Don't handle scroll events here.
                  return NotImplemented
  
      # Not focussed, but focussing on click events.
      else:
          if (
              self.focus_on_click(cli)
              and mouse_event.event_type == MouseEventType.MOUSE_UP
          ):
              # Focus happens on mouseup. (If we did this on mousedown, the
              # up event will be received at the point where this widget is
              # focussed and be handled anyway.)
              cli.focus(self.buffer_name)
          else:
              return NotImplemented
  
imports: from __future__ import unicode_literals
  from abc import ABCMeta, abstractmethod
  from collections import namedtuple
  from six import with_metaclass
  from six.moves import range
  from prompt_toolkit.cache import SimpleCache
  from prompt_toolkit.enums import DEFAULT_BUFFER, SEARCH_BUFFER
  from prompt_toolkit.filters import to_cli_filter
  from prompt_toolkit.mouse_events import MouseEventType
  from prompt_toolkit.search_state import SearchState
  from prompt_toolkit.selection import SelectionType
  from prompt_toolkit.token import Token
  from prompt_toolkit.utils import get_cwidth
  from .lexers import Lexer, SimpleLexer
  from .processors import Processor
  from .screen import Char, Point
  from .utils import token_list_width, split_lines, token_list_to_text
  import six
  import time
label_desc: Use image node_id 9 for calling the BufferControl obj's underlying member method code with example usage: obj.mouse_handler(cli, mouse_event) and returns: NotImplemented, NotImplemented