pub struct TextBuffer { /* private fields */ }Expand description
A UTF-8 text buffer with UTF-16-indexed access.
All public offsets are UTF-16 code units, matching the JavaScript side.
Implementations§
Source§impl TextBuffer
impl TextBuffer
pub fn new(text: impl Into<String>) -> Self
pub fn as_str(&self) -> &str
Sourcepub fn char_count(&self) -> usize
pub fn char_count(&self) -> usize
Length in Unicode scalar values. Differs from Self::len16 wherever a
character outside the BMP occurs.
pub fn is_empty(&self) -> bool
Sourcepub fn slice16(&self, start: usize, end: usize) -> Result<String, FcError>
pub fn slice16(&self, start: usize, end: usize) -> Result<String, FcError>
Extracts a substring using UTF-16 offsets.
Sourcepub fn replace16(
&mut self,
start: usize,
end: usize,
replacement: &str,
) -> Result<Range16, FcError>
pub fn replace16( &mut self, start: usize, end: usize, replacement: &str, ) -> Result<Range16, FcError>
Replaces a UTF-16 range, returning the range the inserted text now occupies so a caller can place the caret after an edit without recomputing it.
Sourcepub fn lines16(&self) -> Vec<Range16>
pub fn lines16(&self) -> Vec<Range16>
Splits into lines, reporting each line’s range in UTF-16 units.
Terminators are not included, and a trailing newline produces a final empty line – the behaviour an editor needs so the caret can sit on the line after a final newline.
Source§impl TextBuffer
impl TextBuffer
Sourcepub fn js_from(text: String) -> TextBuffer
pub fn js_from(text: String) -> TextBuffer
Constructs a buffer from JS.
constructor rather than a static factory: it makes the type
instantiable from JavaScript, which wasm_bindgen otherwise refuses
because it only generates ABI glue for values it can move across the
boundary.
pub fn text(&self) -> String
pub fn js_len16(&self) -> usize
pub fn js_char_count(&self) -> usize
Sourcepub fn js_lines16(&self) -> Vec<u32>
pub fn js_lines16(&self) -> Vec<u32>
Returns flat [start, end, ...] coordinates, one pair per line.
pub fn js_slice16(&self, start: usize, end: usize) -> Result<String, JsValue>
Sourcepub fn js_replace16(
&mut self,
start: usize,
end: usize,
replacement: &str,
) -> Result<Vec<u32>, JsValue>
pub fn js_replace16( &mut self, start: usize, end: usize, replacement: &str, ) -> Result<Vec<u32>, JsValue>
Replaces a range and returns the [start, end] the inserted text now
occupies, so the caller can place the caret without recomputing it.
pub fn js_line_at(&self, offset: usize) -> Result<Vec<u32>, JsValue>
Trait Implementations§
Source§impl Clone for TextBuffer
impl Clone for TextBuffer
Source§impl Debug for TextBuffer
impl Debug for TextBuffer
Source§impl Default for TextBuffer
impl Default for TextBuffer
Source§impl From<TextBuffer> for JsValue
impl From<TextBuffer> for JsValue
Source§fn from(value: TextBuffer) -> Self
fn from(value: TextBuffer) -> Self
Source§impl FromWasmAbi for TextBuffer
impl FromWasmAbi for TextBuffer
Source§impl IntoWasmAbi for TextBuffer
impl IntoWasmAbi for TextBuffer
Source§impl LongRefFromWasmAbi for TextBuffer
impl LongRefFromWasmAbi for TextBuffer
Source§impl OptionFromWasmAbi for TextBuffer
impl OptionFromWasmAbi for TextBuffer
Source§impl OptionIntoWasmAbi for TextBuffer
impl OptionIntoWasmAbi for TextBuffer
Source§impl RefFromWasmAbi for TextBuffer
impl RefFromWasmAbi for TextBuffer
Source§type Anchor = RcRef<TextBuffer>
type Anchor = RcRef<TextBuffer>
Self for the duration of the
invocation of the function that has an &Self parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.Source§impl RefMutFromWasmAbi for TextBuffer
impl RefMutFromWasmAbi for TextBuffer
impl SupportsConstructor for TextBuffer
impl SupportsInstanceProperty for TextBuffer
impl SupportsStaticProperty for TextBuffer
Source§impl TryFromJsValue for TextBuffer
impl TryFromJsValue for TextBuffer
Source§impl VectorFromWasmAbi for TextBuffer
impl VectorFromWasmAbi for TextBuffer
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[TextBuffer]>
Source§impl VectorIntoWasmAbi for TextBuffer
impl VectorIntoWasmAbi for TextBuffer
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[TextBuffer]>) -> Self::Abi
Source§impl WasmDescribeVector for TextBuffer
impl WasmDescribeVector for TextBuffer
Auto Trait Implementations§
impl Freeze for TextBuffer
impl RefUnwindSafe for TextBuffer
impl Send for TextBuffer
impl Sync for TextBuffer
impl Unpin for TextBuffer
impl UnsafeUnpin for TextBuffer
impl UnwindSafe for TextBuffer
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> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.