Implement Clone for Buffer and use Arc::make_mut
This commit is contained in:
parent
0a11fb1045
commit
46d60a3723
4 changed files with 21 additions and 10 deletions
|
|
@ -237,6 +237,21 @@ pub struct Buffer {
|
||||||
scratch: ShapeBuffer,
|
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 {
|
impl Buffer {
|
||||||
/// Create an empty [`Buffer`] with the provided [`Metrics`].
|
/// Create an empty [`Buffer`] with the provided [`Metrics`].
|
||||||
/// This is useful for initializing a [`Buffer`] without a [`FontSystem`].
|
/// This is useful for initializing a [`Buffer`] without a [`FontSystem`].
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use alloc::{string::String, vec::Vec};
|
||||||
use crate::{Align, AttrsList, FontSystem, LayoutLine, ShapeBuffer, ShapeLine, Shaping, Wrap};
|
use crate::{Align, AttrsList, FontSystem, LayoutLine, ShapeBuffer, ShapeLine, Shaping, Wrap};
|
||||||
|
|
||||||
/// A line (or paragraph) of text that is shaped and laid out
|
/// A line (or paragraph) of text that is shaped and laid out
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct BufferLine {
|
pub struct BufferLine {
|
||||||
//TODO: make this not pub(crate)
|
//TODO: make this not pub(crate)
|
||||||
text: String,
|
text: String,
|
||||||
|
|
|
||||||
|
|
@ -176,11 +176,7 @@ pub trait Edit<'buffer> {
|
||||||
match self.buffer_ref_mut() {
|
match self.buffer_ref_mut() {
|
||||||
BufferRef::Owned(buffer) => f(buffer),
|
BufferRef::Owned(buffer) => f(buffer),
|
||||||
BufferRef::Borrowed(buffer) => f(buffer),
|
BufferRef::Borrowed(buffer) => f(buffer),
|
||||||
BufferRef::Arc(arc) => match Arc::get_mut(arc) {
|
BufferRef::Arc(buffer) => f(Arc::make_mut(buffer)),
|
||||||
Some(buffer) => f(buffer),
|
|
||||||
//TODO: use make_mut?
|
|
||||||
None => panic!("BufferRef::Arc cannot be accessed mutibly"),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -379,7 +379,7 @@ fn shape_skip(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A shaped glyph
|
/// A shaped glyph
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct ShapeGlyph {
|
pub struct ShapeGlyph {
|
||||||
pub start: usize,
|
pub start: usize,
|
||||||
pub end: usize,
|
pub end: usize,
|
||||||
|
|
@ -423,7 +423,7 @@ impl ShapeGlyph {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A shaped word (for word wrapping)
|
/// A shaped word (for word wrapping)
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct ShapeWord {
|
pub struct ShapeWord {
|
||||||
pub blank: bool,
|
pub blank: bool,
|
||||||
pub glyphs: Vec<ShapeGlyph>,
|
pub glyphs: Vec<ShapeGlyph>,
|
||||||
|
|
@ -527,7 +527,7 @@ impl ShapeWord {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A shaped span (for bidirectional processing)
|
/// A shaped span (for bidirectional processing)
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct ShapeSpan {
|
pub struct ShapeSpan {
|
||||||
pub level: unicode_bidi::Level,
|
pub level: unicode_bidi::Level,
|
||||||
pub words: Vec<ShapeWord>,
|
pub words: Vec<ShapeWord>,
|
||||||
|
|
@ -638,7 +638,7 @@ impl ShapeSpan {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A shaped line (or paragraph)
|
/// A shaped line (or paragraph)
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct ShapeLine {
|
pub struct ShapeLine {
|
||||||
pub rtl: bool,
|
pub rtl: bool,
|
||||||
pub spans: Vec<ShapeSpan>,
|
pub spans: Vec<ShapeSpan>,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue