-
Notifications
You must be signed in to change notification settings - Fork 117
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
Conversation
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.
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> { |
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.
Why is this still pub
? It has no public API except for construction.
722c639
to
d35bd2e
Compare
d35bd2e
to
9220226
Compare
Co-authored-by: Daniel McNab <[email protected]>
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. |
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.
This is a big improvement, and doesn't seem to regress behaviour.
pub fn offset_for_delete_backwards(caret_position: usize, text: &impl AsRef<str>) -> usize { | ||
backspace_offset(text.as_ref(), caret_position) | ||
} |
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.
I'd probably just delete this function (to be clear, this same comment applies to the old version as well...)
// 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 |
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.
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>; |
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.
I suspect we might want to remove this Deref at some point - it's a bit messy. Not a job for this PR
masonry/src/text/layout.rs
Outdated
// Currently, this is used for underlining IME suggestions | ||
// applying a brush to selected text. |
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.
// 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
// 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()) |
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.
Maybe we want this to be truncated?
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.
?
masonry/src/text/selection.rs
Outdated
} | ||
} | ||
|
||
impl<Str: Deref<Target = str> + AsRef<str> + Eq> Selectable for Str { |
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.
I'm a bit confused why this needs both Deref and AsRef
masonry/src/widget/textbox.rs
Outdated
#[cfg(FALSE)] | ||
if !self.editor.text().links().is_empty() { | ||
tracing::warn!("Links present in text, but not yet integrated"); | ||
} |
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.
Probably should just have the same comment as Prose
?
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.
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.
masonry/src/text/selection.rs
Outdated
@@ -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. |
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.
/// 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
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.
Tested without issue. It looks like an improvement. Should be good once Daniel's comments are addressed.
No description provided.