pub struct Attachments { /* private fields */ }Expand description
Shared handle to the attachments staged on an EditorPane composer.
The composer’s owner keeps a clone (see EditorPane::attachments),
stages images with Attachments::push_image and collapsed pastes with
Attachments::push_text, and drains the queue on submit with
Attachments::take. The pane renders one framed card per visible
attachment above its status band, tinted with the attachment’s identity
color and captioned with its #N marker plus pixel resolution or paste
size.
Attachments::set_visible reconciles the band with the composer text:
an attachment whose inline reference was deleted hides — and returns on
undo — without losing its marker number.
Mutations change the pane’s height out of band, so the owner triggers a
relayout afterwards (e.g. crate::Ui::resize at the current width).
Implementations§
Source§impl Attachments
impl Attachments
Sourcepub fn push_image(&self, source: impl Into<Str>) -> Attachment
pub fn push_image(&self, source: impl Into<Str>) -> Attachment
Stages an image source, probing its pixel dimensions from the file header, and returns the staged descriptor.
Sourcepub fn push_text(&self, text: &str) -> Attachment
pub fn push_text(&self, text: &str) -> Attachment
Stages pasted text collapsed out of the composer and returns the staged descriptor.
Sourcepub fn take(&self) -> Vec<Attachment>
pub fn take(&self) -> Vec<Attachment>
Drains the whole queue, restarting marker numbering, and returns the visible attachments in marker order. Hidden descriptors — whose inline references the user deleted — are discarded, never handed to the host.
Examples found in repository?
801 pub fn handle_key(&mut self, key: Key) -> bool {
802 *self.edit_outcome.borrow_mut() = None;
803 let _ = self.editor_ui.handle_key(key);
804 let outcome = self
805 .edit_outcome
806 .borrow_mut()
807 .take()
808 .unwrap_or(EditOutcome::Ignored);
809 match outcome {
810 EditOutcome::Submitted(text) => {
811 let trimmed = text.trim();
812 if trimmed == "/switch" {
813 self.switch_requested = true;
814 return false;
815 }
816 if let Some(path) = trimmed
817 .strip_prefix("/attach")
818 .filter(|rest| rest.is_empty() || rest.starts_with(' '))
819 {
820 let path = path.trim().to_string();
821 if !path.is_empty() {
822 self.attach_image(&path);
823 }
824 return false;
825 }
826 let _ = self.attachments.take();
827 self.refresh_composer();
828 self
829 .transcript
830 .push(Entry::Submitted(Box::new(Submission::new(
831 text,
832 Self::message_width(self.last_viewport.width),
833 &self.ctx,
834 ))));
835 self.set_working(true, self.started_at.elapsed());
836 false
837 },
838 EditOutcome::Changed => {
839 self.reconcile_attachments();
840 false
841 },
842 EditOutcome::Ignored => {
843 if key == Key::Ctrl('c') {
844 return true;
845 }
846 if key != Key::Esc {
847 return false;
848 }
849 if self.work.borrow().working {
850 self.set_working(false, self.started_at.elapsed());
851 return false;
852 }
853 true
854 },
855 }
856 }Sourcepub fn set_visible(&self, visible: impl FnMut(&Attachment) -> bool) -> bool
pub fn set_visible(&self, visible: impl FnMut(&Attachment) -> bool) -> bool
Shows exactly the attachments visible accepts and hides the rest
(ones whose inline reference was deleted), returning whether
anything changed. Hidden attachments stay staged, so an undo can
bring them back.
Examples found in repository?
959 fn reconcile_attachments(&mut self) {
960 let charset = self.ctx.charset;
961 let changed = {
962 let editor = self.editor.borrow();
963 let text = editor.text();
964 let ranges = editor.atom_ranges();
965 self.attachments.set_visible(|attachment| {
966 let chip = chip_label(attachment, charset);
967 ranges
968 .iter()
969 .any(|&(start, end)| text.get(start..end) == Some(chip.as_str()))
970 })
971 };
972 if changed {
973 self.refresh_composer();
974 }
975 }Trait Implementations§
Source§impl Clone for Attachments
impl Clone for Attachments
Source§fn clone(&self) -> Attachments
fn clone(&self) -> Attachments
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for Attachments
impl Default for Attachments
Source§fn default() -> Attachments
fn default() -> Attachments
Auto Trait Implementations§
impl !RefUnwindSafe for Attachments
impl !Send for Attachments
impl !Sync for Attachments
impl !UnwindSafe for Attachments
impl Freeze for Attachments
impl Unpin for Attachments
impl UnsafeUnpin for Attachments
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more