Skip to content

Commit 8f85dd5

Browse files
Use highlighters instead of input processors for highlighting text in the history screen (much faster).
1 parent cfc9b2e commit 8f85dd5

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

ptpython/history_browser.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
from prompt_toolkit.buffer_mapping import BufferMapping
1212
from prompt_toolkit.document import Document
1313
from prompt_toolkit.enums import DEFAULT_BUFFER
14-
from prompt_toolkit.filters import Always, Condition, HasFocus, InFocusStack
14+
from prompt_toolkit.filters import Condition, HasFocus, InFocusStack
1515
from prompt_toolkit.key_binding.manager import KeyBindingManager
1616
from prompt_toolkit.keys import Keys
1717
from prompt_toolkit.layout.containers import HSplit, VSplit, Window, FloatContainer, Float, ConditionalContainer, Container, ScrollOffsets
1818
from prompt_toolkit.layout.controls import BufferControl, FillControl
1919
from prompt_toolkit.layout.dimension import LayoutDimension as D
20+
from prompt_toolkit.layout.highlighters import SearchHighlighter, SelectionHighlighter
2021
from prompt_toolkit.layout.lexers import PygmentsLexer
2122
from prompt_toolkit.layout.margins import Margin, ScrollbarMargin
22-
from prompt_toolkit.layout.processors import HighlightSearchProcessor, HighlightSelectionProcessor
2323
from prompt_toolkit.layout.processors import Processor, Transformation
2424
from prompt_toolkit.layout.screen import Char
2525
from prompt_toolkit.layout.toolbars import ArgToolbar, SearchToolbar
@@ -143,9 +143,9 @@ def create_layout(python_input, history_mapping):
143143
Create and return a `Container` instance for the history
144144
application.
145145
"""
146-
default_processors = [
147-
HighlightSearchProcessor(preview_search=Always()),
148-
HighlightSelectionProcessor()]
146+
highlighters = [
147+
SearchHighlighter(preview_search=True),
148+
SelectionHighlighter()]
149149

150150
help_window = create_popup_window(
151151
title='History Help',
@@ -154,7 +154,7 @@ def create_layout(python_input, history_mapping):
154154
buffer_name=HELP_BUFFER,
155155
default_char=Char(token=Token),
156156
lexer=PygmentsLexer(RstLexer),
157-
input_processors=default_processors),
157+
highlighters=highlighters),
158158
right_margins=[ScrollbarMargin()],
159159
scroll_offsets=ScrollOffsets(top=2, bottom=2)))
160160

@@ -172,7 +172,7 @@ def create_layout(python_input, history_mapping):
172172
buffer_name=HISTORY_BUFFER,
173173
wrap_lines=False,
174174
lexer=PygmentsLexer(PythonLexer),
175-
input_processors=default_processors),
175+
highlighters=highlighters),
176176
left_margins=[HistoryMargin(history_mapping)],
177177
scroll_offsets=ScrollOffsets(top=2, bottom=2)),
178178
# Separator.
@@ -183,7 +183,8 @@ def create_layout(python_input, history_mapping):
183183
content=BufferControl(
184184
buffer_name=DEFAULT_BUFFER,
185185
wrap_lines=False,
186-
input_processors=[GrayExistingText(history_mapping)] + default_processors,
186+
highlighters=highlighters,
187+
input_processors=[GrayExistingText(history_mapping)],
187188
lexer=PygmentsLexer(PythonLexer)),
188189
left_margins=[ResultMargin(history_mapping)],
189190
scroll_offsets=ScrollOffsets(top=2, bottom=2)),

0 commit comments

Comments
 (0)