prompt-toolkit / prompt-toolkit/python-prompt-toolkit

Transformation.display_to_source is never called

Open
#1,334 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Description

When I'm looking at the code, the only call to display_to_source is made in BufferControl.mouse_handler. If mouse_support=False, display_to_source is never called. If mouse_support=True, display_to_source is only called for clicks.

Here is some demo code:

from prompt_toolkit import Application
from prompt_toolkit.buffer import Buffer
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.layout.containers import Window
from prompt_toolkit.layout.controls import BufferControl
from prompt_toolkit.layout.layout import Layout
from prompt_toolkit.layout.processors import Processor, Transformation


class MyProcessor(Processor):
    def apply_transformation(self, transformation_input):
        return Transformation(
            fragments=transformation_input.fragments,

            # This exits the application as expected.
            #source_to_display=exit,

            # This does nothing unless mouse support is enabled and the
            # BufferControl is clicked.
            display_to_source=exit,
        )

root_container = Window(BufferControl(
    buffer=Buffer(),
    input_processors=[MyProcessor()],
))

kb = KeyBindings()
@kb.add('c-q')
def exit_(event):
    event.app.exit()

app = Application(
    layout=Layout(root_container),
    key_bindings=kb,
    mouse_support=True,
)
app.run()

The application runs normally until you click on it.

Setting mouse_support=False turns display_to_source into dead code.

Uncommenting source_to_display=exit confirms that the Transformation object is used.

Is this a bug or am I misunderstanding how this is supposed to work?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading BufferControl.mouse_handler and the Transformation handling around display_to_source, then run the demo from the issue with mouse support both enabled and disabled. Trace when source_to_display and display_to_source are consumed. Done means the intended display-to-source behavior is established and covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.