69 lines
1.9 KiB
Rust
Raw Normal View History

2021-08-11 23:34:35 +08:00
use crate::{
client::view::FormatExt,
2021-08-12 13:57:41 +08:00
core::{Attribute, AttributeScope, Attributes, Delta, DeltaBuilder, DeltaIter, Interval},
2021-08-11 23:34:35 +08:00
};
pub struct FormatLinkAtCaretPositionExt {}
impl FormatExt for FormatLinkAtCaretPositionExt {
fn apply(&self, delta: &Delta, interval: Interval, attribute: &Attribute) -> Option<Delta> {
2021-08-12 13:57:41 +08:00
let mut iter = DeltaIter::new(delta);
iter.seek(interval.start);
let (before, after) = (iter.next(), iter.next());
let mut start = interval.start;
let mut retain = 0;
if let Some(before) = before {
if before.contain_attribute(attribute) {
start -= before.length();
retain += before.length();
}
}
if let Some(after) = after {
if after.contain_attribute(attribute) {
if retain != 0 {
retain += after.length();
}
}
}
if retain == 0 {
return None;
}
Some(
DeltaBuilder::new()
.retain(start, Attributes::default())
.retain(retain, (attribute.clone()).into())
.build(),
)
2021-08-11 23:34:35 +08:00
}
}
pub struct ResolveLineFormatExt {}
impl FormatExt for ResolveLineFormatExt {
fn apply(&self, delta: &Delta, interval: Interval, attribute: &Attribute) -> Option<Delta> {
2021-08-12 13:57:41 +08:00
if attribute.scope != AttributeScope::Block {
return None;
}
let mut new_delta = Delta::new();
new_delta.retain(interval.start, Attributes::default());
let mut iter = DeltaIter::new(delta);
iter.seek(interval.start);
None
2021-08-11 23:34:35 +08:00
}
}
pub struct ResolveInlineFormatExt {}
impl FormatExt for ResolveInlineFormatExt {
fn apply(&self, delta: &Delta, interval: Interval, attribute: &Attribute) -> Option<Delta> {
unimplemented!()
}
}