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

Add an option for up and down keys to move vertically across "visual rows"

Open
#1,049 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I've looked for it, but there doesn't seem to be a way to do this easily currently. That is, having the up and down keys behave like a lot of text editors moving the cursor in an imaginary vertical line across the prompt, only straying from that when shorter rows are encountered and at the beginning/end of the document. Right now it seems that they go to the same index on the previous/next internal line, and not the "visual row".

My own hacky implementation is in this file:
https://github.com/MikkoMMM/Clover-Edition/blob/master/inline_editor.py
And even then I encountered problems where rarely but seemingly randomly the cursor would go in the slightly wrong column. That's why for example pressing left and right also manually invoke update_stored_pos in addition to the textf.buffer.on_cursor_position_changed event. And since I wasn't sure about the source of the problem, I also reimplemented the textf.document.cursor_position_col and textf.document.cursor_position_row functions.

So, it's a very messy solution and I'm not sure if it's working perfectly even still. It would be so much better if Python Prompt Toolkit could just offer the option to do it itself, and properly.

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 reviewing the linked inline_editor.py implementation and the referenced textf.buffer.on_cursor_position_changed event, document.cursor_position_col, and document.cursor_position_row functions. Compare how it tracks visual rows and cursor columns with the current prompt-toolkit behavior. Done means providing a built-in option for vertical movement across visual rows without the reported column errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 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.