-
Notifications
You must be signed in to change notification settings - Fork 258
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
feat: Add selection of multiple marks for table widget #1104
base: main
Are you sure you want to change the base?
Conversation
Edit: first two points are resolved in 31de358 To keep this proof of concept PR small, I didn't address the following features:
|
Perhaps move I suspect this should be an enum named |
I'm tempted to leave the |
Selection is something done normally with the cursor. Which row is selected is moved up / down by keyboard / mouse. Maybe I am mainly tipped of by the PR title, haven't really looked into the implementation yet. |
Generally most widgets / controls in other frameworks will have a flag that is set to enable multi select. This is not generally enabled by default. It feels a bit odd to me for that to be different here. Does that sway you? |
I am also fine with cursor and selection. Currently, the selection is the cursor. Mixing these feels weird to me.
They are likely mouse based? |
Maybe the name of the PR should be "multi-mark" instead? We use the terminology "selection" to mean current cursor position. In this PR, you can "mark" the current cursor selection and the state will remember the e.g. in |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1104 +/- ##
======================================
Coverage 94.3% 94.4%
======================================
Files 61 61
Lines 14768 15131 +363
======================================
+ Hits 13932 14285 +353
- Misses 836 846 +10 ☔ View full report in Codecov by Sentry. |
I think (could be worng) Selection and Highlight are the two concept names I'd use for what you're calling Mark and Selection. I'm not 100% sure of this though. |
We unfortunately already have But you are right, we use I'm open to suggestions on how to proceed. |
Yeah, I think this is a difficult one to get right - I wonder if the table would be worth moving out of Ratatui to get some higher velocity / experimental breaking changes like this and some of the other things (multi-select, built-in scrolling, column / cell selection, borders, property name changes etc.)? |
I see the appeal but I'm not sure I want to go down that route. I'd guess an external package containing a |
/// Set the symbol to be displayed in front of the unmarked row | ||
/// | ||
/// This is a fluent setter method which must be chained or used as it consumes self | ||
/// | ||
/// # Examples | ||
/// | ||
/// ```rust | ||
/// # use ratatui::{prelude::*, widgets::*}; | ||
/// # let rows = [Row::new(vec!["Cell1", "Cell2"])]; | ||
/// # let widths = [Constraint::Length(5), Constraint::Length(5)]; | ||
/// let table = Table::new(rows, widths).unmark_symbol(" "); | ||
/// ``` | ||
#[must_use = "method moves the value of self and returns the modified value"] | ||
pub fn unmark_symbol<T: Into<Text<'a>>>(mut self, unmark_symbol: T) -> Self { | ||
self.unmark_symbol = unmark_symbol.into(); | ||
self | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better name for this? nomark_symbol
? blank_symbol
?
2707645
to
b712034
Compare
We can feature flag the new table in or something like that. I guess it would only really cause problems for situations where another library uses the table widget as part of its rendering. That seems pretty niche however (perhaps tui-logger or similar crates might be affected). Either way, given that the table has many things that it doesn't do, I'd really suggest that if we want to make it really nice getting it out of Ratatui and into a separate crate is the right thing to do. This would allow faster iteration, more frequent breaking changes / unstable ideas, and doing the right thing with respect to the existing downsides of the table without having to worry about existing users (e.g. rendering tables with large numbers of rows with reasonable perf) |
This PR allows users to display a mark next to multiple rows. The marked rows are stored in the table.
e.g. here's a table with 2 rows marked and the first row selected (i.e. where the cursor currently is located).
If we move the cursor down 1, the marked row and the currently selected row overlap:
The index for all marked rows can be retrieved from
TableState::marked()
. This PR adds other methods to theTableState
struct to manipulate the marks.