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

Add DataTable.move_cursor #2479

Merged
merged 4 commits into from
May 8, 2023
Merged

Add DataTable.move_cursor #2479

merged 4 commits into from
May 8, 2023

Conversation

rodrigogiraoserrao
Copy link
Contributor

This will add the method DataTable.move_cursor.
This also fixes the animation you get when going left/right in a data table.

  • Docstrings on all new or modified functions / classes
  • Updated documentation
  • Updated CHANGELOG.md (where appropriate)

Closes #2471.
Closes #2472.

# scrolling because it may be animated.
self.call_next(self._scroll_cursor_into_view)

def move_cursor(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the API here personally, because the parameters are kind of dependent on each other. (e.g. if you pass coordinate and row, things get weird). Do we need the coordinate parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you pass a coordinate and a row, you get an error.

I opted for this signature because if the cursor is a coordinate (DataTable.cursor_coordinate) it makes sense to accept the same type; then I added row and column as convenience parameters, which work similarly to the parameters after and before in methods like Widget.mount and Widget.move_child

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I concur with Darren here. The signature can be ambiguous. Given there can be row and column cursors, where only a single value makes sense, I think we should drop the coordinate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even when the cursor type is row/column, the reactive attribute cursor_coordinate is a full coordinate with X and Y coordinates, so this is aligned with that.
But if you all think it is a bad idea 🤷

# scrolling because it may be animated.
self.call_next(self._scroll_cursor_into_view)

def move_cursor(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I concur with Darren here. The signature can be ambiguous. Given there can be row and column cursors, where only a single value makes sense, I think we should drop the coordinate.

src/textual/widgets/_data_table.py Outdated Show resolved Hide resolved
rodrigogiraoserrao added a commit that referenced this pull request May 4, 2023
rodrigogiraoserrao added a commit that referenced this pull request May 4, 2023
* Tweaks to DataTable docs.

Related PRs: #2479.

* Fix link.
@rodrigogiraoserrao rodrigogiraoserrao self-assigned this May 5, 2023
@rodrigogiraoserrao rodrigogiraoserrao added enhancement New feature or request Task labels May 5, 2023
@willmcgugan willmcgugan merged commit 819b2f1 into main May 8, 2023
@willmcgugan willmcgugan deleted the datatable-cursor branch May 8, 2023 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add method move_cursor to DataTable Moving cursor sideways in the DataTable should animate.
3 participants