diff --git a/src/buffer.rs b/src/buffer.rs index 75678aa..15d1900 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -237,6 +237,21 @@ pub struct Buffer { scratch: ShapeBuffer, } +impl Clone for Buffer { + fn clone(&self) -> Self { + Self { + lines: self.lines.clone(), + metrics: self.metrics, + width: self.width, + height: self.height, + scroll: self.scroll, + redraw: self.redraw, + wrap: self.wrap, + scratch: ShapeBuffer::default(), + } + } +} + impl Buffer { /// Create an empty [`Buffer`] with the provided [`Metrics`]. /// This is useful for initializing a [`Buffer`] without a [`FontSystem`]. diff --git a/src/buffer_line.rs b/src/buffer_line.rs index 64f706c..ec6c661 100644 --- a/src/buffer_line.rs +++ b/src/buffer_line.rs @@ -4,7 +4,7 @@ use alloc::{string::String, vec::Vec}; use crate::{Align, AttrsList, FontSystem, LayoutLine, ShapeBuffer, ShapeLine, Shaping, Wrap}; /// A line (or paragraph) of text that is shaped and laid out -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct BufferLine { //TODO: make this not pub(crate) text: String, diff --git a/src/edit/mod.rs b/src/edit/mod.rs index 01c89cf..76bff0e 100644 --- a/src/edit/mod.rs +++ b/src/edit/mod.rs @@ -176,11 +176,7 @@ pub trait Edit<'buffer> { match self.buffer_ref_mut() { BufferRef::Owned(buffer) => f(buffer), BufferRef::Borrowed(buffer) => f(buffer), - BufferRef::Arc(arc) => match Arc::get_mut(arc) { - Some(buffer) => f(buffer), - //TODO: use make_mut? - None => panic!("BufferRef::Arc cannot be accessed mutibly"), - }, + BufferRef::Arc(buffer) => f(Arc::make_mut(buffer)), } } diff --git a/src/shape.rs b/src/shape.rs index 88c1439..e480a66 100644 --- a/src/shape.rs +++ b/src/shape.rs @@ -379,7 +379,7 @@ fn shape_skip( } /// A shaped glyph -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct ShapeGlyph { pub start: usize, pub end: usize, @@ -423,7 +423,7 @@ impl ShapeGlyph { } /// A shaped word (for word wrapping) -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct ShapeWord { pub blank: bool, pub glyphs: Vec, @@ -527,7 +527,7 @@ impl ShapeWord { } /// A shaped span (for bidirectional processing) -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct ShapeSpan { pub level: unicode_bidi::Level, pub words: Vec, @@ -638,7 +638,7 @@ impl ShapeSpan { } /// A shaped line (or paragraph) -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct ShapeLine { pub rtl: bool, pub spans: Vec,