mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-27 02:48:34 +00:00
Remove lifetime parameter from TextDimension trait
Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
parent
6a44a7448e
commit
a88cff4fa0
6 changed files with 39 additions and 51 deletions
|
@ -3056,7 +3056,7 @@ impl Editor {
|
|||
|
||||
pub fn selections<'a, D>(&self, cx: &'a AppContext) -> impl 'a + Iterator<Item = Selection<D>>
|
||||
where
|
||||
D: 'a + TextDimension<'a> + Ord,
|
||||
D: 'a + TextDimension + Ord,
|
||||
{
|
||||
let buffer = self.buffer.read(cx);
|
||||
let mut selections = self.selection_set(cx).selections::<D>(buffer).peekable();
|
||||
|
@ -3086,10 +3086,7 @@ impl Editor {
|
|||
})
|
||||
}
|
||||
|
||||
fn pending_selection<'a, D>(&self, cx: &'a AppContext) -> Option<Selection<D>>
|
||||
where
|
||||
D: 'a + TextDimension<'a>,
|
||||
{
|
||||
fn pending_selection<D: TextDimension>(&self, cx: &AppContext) -> Option<Selection<D>> {
|
||||
let buffer = self.buffer.read(cx);
|
||||
self.pending_selection.as_ref().map(|pending| Selection {
|
||||
id: pending.selection.id,
|
||||
|
@ -3108,10 +3105,7 @@ impl Editor {
|
|||
selection_count
|
||||
}
|
||||
|
||||
pub fn oldest_selection<'a, T>(&self, cx: &'a AppContext) -> Selection<T>
|
||||
where
|
||||
T: 'a + TextDimension<'a>,
|
||||
{
|
||||
pub fn oldest_selection<T: TextDimension>(&self, cx: &AppContext) -> Selection<T> {
|
||||
let buffer = self.buffer.read(cx);
|
||||
self.selection_set(cx)
|
||||
.oldest_selection(buffer)
|
||||
|
@ -3119,10 +3113,7 @@ impl Editor {
|
|||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn newest_selection<'a, T>(&self, cx: &'a AppContext) -> Selection<T>
|
||||
where
|
||||
T: 'a + TextDimension<'a>,
|
||||
{
|
||||
pub fn newest_selection<T: TextDimension>(&self, cx: &AppContext) -> Selection<T> {
|
||||
let buffer = self.buffer.read(cx);
|
||||
self.pending_selection(cx)
|
||||
.or_else(|| self.selection_set(cx).newest_selection(buffer))
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
use text::{Bias, Point, Selection};
|
||||
use editor::{display_map::ToDisplayPoint, Autoscroll, Editor, EditorSettings};
|
||||
use gpui::{
|
||||
action, elements::*, geometry::vector::Vector2F, keymap::Binding, Axis, Entity,
|
||||
MutableAppContext, RenderContext, View, ViewContext, ViewHandle,
|
||||
};
|
||||
use postage::watch;
|
||||
use text::{Bias, Point, Selection};
|
||||
use workspace::{Settings, Workspace};
|
||||
|
||||
action!(Toggle);
|
||||
|
|
|
@ -117,7 +117,7 @@ impl Anchor {
|
|||
|
||||
pub fn summary<'a, D>(&self, content: &'a BufferSnapshot) -> D
|
||||
where
|
||||
D: TextDimension<'a>,
|
||||
D: TextDimension,
|
||||
{
|
||||
content.summary_for_anchor(self)
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ impl<T> AnchorMap<T> {
|
|||
snapshot: &'a BufferSnapshot,
|
||||
) -> impl Iterator<Item = (D, &'a T)> + 'a
|
||||
where
|
||||
D: 'a + TextDimension<'a>,
|
||||
D: TextDimension,
|
||||
{
|
||||
snapshot
|
||||
.summaries_for_anchors(
|
||||
|
@ -160,7 +160,7 @@ impl AnchorSet {
|
|||
|
||||
pub fn iter<'a, D>(&'a self, content: &'a BufferSnapshot) -> impl Iterator<Item = D> + 'a
|
||||
where
|
||||
D: 'a + TextDimension<'a>,
|
||||
D: TextDimension,
|
||||
{
|
||||
self.0.iter(content).map(|(position, _)| position)
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ impl<T> AnchorRangeMap<T> {
|
|||
content: &'a BufferSnapshot,
|
||||
) -> impl Iterator<Item = (Range<D>, &'a T)> + 'a
|
||||
where
|
||||
D: 'a + TextDimension<'a>,
|
||||
D: TextDimension,
|
||||
{
|
||||
content
|
||||
.summaries_for_anchor_ranges(
|
||||
|
@ -212,7 +212,7 @@ impl<T> AnchorRangeMap<T> {
|
|||
content: &'a BufferSnapshot,
|
||||
) -> impl Iterator<Item = (Range<D>, &'a T)> + 'a
|
||||
where
|
||||
D: 'a + TextDimension<'a>,
|
||||
D: TextDimension,
|
||||
I: ToOffset,
|
||||
{
|
||||
let range = content.anchor_at(range.start.0, range.start.1)
|
||||
|
@ -250,7 +250,7 @@ impl<T> AnchorRangeMap<T> {
|
|||
mut extract_key: F,
|
||||
) -> Option<(Range<D>, &T)>
|
||||
where
|
||||
D: 'a + TextDimension<'a>,
|
||||
D: TextDimension,
|
||||
F: FnMut(&T) -> K,
|
||||
K: Ord,
|
||||
{
|
||||
|
@ -266,7 +266,7 @@ impl<T> AnchorRangeMap<T> {
|
|||
mut extract_key: F,
|
||||
) -> Option<(Range<D>, &T)>
|
||||
where
|
||||
D: 'a + TextDimension<'a>,
|
||||
D: TextDimension,
|
||||
F: FnMut(&T) -> K,
|
||||
K: Ord,
|
||||
{
|
||||
|
@ -282,7 +282,7 @@ impl<T> AnchorRangeMap<T> {
|
|||
content: &'a BufferSnapshot,
|
||||
) -> Range<D>
|
||||
where
|
||||
D: 'a + TextDimension<'a>,
|
||||
D: TextDimension,
|
||||
{
|
||||
let mut anchor = Anchor {
|
||||
full_offset: range.start,
|
||||
|
@ -342,7 +342,7 @@ impl AnchorRangeSet {
|
|||
content: &'a BufferSnapshot,
|
||||
) -> impl 'a + Iterator<Item = Range<Point>>
|
||||
where
|
||||
D: 'a + TextDimension<'a>,
|
||||
D: TextDimension,
|
||||
{
|
||||
self.0.ranges(content).map(|(range, _)| range)
|
||||
}
|
||||
|
|
|
@ -327,7 +327,7 @@ impl<'a> Cursor<'a> {
|
|||
slice
|
||||
}
|
||||
|
||||
pub fn summary<D: TextDimension<'a>>(&mut self, end_offset: usize) -> D {
|
||||
pub fn summary<D: TextDimension>(&mut self, end_offset: usize) -> D {
|
||||
debug_assert!(end_offset >= self.offset);
|
||||
|
||||
let mut summary = D::default();
|
||||
|
@ -719,12 +719,12 @@ impl std::ops::AddAssign<Self> for TextSummary {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait TextDimension<'a>: Dimension<'a, TextSummary> {
|
||||
pub trait TextDimension: 'static + for<'a> Dimension<'a, TextSummary> {
|
||||
fn from_text_summary(summary: &TextSummary) -> Self;
|
||||
fn add_assign(&mut self, other: &Self);
|
||||
}
|
||||
|
||||
impl<'a, D1: TextDimension<'a>, D2: TextDimension<'a>> TextDimension<'a> for (D1, D2) {
|
||||
impl<'a, D1: TextDimension, D2: TextDimension> TextDimension for (D1, D2) {
|
||||
fn from_text_summary(summary: &TextSummary) -> Self {
|
||||
(
|
||||
D1::from_text_summary(summary),
|
||||
|
@ -738,7 +738,7 @@ impl<'a, D1: TextDimension<'a>, D2: TextDimension<'a>> TextDimension<'a> for (D1
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> TextDimension<'a> for TextSummary {
|
||||
impl TextDimension for TextSummary {
|
||||
fn from_text_summary(summary: &TextSummary) -> Self {
|
||||
summary.clone()
|
||||
}
|
||||
|
@ -754,7 +754,7 @@ impl<'a> sum_tree::Dimension<'a, TextSummary> for usize {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> TextDimension<'a> for usize {
|
||||
impl TextDimension for usize {
|
||||
fn from_text_summary(summary: &TextSummary) -> Self {
|
||||
summary.bytes
|
||||
}
|
||||
|
@ -770,7 +770,7 @@ impl<'a> sum_tree::Dimension<'a, TextSummary> for Point {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> TextDimension<'a> for Point {
|
||||
impl TextDimension for Point {
|
||||
fn from_text_summary(summary: &TextSummary) -> Self {
|
||||
summary.lines
|
||||
}
|
||||
|
@ -786,7 +786,7 @@ impl<'a> sum_tree::Dimension<'a, TextSummary> for PointUtf16 {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> TextDimension<'a> for PointUtf16 {
|
||||
impl TextDimension for PointUtf16 {
|
||||
fn from_text_summary(summary: &TextSummary) -> Self {
|
||||
summary.lines_utf16
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
use sum_tree::Bias;
|
||||
|
||||
use crate::{rope::TextDimension, BufferSnapshot};
|
||||
|
||||
use super::{AnchorRangeMap, Buffer, Point, ToOffset, ToPoint};
|
||||
use crate::{
|
||||
rope::TextDimension, AnchorRangeMap, Buffer, BufferSnapshot, Point, ToOffset, ToPoint,
|
||||
};
|
||||
use std::{cmp::Ordering, ops::Range, sync::Arc};
|
||||
use sum_tree::Bias;
|
||||
|
||||
pub type SelectionSetId = clock::Lamport;
|
||||
pub type SelectionsVersion = usize;
|
||||
|
@ -108,7 +107,7 @@ impl SelectionSet {
|
|||
content: &'a BufferSnapshot,
|
||||
) -> impl 'a + Iterator<Item = Selection<D>>
|
||||
where
|
||||
D: 'a + TextDimension<'a>,
|
||||
D: TextDimension,
|
||||
{
|
||||
self.selections
|
||||
.ranges(content)
|
||||
|
@ -127,7 +126,7 @@ impl SelectionSet {
|
|||
content: &'a BufferSnapshot,
|
||||
) -> impl 'a + Iterator<Item = Selection<D>>
|
||||
where
|
||||
D: 'a + TextDimension<'a>,
|
||||
D: TextDimension,
|
||||
I: 'a + ToOffset,
|
||||
{
|
||||
self.selections
|
||||
|
@ -143,7 +142,7 @@ impl SelectionSet {
|
|||
|
||||
pub fn oldest_selection<'a, D>(&'a self, content: &'a BufferSnapshot) -> Option<Selection<D>>
|
||||
where
|
||||
D: 'a + TextDimension<'a>,
|
||||
D: TextDimension,
|
||||
{
|
||||
self.selections
|
||||
.min_by_key(content, |selection| selection.id)
|
||||
|
@ -158,7 +157,7 @@ impl SelectionSet {
|
|||
|
||||
pub fn newest_selection<'a, D>(&'a self, content: &'a BufferSnapshot) -> Option<Selection<D>>
|
||||
where
|
||||
D: 'a + TextDimension<'a>,
|
||||
D: TextDimension,
|
||||
{
|
||||
self.selections
|
||||
.max_by_key(content, |selection| selection.id)
|
||||
|
|
|
@ -295,7 +295,7 @@ impl UndoMap {
|
|||
}
|
||||
}
|
||||
|
||||
struct Edits<'a, D: TextDimension<'a>, F: FnMut(&FragmentSummary) -> bool> {
|
||||
struct Edits<'a, D: TextDimension, F: FnMut(&FragmentSummary) -> bool> {
|
||||
visible_cursor: rope::Cursor<'a>,
|
||||
deleted_cursor: rope::Cursor<'a>,
|
||||
fragments_cursor: Option<FilterCursor<'a, F, Fragment, FragmentTextSummary>>,
|
||||
|
@ -1447,7 +1447,7 @@ impl Buffer {
|
|||
#[cfg(test)]
|
||||
pub fn selection_ranges<'a, D>(&'a self, set_id: SelectionSetId) -> Result<Vec<Range<D>>>
|
||||
where
|
||||
D: 'a + TextDimension<'a>,
|
||||
D: TextDimension,
|
||||
{
|
||||
Ok(self
|
||||
.selection_set(set_id)?
|
||||
|
@ -1467,7 +1467,7 @@ impl Buffer {
|
|||
&'a self,
|
||||
) -> impl 'a + Iterator<Item = (SelectionSetId, Vec<Range<usize>>)>
|
||||
where
|
||||
D: 'a + TextDimension<'a>,
|
||||
D: TextDimension,
|
||||
{
|
||||
self.selections
|
||||
.keys()
|
||||
|
@ -1596,7 +1596,7 @@ impl BufferSnapshot {
|
|||
|
||||
fn summary_for_anchor<'a, D>(&'a self, anchor: &Anchor) -> D
|
||||
where
|
||||
D: TextDimension<'a>,
|
||||
D: TextDimension,
|
||||
{
|
||||
let cx = Some(anchor.version.clone());
|
||||
let mut cursor = self.fragments.cursor::<(VersionedFullOffset, usize)>();
|
||||
|
@ -1615,7 +1615,7 @@ impl BufferSnapshot {
|
|||
|
||||
pub fn text_summary_for_range<'a, D, O: ToOffset>(&'a self, range: Range<O>) -> D
|
||||
where
|
||||
D: TextDimension<'a>,
|
||||
D: TextDimension,
|
||||
{
|
||||
self.visible_text
|
||||
.cursor(range.start.to_offset(self))
|
||||
|
@ -1629,7 +1629,7 @@ impl BufferSnapshot {
|
|||
ranges: I,
|
||||
) -> impl 'a + Iterator<Item = D>
|
||||
where
|
||||
D: 'a + TextDimension<'a>,
|
||||
D: TextDimension,
|
||||
I: 'a + IntoIterator<Item = &'a FullOffset>,
|
||||
{
|
||||
let cx = Some(version.clone());
|
||||
|
@ -1656,7 +1656,7 @@ impl BufferSnapshot {
|
|||
ranges: I,
|
||||
) -> impl 'a + Iterator<Item = Range<D>>
|
||||
where
|
||||
D: 'a + TextDimension<'a>,
|
||||
D: TextDimension,
|
||||
I: 'a + IntoIterator<Item = &'a Range<FullOffset>>,
|
||||
{
|
||||
let cx = Some(version);
|
||||
|
@ -1855,7 +1855,7 @@ impl BufferSnapshot {
|
|||
since: &'a clock::Global,
|
||||
) -> impl 'a + Iterator<Item = Edit<D>>
|
||||
where
|
||||
D: 'a + TextDimension<'a> + Ord,
|
||||
D: TextDimension + Ord,
|
||||
{
|
||||
self.edits_since_in_range(since, Anchor::min()..Anchor::max())
|
||||
}
|
||||
|
@ -1866,7 +1866,7 @@ impl BufferSnapshot {
|
|||
range: Range<Anchor>,
|
||||
) -> impl 'a + Iterator<Item = Edit<D>>
|
||||
where
|
||||
D: 'a + TextDimension<'a> + Ord,
|
||||
D: TextDimension + Ord,
|
||||
{
|
||||
let fragments_cursor = if *since == self.version {
|
||||
None
|
||||
|
@ -1964,9 +1964,7 @@ impl<'a> RopeBuilder<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, D: TextDimension<'a> + Ord, F: FnMut(&FragmentSummary) -> bool> Iterator
|
||||
for Edits<'a, D, F>
|
||||
{
|
||||
impl<'a, D: TextDimension + Ord, F: FnMut(&FragmentSummary) -> bool> Iterator for Edits<'a, D, F> {
|
||||
type Item = Edit<D>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
|
|
Loading…
Reference in a new issue