1717from prompt_toolkit .layout .containers import HSplit , VSplit , Window , FloatContainer , Float , ConditionalContainer , Container , ScrollOffsets
1818from prompt_toolkit .layout .controls import BufferControl , FillControl
1919from prompt_toolkit .layout .dimension import LayoutDimension as D
20- from prompt_toolkit .layout .highlighters import SearchHighlighter , SelectionHighlighter
2120from prompt_toolkit .layout .lexers import PygmentsLexer
2221from prompt_toolkit .layout .margins import Margin , ScrollbarMargin
23- from prompt_toolkit .layout .processors import Processor , Transformation
22+ from prompt_toolkit .layout .processors import Processor , Transformation , HighlightSearchProcessor , HighlightSelectionProcessor
2423from prompt_toolkit .layout .screen import Char
2524from prompt_toolkit .layout .toolbars import ArgToolbar , SearchToolbar
2625from prompt_toolkit .layout .toolbars import TokenListToolbar
27- from prompt_toolkit .layout .utils import explode_tokens
26+ from prompt_toolkit .layout .utils import token_list_to_text
2827from prompt_toolkit .utils import Callback
2928from pygments .lexers import RstLexer
3029from pygments .token import Token
@@ -143,9 +142,9 @@ def create_layout(python_input, history_mapping):
143142 Create and return a `Container` instance for the history
144143 application.
145144 """
146- highlighters = [
147- SearchHighlighter (preview_search = True ),
148- SelectionHighlighter ()]
145+ processors = [
146+ HighlightSearchProcessor (preview_search = True ),
147+ HighlightSelectionProcessor ()]
149148
150149 help_window = create_popup_window (
151150 title = 'History Help' ,
@@ -154,7 +153,7 @@ def create_layout(python_input, history_mapping):
154153 buffer_name = HELP_BUFFER ,
155154 default_char = Char (token = Token ),
156155 lexer = PygmentsLexer (RstLexer ),
157- highlighters = highlighters ),
156+ input_processors = processors ),
158157 right_margins = [ScrollbarMargin ()],
159158 scroll_offsets = ScrollOffsets (top = 2 , bottom = 2 )))
160159
@@ -170,9 +169,9 @@ def create_layout(python_input, history_mapping):
170169 Window (
171170 content = BufferControl (
172171 buffer_name = HISTORY_BUFFER ,
173- wrap_lines = False ,
174172 lexer = PygmentsLexer (PythonLexer ),
175- highlighters = highlighters ),
173+ input_processors = processors ),
174+ wrap_lines = False ,
176175 left_margins = [HistoryMargin (history_mapping )],
177176 scroll_offsets = ScrollOffsets (top = 2 , bottom = 2 )),
178177 # Separator.
@@ -182,10 +181,9 @@ def create_layout(python_input, history_mapping):
182181 Window (
183182 content = BufferControl (
184183 buffer_name = DEFAULT_BUFFER ,
185- wrap_lines = False ,
186- highlighters = highlighters ,
187- input_processors = [GrayExistingText (history_mapping )],
184+ input_processors = processors + [GrayExistingText (history_mapping )],
188185 lexer = PygmentsLexer (PythonLexer )),
186+ wrap_lines = False ,
189187 left_margins = [ResultMargin (history_mapping )],
190188 scroll_offsets = ScrollOffsets (top = 2 , bottom = 2 )),
191189 ]),
@@ -244,7 +242,7 @@ class HistoryMargin(Margin):
244242 def __init__ (self , history_mapping ):
245243 self .history_mapping = history_mapping
246244
247- def get_width (self , cli ):
245+ def get_width (self , cli , ui_content ):
248246 return 2
249247
250248 def create_margin (self , cli , window_render_info , width , height ):
@@ -289,7 +287,7 @@ class ResultMargin(Margin):
289287 def __init__ (self , history_mapping ):
290288 self .history_mapping = history_mapping
291289
292- def get_width (self , cli ):
290+ def get_width (self , cli , ui_content ):
293291 return 2
294292
295293 def create_margin (self , cli , window_render_info , width , height ):
@@ -328,24 +326,15 @@ class GrayExistingText(Processor):
328326 """
329327 def __init__ (self , history_mapping ):
330328 self .history_mapping = history_mapping
331- self ._len_before = len (history_mapping .original_document .text_before_cursor )
332- self ._len_after = len (history_mapping .original_document .text_after_cursor )
333-
334- def apply_transformation (self , cli , document , tokens ):
335- if self ._len_before or self ._len_after :
336- tokens = explode_tokens (tokens )
337- pos_after = len (tokens ) - self ._len_after
338-
339- text_before = '' .join (t [1 ] for t in tokens [:self ._len_before ])
340- text_after = '' .join (t [1 ] for t in tokens [pos_after :])
341-
342- return Transformation (
343- document = document ,
344- tokens = explode_tokens ([(Token .History .ExistingInput , text_before )] +
345- tokens [self ._len_before :pos_after ] +
346- [(Token .History .ExistingInput , text_after )]))
329+ self ._lines_before = len (history_mapping .original_document .text_before_cursor .splitlines ())
330+
331+ def apply_transformation (self , cli , document , lineno , source_to_display , tokens ):
332+ if (lineno < self ._lines_before or
333+ lineno >= self ._lines_before + len (self .history_mapping .selected_lines )):
334+ text = token_list_to_text (tokens )
335+ return Transformation (tokens = [(Token .History .ExistingInput , text )])
347336 else :
348- return Transformation (document , tokens )
337+ return Transformation (tokens = tokens )
349338
350339
351340class HistoryMapping (object ):
0 commit comments