Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexError with TextBlock mouse integration #98

Closed
PabloLec opened this issue Mar 10, 2021 · 0 comments
Closed

IndexError with TextBlock mouse integration #98

PabloLec opened this issue Mar 10, 2021 · 0 comments
Labels
Bug Something isn't working Core Add for issues having to do with core functions Widgets Add for issues having to do with widgets
Milestone

Comments

@PabloLec
Copy link
Contributor

PabloLec commented Mar 10, 2021

Describe the bug
When using a ScrollTextBlock widget instantiated via add_text_block, mouse integration may raise an IndexError.
This occurs when you click below your text. For example:

  • With an empty TextBlock, click in the middle of the widget to focus it and then start typing.
  • Write a few lines and click in the middle/end of the text block then start typing again.

An error will be raised as the cursor Y pos is bigger than the number of text lines.

To Reproduce
Steps to reproduce the behavior:

  1. Create an app with a text block
  2. Click in the middle of the widget (below the first empty line) to give him focus.
  3. Start typing.

Expected behavior
Obviously, the error should not be raised. Instead, the cursors should move at the very end of the text to let the user continue typing.

Screenshots
Sorry, I wanted to provide a nice little GIF but I can't do it right now, here is the error thrown:

  File "/tmp/recoverpy/env/lib/python3.8/site-packages/py_cui/__init__.py", line 318, in start
    curses.wrapper(self._draw)
  File "/usr/lib/python3.8/curses/__init__.py", line 105, in wrapper
    return func(stdscr, *args, **kwds)
  File "/tmp/recoverpy/env/lib/python3.8/site-packages/py_cui/__init__.py", line 1545, in _draw
    self._handle_key_presses(key_pressed)
  File "/tmp/recoverpy/env/lib/python3.8/site-packages/py_cui/__init__.py", line 1423, in _handle_key_presses
    selected_widget._handle_key_press(key_pressed)
  File "/tmp/recoverpy/env/lib/python3.8/site-packages/py_cui/widgets.py", line 833, in _handle_key_press
    self._insert_char(key_pressed)
  File "/tmp/recoverpy/env/lib/python3.8/site-packages/py_cui/ui.py", line 1311, in _insert_char
    current_line = self.get_current_line()
  File "/tmp/recoverpy/env/lib/python3.8/site-packages/py_cui/ui.py", line 1110, in get_current_line
    return self._text_lines[self._cursor_text_pos_y]
IndexError: list index out of range

Environment:

  • OS: Ubuntu 20.10 AMD64 & Ubuntu 20.10 ARM64
  • Terminal: bash & zsh
  • Version: 0.1.2 & 0.1.3 (pre-release)

Edit: Opened PR #99 that fixes the issue 😉

@PabloLec PabloLec added the Bug Something isn't working label Mar 10, 2021
@jwlodek jwlodek added this to the v0.1.4 milestone Apr 18, 2021
@jwlodek jwlodek added Widgets Add for issues having to do with widgets Core Add for issues having to do with core functions labels Apr 18, 2021
@jwlodek jwlodek mentioned this issue May 29, 2021
3 tasks
@jwlodek jwlodek closed this as completed Oct 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Core Add for issues having to do with core functions Widgets Add for issues having to do with widgets
Projects
None yet
Development

No branches or pull requests

2 participants