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

make text selection a struct #203

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion atspi-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,25 @@ use zvariant::Type;

pub type Result<T> = std::result::Result<T, AtspiError>;

pub type TextSelection = (ObjectRef, i32, ObjectRef, i32, bool);
/// Describes a selection of text, including selections across object boundaries.
/// For example, selecting from the beginning of a paragraph to half way through a link would cause
/// the start and end object references to be different.
Copy link
Collaborator

Choose a reason for hiding this comment

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

TIL, again! Great stuff, thanks!

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
pub struct TextSelection {
/// starting object reference
start_obj: ObjectRef,
/// text offset within `start_obj`
start_idx: i32,
/// ending object reference
end_obj: ObjectRef,
/// text offset within `end_obj`
end_idx: i32,
/// is the `start_obj` active;
///
/// This is the same as querying for the [`StateSet`], then checking if [`State::Active`] is contained.
/// See `atspi_proxies::accessible::AccessibleProxy` for more information on checking state.
start_is_active: bool,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type)]
#[repr(u32)]
Expand Down Expand Up @@ -229,4 +247,12 @@ mod tests {
let match_type_signature = rule_signature.slice(3..4);
assert_eq!(MatchType::signature(), match_type_signature);
}

#[test]
fn validate_text_selection_signature() {
let selection_signature = method_args_signature!(member: "GetTextSelections", interface: "org.a11y.atspi.Document", argument: "selections")
.slice(1..);
// this signature is written: `a(...)`, where `(...)` is the signature we want to compare against
assert_eq!(TextSelection::signature(), selection_signature);
}
}
1 change: 1 addition & 0 deletions type_validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ We leverage [zbus-lockstep](https://github.com/luukvanderduim/zbus-lockstep/) to
| `ScrollType` || `Component::ScrollTo` argument `type`|
| `Politeness` || `Event.Object::Announcement` argument `politeness`|
| `ObjectMatchRule` || `Collection::GetMatches` argument 'rule' contains `Vec<Role>` and `StateSet` which are defined as "ai", but `Role` and `StateSet` are not.|
| `TextSelection` | ✓ | `Document::GetTextSelections` argument `selections` contains `Vec<TextSelection>`
Loading