mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 13:25:51 +03:00
[GH-ISSUE #838] How can I show an InputField at the position of the current list item? #607
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#607
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @quantonganh on GitHub (Apr 8, 2023).
Original GitHub issue: https://github.com/rivo/tview/issues/838
Hi,
I'm building something like this:
I want to allow to edit the list item: for e.g, when user press
e, I want to show an InputField at the position of the list item. To do that, I can create a Modal on top of this layout, will all items nil except for the one at the list item's position:and then I can call it in the
SetInputCapturefunc:https://gist.github.com/quantonganh/88d14214cffcf226cfcd7bea5a17ecf3
If the list is short, it will be ok. But if the current index is greater than the height of the screen / 2 (there is a blank line between each list item), it shows nothing as it is out of the screen.
Let me give you an example:
Please look at the above screenshot: if I scroll down, then up to hide some top items, then I stop at the item that has index 5 and press
e, the InputField will be shown at the position of "item 8".So, how can I show an InputField at the position of the current list item?
If I can get the position of the "item 5" on the screen (2 in this case, if we start from 0 - "item 3", 1 - "item 4"), then I can show the InputField at line: 4 + 2*2 = 8 (and it will be matched, since the "New chat" button has height of 3, the "item 5" is at line 5).
@quantonganh commented on GitHub (Apr 11, 2023):
I solved it by counting how many items are hidden base on the height of list:
@rivo commented on GitHub (Jun 18, 2023):
This is probably more complicated when the list is longer than the screen height and there is scrolling involved.
There is currently no solution to this. Eventually, I might add a function to return the current selection's screen position. It will be needed in
Table,TreeView, and others as well.But for now, there is nothing like this in
tview.