urwid_readline icon indicating copy to clipboard operation
urwid_readline copied to clipboard

[bug] "up" keypress not properly handled

Open adbenitez opened this issue 10 months ago • 1 comments

when "up" key is pressed and the editor is already at the first line, keypress should be considered not handled and propagated to parent widget, that seems to be already intended at:

https://github.com/rr-/urwid_readline/blob/46cfd3bba7c4028a7659e5317ca712db6248e1e8/urwid_readline/readline_edit.py#L139-L140

but then previous_line() is not returning False when there is not previous line:

https://github.com/rr-/urwid_readline/blob/46cfd3bba7c4028a7659e5317ca712db6248e1e8/urwid_readline/readline_edit.py#L213-L215

this is due to that max(0, y - 1) which causes to always pass 0 at the worse case so move_cursor_to_coords() never actually returns False since line 0 is valid, max(0, y - 1) is unnecessary because move_cursor_to_coords() will check this and return the expected False result if the coordinate is out of bounds:

    def move_cursor_to_coords(
        self,
        size: tuple[int],
        x: int | Literal[Align.LEFT, Align.RIGHT],
        y: int,
    ) -> bool:
        """
        Set the cursor position with (x,y) coordinates.
        Returns True if move succeeded, False otherwise.
        ...
        """
        (maxcol,) = size
        trans = self.get_line_translation(maxcol)
        _top_x, top_y = self.position_coords(maxcol, 0)
        if y < top_y or y >= len(trans):
            return False

        pos = text_layout.calc_pos(self.get_text()[0], trans, x, y)
        e_pos = min(max(pos - len(self.caption), 0), len(self.edit_text))
        self.edit_pos = e_pos
        self.pref_col_maxcol = x, maxcol
        self._invalidate()
        return True

adbenitez avatar Apr 02 '24 16:04 adbenitez

@neiljp can you confirm this doesn't break anything on your end? Thanks.

rr- avatar Apr 02 '24 17:04 rr-

@Niloth-p Would you be up for checking if this is a problem? (@rr- @adbenitez Apologies for the delay, this slipped through my email)

neiljp avatar May 09 '24 16:05 neiljp

@neiljp can you confirm this doesn't break anything on your end? Thanks.

Hi @rr- @adbenitez ! Sorry for the delay since Neil pinged me in. Checked the issue and the PR change - both seem to be working fine, no changes in behaviour.

We don't currently use these particular returned keypresses, so this issue has not been affecting us. But, this PR would allow us to use them in future ofc. :)

Niloth-p avatar May 11 '24 07:05 Niloth-p