Skip to content

Editor cleanups / extensions, esp Rc<String> support#697

Merged
dhardy merged 8 commits into
masterfrom
push-vpykntulpstv
May 31, 2026
Merged

Editor cleanups / extensions, esp Rc<String> support#697
dhardy merged 8 commits into
masterfrom
push-vpykntulpstv

Conversation

@dhardy
Copy link
Copy Markdown
Collaborator

@dhardy dhardy commented May 31, 2026

Some fixes / simplifications for recent PRs (see commits).

The editor types Common and Part are now pub. New pub fns:

  • Common::direction, set_direction, update_direction, set_colors
  • Part::status, prepare_wrap
  • impl<S: ToString> From<S> for Part
  • Part::text and Editor::text -> &Rc<String>
  • Part::clone_text and Editor::clone_text -> Rc<String>
  • Editor::set_text(&mut self, cx: _, text: Rc<String>

Copy link
Copy Markdown
Collaborator Author

@dhardy dhardy left a comment

Choose a reason for hiding this comment

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

There is a weak incentive here to use Arc<String> instead of Rc<String> (since it supports Send). I'm not convinced it is sufficient motivation.

A stronger motivation might be to spawn a worker thread doing some work over cloned text contents so this might be revised later. (Note: &String is Send so it may still be possible to send text contents to a worker thread without a deep clone using scoped threads.)

Comment thread examples/gallery.rs
Comment on lines 94 to 96
fn activate(&mut self, edit: &mut Editor, cx: &mut EventCx, _: &Data) -> IsUsed {
cx.push(Item::Edit(edit.clone_string()));
cx.push(Item::Edit(edit.clone_text()));
Used
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The gallery can now clone by ref-count instead of copying String contents, passing Rc<String> as a message

Comment thread examples/gallery.rs
Comment on lines -159 to +158
Button::label_msg("&Press me", Item::Button).map_any()
Button::label("&Press me").with(|cx, _| cx.push(Item::Button)).map_any()
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

One workaround was required: Button::label_msg requires the message type support Send (no longer the case due to usage of Rc). We can avoid this requirement by direct implementation of the closure.

@dhardy dhardy force-pushed the push-vpykntulpstv branch from 4ff04cd to 7392127 Compare May 31, 2026 07:18
@dhardy dhardy merged commit cd1b21c into master May 31, 2026
5 checks passed
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.

1 participant