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

De-traitify text module #515

Merged
merged 6 commits into from
Sep 23, 2024
Merged

De-traitify text module #515

merged 6 commits into from
Sep 23, 2024

Conversation

PoignardAzur
Copy link
Contributor

No description provided.

Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

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

I agree with this change. Not approving as PR is draft

@@ -675,27 +616,43 @@ impl<Str: Deref<Target = str> + TextStorage> Selectable for Str {
}
}

/// A cursor type that implements `EditableTextCursor` for string types
/// A cursor type with helper methods for working with strings.
#[derive(Debug)]
pub struct StringCursor<'a> {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this still pub? It has no public API except for construction.

masonry/src/text/selection.rs Outdated Show resolved Hide resolved
masonry/src/widget/prose.rs Outdated Show resolved Hide resolved
masonry/src/widget/label.rs Outdated Show resolved Hide resolved
@PoignardAzur PoignardAzur marked this pull request as ready for review September 19, 2024 16:16
@PoignardAzur
Copy link
Contributor Author

Since I keep delaying the text refactor, and this is mostly ready, I'm removing the draft status and the TMP commit. I'll do the text refactor in another branch.

Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

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

This is a big improvement, and doesn't seem to regress behaviour.

Comment on lines +199 to 201
pub fn offset_for_delete_backwards(caret_position: usize, text: &impl AsRef<str>) -> usize {
backspace_offset(text.as_ref(), caret_position)
}
Copy link
Member

Choose a reason for hiding this comment

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

I'd probably just delete this function (to be clear, this same comment applies to the old version as well...)

Comment on lines 45 to 47
// We might change this to a rope based structure at some point.
// If you need a text box which uses a different text type, you should
// create a custom widget
Copy link
Member

Choose a reason for hiding this comment

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

The gist of this comment should be moved into TextEditor.

impl<T: EditableText> Deref for TextEditor<T> {
type Target = TextWithSelection<T>;
impl Deref for TextEditor {
type Target = TextWithSelection<String>;
Copy link
Member

Choose a reason for hiding this comment

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

I suspect we might want to remove this Deref at some point - it's a bit messy. Not a job for this PR

Comment on lines 467 to 468
// Currently, this is used for underlining IME suggestions
// applying a brush to selected text.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Currently, this is used for underlining IME suggestions
// applying a brush to selected text.
// Currently, this is used for:
// - underlining IME suggestions
// - applying a brush to selected text.

or

Suggested change
// Currently, this is used for underlining IME suggestions
// applying a brush to selected text.
// Currently, this is used for underlining IME suggestions
// and applying a brush to selected text.

fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.debug_struct("TextLayout")
.field("text", &self.text.as_str().len())
.field("text", &self.text.as_ref())
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we want this to be truncated?

Copy link
Member

Choose a reason for hiding this comment

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

?

}
}

impl<Str: Deref<Target = str> + AsRef<str> + Eq> Selectable for Str {
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit confused why this needs both Deref and AsRef

Comment on lines 262 to 265
#[cfg(FALSE)]
if !self.editor.text().links().is_empty() {
tracing::warn!("Links present in text, but not yet integrated");
}
Copy link
Member

Choose a reason for hiding this comment

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

Probably should just have the same comment as Prose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm removing references to links for now. They were copy-pasted from Label's implementation, but I don't see links in editable text being implemented any time soon.

@@ -686,27 +627,43 @@ impl<Str: Deref<Target = str> + TextStorage> Selectable for Str {
}
}

/// A cursor type that implements `EditableTextCursor` for string types
/// A cursor type with helper methods for working with strings.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// A cursor type with helper methods for working with strings.
/// A cursor type with helper methods for moving through strings.

This helps make it clear to readers that the methods are mutating a cursor position

Copy link
Contributor

@jaredoconnell jaredoconnell left a comment

Choose a reason for hiding this comment

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

Tested without issue. It looks like an improvement. Should be good once Daniel's comments are addressed.

@PoignardAzur PoignardAzur added this pull request to the merge queue Sep 23, 2024
Merged via the queue into main with commit 0308db2 Sep 23, 2024
17 checks passed
@PoignardAzur PoignardAzur deleted the refactor_text branch September 23, 2024 09:17
@mwcampbell mwcampbell mentioned this pull request Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants