-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 support for buffers other than a String
in TextEdit
#399
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.
Looks good!
@@ -478,18 +523,24 @@ impl<'t> TextEdit<'t> { | |||
let did_mutate_text = match event { | |||
Event::Copy => { | |||
if cursorp.is_empty() { | |||
copy_if_not_password(ui, text.clone()); | |||
copy_if_not_password(ui, text.as_ref().to_owned()); |
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.
copy_if_not_password(ui, text.as_ref().to_owned()); | |
copy_if_not_password(ui, text.to_string()); |
is a bit shorter (and iirc it should work since text
implements Display
)
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.
Wouldn't calling to_owned
on a str
bypass the std::fmt
formatting, though?
I don't know how it works in general, but there might be a specialization for String
and str
so it might not matter.
The branch conflict seems to be because of the changelog, I added the "Added" heading, should I rebase on master? |
yeah, rebase on or merge in master |
…pes other than `String`.
This allows the user to implement text inserting depedent on their type instead of using a `String` and converting back to `S`, which may be a lossless convertion.
…xtBuffer::delete_range`.
…ed into the buffer. This allows implementations to "saturate" the buffer, only allowing for a limited length of characters to be inserted.
Removed `From<String>` bound for `TextBuffer`.
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Should be rebased now? I had to do a |
Adds support for custom buffers to be used with the
TextEdit
widget.I haven't made an issue because this was relatively simple to implement and it's something I need for one of my projects, so I'd likely re-use it even if you'd prefer to not make this change.
The motivation behind this for me is to use an
AsciiString
from theascii
crate as the underlying buffer, and also limit it's size to a certain number of max characters.In order to achieve this the
TextBuffer
trait hands responsibility of any actual insertions / removals to the type itself, with a default impl forString
.Due to the default type of
String
I believe this doesn't break any existing code and a default ofString
is likely the best option either way.This also modifies most operations to be in-place instead of creating a new string and assigning it to it. This should (?) also increase performance slightly, but I doubt it's too noticeable.