Merge branch 'master' into copy-paste
This commit is contained in:
commit
40980edffe
10 changed files with 102 additions and 84 deletions
|
@ -1499,14 +1499,6 @@ impl<'a, T: Entity> ModelContext<'a, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn app(&self) -> &AppContext {
|
|
||||||
&self.app.ctx
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn app_mut(&mut self) -> &mut MutableAppContext {
|
|
||||||
self.app
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn background_executor(&self) -> &Arc<executor::Background> {
|
pub fn background_executor(&self) -> &Arc<executor::Background> {
|
||||||
&self.app.ctx.background
|
&self.app.ctx.background
|
||||||
}
|
}
|
||||||
|
@ -1644,6 +1636,18 @@ impl<'a, T: Entity> ModelContext<'a, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<M> AsRef<AppContext> for ModelContext<'_, M> {
|
||||||
|
fn as_ref(&self) -> &AppContext {
|
||||||
|
&self.app.ctx
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<M> AsMut<MutableAppContext> for ModelContext<'_, M> {
|
||||||
|
fn as_mut(&mut self) -> &mut MutableAppContext {
|
||||||
|
self.app
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<M> ReadModel for ModelContext<'_, M> {
|
impl<M> ReadModel for ModelContext<'_, M> {
|
||||||
fn read_model<T: Entity>(&self, handle: &ModelHandle<T>) -> &T {
|
fn read_model<T: Entity>(&self, handle: &ModelHandle<T>) -> &T {
|
||||||
self.app.read_model(handle)
|
self.app.read_model(handle)
|
||||||
|
@ -1689,14 +1693,6 @@ impl<'a, T: View> ViewContext<'a, T> {
|
||||||
self.window_id
|
self.window_id
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn app(&self) -> &AppContext {
|
|
||||||
&self.app.ctx
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn app_mut(&mut self) -> &mut MutableAppContext {
|
|
||||||
self.app
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn background_executor(&self) -> &Arc<executor::Background> {
|
pub fn background_executor(&self) -> &Arc<executor::Background> {
|
||||||
&self.app.ctx.background
|
&self.app.ctx.background
|
||||||
}
|
}
|
||||||
|
@ -1899,6 +1895,18 @@ impl<'a, T: View> ViewContext<'a, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<M> AsRef<AppContext> for ViewContext<'_, M> {
|
||||||
|
fn as_ref(&self) -> &AppContext {
|
||||||
|
&self.app.ctx
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<M> AsMut<MutableAppContext> for ViewContext<'_, M> {
|
||||||
|
fn as_mut(&mut self) -> &mut MutableAppContext {
|
||||||
|
self.app
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<V> ReadModel for ViewContext<'_, V> {
|
impl<V> ReadModel for ViewContext<'_, V> {
|
||||||
fn read_model<T: Entity>(&self, handle: &ModelHandle<T>) -> &T {
|
fn read_model<T: Entity>(&self, handle: &ModelHandle<T>) -> &T {
|
||||||
self.app.read_model(handle)
|
self.app.read_model(handle)
|
||||||
|
|
|
@ -447,7 +447,7 @@ impl Buffer {
|
||||||
if let Some(file) = &self.file {
|
if let Some(file) = &self.file {
|
||||||
let snapshot = self.snapshot();
|
let snapshot = self.snapshot();
|
||||||
let version = self.version.clone();
|
let version = self.version.clone();
|
||||||
let save_task = file.save(snapshot, ctx.app());
|
let save_task = file.save(snapshot, ctx.as_ref());
|
||||||
let task = ctx.spawn(save_task, |me, save_result, ctx| {
|
let task = ctx.spawn(save_task, |me, save_result, ctx| {
|
||||||
if save_result.is_ok() {
|
if save_result.is_ok() {
|
||||||
me.did_save(version, ctx);
|
me.did_save(version, ctx);
|
||||||
|
|
|
@ -311,7 +311,7 @@ impl BufferView {
|
||||||
|
|
||||||
let display_map = self.display_map.read(ctx);
|
let display_map = self.display_map.read(ctx);
|
||||||
let cursor = display_map
|
let cursor = display_map
|
||||||
.anchor_before(position, Bias::Left, ctx.app())
|
.anchor_before(position, Bias::Left, ctx.as_ref())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let selection = Selection {
|
let selection = Selection {
|
||||||
start: cursor.clone(),
|
start: cursor.clone(),
|
||||||
|
@ -336,7 +336,9 @@ impl BufferView {
|
||||||
) {
|
) {
|
||||||
let buffer = self.buffer.read(ctx);
|
let buffer = self.buffer.read(ctx);
|
||||||
let map = self.display_map.read(ctx);
|
let map = self.display_map.read(ctx);
|
||||||
let cursor = map.anchor_before(position, Bias::Left, ctx.app()).unwrap();
|
let cursor = map
|
||||||
|
.anchor_before(position, Bias::Left, ctx.as_ref())
|
||||||
|
.unwrap();
|
||||||
if let Some(selection) = self.pending_selection.as_mut() {
|
if let Some(selection) = self.pending_selection.as_mut() {
|
||||||
selection.set_head(buffer, cursor);
|
selection.set_head(buffer, cursor);
|
||||||
} else {
|
} else {
|
||||||
|
@ -351,8 +353,8 @@ impl BufferView {
|
||||||
|
|
||||||
fn end_selection(&mut self, ctx: &mut ViewContext<Self>) {
|
fn end_selection(&mut self, ctx: &mut ViewContext<Self>) {
|
||||||
if let Some(selection) = self.pending_selection.take() {
|
if let Some(selection) = self.pending_selection.take() {
|
||||||
let ix = self.selection_insertion_index(&selection.start, ctx.app());
|
let ix = self.selection_insertion_index(&selection.start, ctx.as_ref());
|
||||||
let mut selections = self.selections(ctx.app()).to_vec();
|
let mut selections = self.selections(ctx.as_ref()).to_vec();
|
||||||
selections.insert(ix, selection);
|
selections.insert(ix, selection);
|
||||||
self.update_selections(selections, ctx);
|
self.update_selections(selections, ctx);
|
||||||
} else {
|
} else {
|
||||||
|
@ -392,8 +394,8 @@ impl BufferView {
|
||||||
let mut selections = Vec::new();
|
let mut selections = Vec::new();
|
||||||
for range in ranges {
|
for range in ranges {
|
||||||
selections.push(Selection {
|
selections.push(Selection {
|
||||||
start: map.anchor_after(range.start, Bias::Left, ctx.app())?,
|
start: map.anchor_after(range.start, Bias::Left, ctx.as_ref())?,
|
||||||
end: map.anchor_before(range.end, Bias::Left, ctx.app())?,
|
end: map.anchor_before(range.end, Bias::Left, ctx.as_ref())?,
|
||||||
reversed: false,
|
reversed: false,
|
||||||
goal_column: None,
|
goal_column: None,
|
||||||
});
|
});
|
||||||
|
@ -406,7 +408,7 @@ impl BufferView {
|
||||||
let mut offset_ranges = SmallVec::<[Range<usize>; 32]>::new();
|
let mut offset_ranges = SmallVec::<[Range<usize>; 32]>::new();
|
||||||
{
|
{
|
||||||
let buffer = self.buffer.read(ctx);
|
let buffer = self.buffer.read(ctx);
|
||||||
for selection in self.selections(ctx.app()) {
|
for selection in self.selections(ctx.as_ref()) {
|
||||||
let start = selection.start.to_offset(buffer).unwrap();
|
let start = selection.start.to_offset(buffer).unwrap();
|
||||||
let end = selection.end.to_offset(buffer).unwrap();
|
let end = selection.end.to_offset(buffer).unwrap();
|
||||||
offset_ranges.push(start..end);
|
offset_ranges.push(start..end);
|
||||||
|
@ -456,18 +458,21 @@ impl BufferView {
|
||||||
|
|
||||||
pub fn backspace(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
|
pub fn backspace(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
|
||||||
self.start_transaction(ctx);
|
self.start_transaction(ctx);
|
||||||
let mut selections = self.selections(ctx.app()).to_vec();
|
let mut selections = self.selections(ctx.as_ref()).to_vec();
|
||||||
{
|
{
|
||||||
let buffer = self.buffer.read(ctx);
|
let buffer = self.buffer.read(ctx);
|
||||||
let map = self.display_map.read(ctx);
|
let map = self.display_map.read(ctx);
|
||||||
for selection in &mut selections {
|
for selection in &mut selections {
|
||||||
if selection.range(buffer).is_empty() {
|
if selection.range(buffer).is_empty() {
|
||||||
let head = selection.head().to_display_point(map, ctx.app()).unwrap();
|
let head = selection
|
||||||
|
.head()
|
||||||
|
.to_display_point(map, ctx.as_ref())
|
||||||
|
.unwrap();
|
||||||
let cursor = map
|
let cursor = map
|
||||||
.anchor_before(
|
.anchor_before(
|
||||||
movement::left(map, head, ctx.app()).unwrap(),
|
movement::left(map, head, ctx.as_ref()).unwrap(),
|
||||||
Bias::Left,
|
Bias::Left,
|
||||||
ctx.app(),
|
ctx.as_ref(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
selection.set_head(&buffer, cursor);
|
selection.set_head(&buffer, cursor);
|
||||||
|
@ -485,7 +490,7 @@ impl BufferView {
|
||||||
pub fn cut(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
|
pub fn cut(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
|
||||||
self.start_transaction(ctx);
|
self.start_transaction(ctx);
|
||||||
let mut text = String::new();
|
let mut text = String::new();
|
||||||
let mut selections = self.selections(ctx.app()).to_vec();
|
let mut selections = self.selections(ctx.as_ref()).to_vec();
|
||||||
let mut clipboard_selections = Vec::with_capacity(selections.len());
|
let mut clipboard_selections = Vec::with_capacity(selections.len());
|
||||||
{
|
{
|
||||||
let buffer = self.buffer.read(ctx);
|
let buffer = self.buffer.read(ctx);
|
||||||
|
@ -516,7 +521,7 @@ impl BufferView {
|
||||||
self.insert(&String::new(), ctx);
|
self.insert(&String::new(), ctx);
|
||||||
self.end_transaction(ctx);
|
self.end_transaction(ctx);
|
||||||
|
|
||||||
ctx.app_mut()
|
ctx.as_mut()
|
||||||
.write_to_clipboard(ClipboardItem::new(text).with_metadata(clipboard_selections));
|
.write_to_clipboard(ClipboardItem::new(text).with_metadata(clipboard_selections));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -524,7 +529,7 @@ impl BufferView {
|
||||||
let buffer = self.buffer.read(ctx);
|
let buffer = self.buffer.read(ctx);
|
||||||
let max_point = buffer.max_point();
|
let max_point = buffer.max_point();
|
||||||
let mut text = String::new();
|
let mut text = String::new();
|
||||||
let selections = self.selections(ctx.app());
|
let selections = self.selections(ctx.as_ref());
|
||||||
let mut clipboard_selections = Vec::with_capacity(selections.len());
|
let mut clipboard_selections = Vec::with_capacity(selections.len());
|
||||||
for selection in selections {
|
for selection in selections {
|
||||||
let mut start = selection.start.to_point(buffer).expect("invalid start");
|
let mut start = selection.start.to_point(buffer).expect("invalid start");
|
||||||
|
@ -545,15 +550,15 @@ impl BufferView {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.app_mut()
|
ctx.as_mut()
|
||||||
.write_to_clipboard(ClipboardItem::new(text).with_metadata(clipboard_selections));
|
.write_to_clipboard(ClipboardItem::new(text).with_metadata(clipboard_selections));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn paste(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
|
pub fn paste(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
|
||||||
if let Some(item) = ctx.app_mut().read_from_clipboard() {
|
if let Some(item) = ctx.as_mut().read_from_clipboard() {
|
||||||
let clipboard_text = item.text();
|
let clipboard_text = item.text();
|
||||||
if let Some(clipboard_selections) = item.metadata::<Vec<ClipboardSelection>>() {
|
if let Some(clipboard_selections) = item.metadata::<Vec<ClipboardSelection>>() {
|
||||||
let selections_len = self.selections(ctx.app()).len();
|
let selections_len = self.selections(ctx.as_ref()).len();
|
||||||
if clipboard_selections.len() == selections_len {
|
if clipboard_selections.len() == selections_len {
|
||||||
// If there are the same number of selections as there were at the time that
|
// If there are the same number of selections as there were at the time that
|
||||||
// this clipboard data was written, then paste one slice of the clipboard text
|
// this clipboard data was written, then paste one slice of the clipboard text
|
||||||
|
@ -585,7 +590,7 @@ impl BufferView {
|
||||||
ctx: &mut ViewContext<Self>,
|
ctx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
self.start_transaction(ctx);
|
self.start_transaction(ctx);
|
||||||
let selections = self.selections(ctx.app()).to_vec();
|
let selections = self.selections(ctx.as_ref()).to_vec();
|
||||||
let mut new_selections = Vec::with_capacity(selections.len());
|
let mut new_selections = Vec::with_capacity(selections.len());
|
||||||
let mut clipboard_offset = 0;
|
let mut clipboard_offset = 0;
|
||||||
for (selection, clipboard_selection) in selections.iter().zip(clipboard_selections) {
|
for (selection, clipboard_selection) in selections.iter().zip(clipboard_selections) {
|
||||||
|
@ -648,7 +653,7 @@ impl BufferView {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_left(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
|
pub fn move_left(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
|
||||||
let app = ctx.app();
|
let app = ctx.as_ref();
|
||||||
let mut selections = self.selections(app).to_vec();
|
let mut selections = self.selections(app).to_vec();
|
||||||
{
|
{
|
||||||
let map = self.display_map.read(app);
|
let map = self.display_map.read(app);
|
||||||
|
@ -674,17 +679,20 @@ impl BufferView {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_left(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
|
pub fn select_left(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
|
||||||
let mut selections = self.selections(ctx.app()).to_vec();
|
let mut selections = self.selections(ctx.as_ref()).to_vec();
|
||||||
{
|
{
|
||||||
let buffer = self.buffer.read(ctx);
|
let buffer = self.buffer.read(ctx);
|
||||||
let map = self.display_map.read(ctx);
|
let map = self.display_map.read(ctx);
|
||||||
for selection in &mut selections {
|
for selection in &mut selections {
|
||||||
let head = selection.head().to_display_point(map, ctx.app()).unwrap();
|
let head = selection
|
||||||
|
.head()
|
||||||
|
.to_display_point(map, ctx.as_ref())
|
||||||
|
.unwrap();
|
||||||
let cursor = map
|
let cursor = map
|
||||||
.anchor_before(
|
.anchor_before(
|
||||||
movement::left(map, head, ctx.app()).unwrap(),
|
movement::left(map, head, ctx.as_ref()).unwrap(),
|
||||||
Bias::Left,
|
Bias::Left,
|
||||||
ctx.app(),
|
ctx.as_ref(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
selection.set_head(&buffer, cursor);
|
selection.set_head(&buffer, cursor);
|
||||||
|
@ -696,9 +704,9 @@ impl BufferView {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_right(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
|
pub fn move_right(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
|
||||||
let mut selections = self.selections(ctx.app()).to_vec();
|
let mut selections = self.selections(ctx.as_ref()).to_vec();
|
||||||
{
|
{
|
||||||
let app = ctx.app();
|
let app = ctx.as_ref();
|
||||||
let map = self.display_map.read(app);
|
let map = self.display_map.read(app);
|
||||||
for selection in &mut selections {
|
for selection in &mut selections {
|
||||||
let start = selection.start.to_display_point(map, app).unwrap();
|
let start = selection.start.to_display_point(map, app).unwrap();
|
||||||
|
@ -722,13 +730,16 @@ impl BufferView {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_right(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
|
pub fn select_right(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
|
||||||
let mut selections = self.selections(ctx.app()).to_vec();
|
let mut selections = self.selections(ctx.as_ref()).to_vec();
|
||||||
{
|
{
|
||||||
let app = ctx.app();
|
let app = ctx.as_ref();
|
||||||
let buffer = self.buffer.read(app);
|
let buffer = self.buffer.read(app);
|
||||||
let map = self.display_map.read(app);
|
let map = self.display_map.read(app);
|
||||||
for selection in &mut selections {
|
for selection in &mut selections {
|
||||||
let head = selection.head().to_display_point(map, ctx.app()).unwrap();
|
let head = selection
|
||||||
|
.head()
|
||||||
|
.to_display_point(map, ctx.as_ref())
|
||||||
|
.unwrap();
|
||||||
let cursor = map
|
let cursor = map
|
||||||
.anchor_before(movement::right(map, head, app).unwrap(), Bias::Right, app)
|
.anchor_before(movement::right(map, head, app).unwrap(), Bias::Right, app)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -744,9 +755,9 @@ impl BufferView {
|
||||||
if self.single_line {
|
if self.single_line {
|
||||||
ctx.propagate_action();
|
ctx.propagate_action();
|
||||||
} else {
|
} else {
|
||||||
let mut selections = self.selections(ctx.app()).to_vec();
|
let mut selections = self.selections(ctx.as_ref()).to_vec();
|
||||||
{
|
{
|
||||||
let app = ctx.app();
|
let app = ctx.as_ref();
|
||||||
let map = self.display_map.read(app);
|
let map = self.display_map.read(app);
|
||||||
for selection in &mut selections {
|
for selection in &mut selections {
|
||||||
let start = selection.start.to_display_point(map, app).unwrap();
|
let start = selection.start.to_display_point(map, app).unwrap();
|
||||||
|
@ -773,9 +784,9 @@ impl BufferView {
|
||||||
if self.single_line {
|
if self.single_line {
|
||||||
ctx.propagate_action();
|
ctx.propagate_action();
|
||||||
} else {
|
} else {
|
||||||
let mut selections = self.selections(ctx.app()).to_vec();
|
let mut selections = self.selections(ctx.as_ref()).to_vec();
|
||||||
{
|
{
|
||||||
let app = ctx.app();
|
let app = ctx.as_ref();
|
||||||
let buffer = self.buffer.read(app);
|
let buffer = self.buffer.read(app);
|
||||||
let map = self.display_map.read(app);
|
let map = self.display_map.read(app);
|
||||||
for selection in &mut selections {
|
for selection in &mut selections {
|
||||||
|
@ -795,9 +806,9 @@ impl BufferView {
|
||||||
if self.single_line {
|
if self.single_line {
|
||||||
ctx.propagate_action();
|
ctx.propagate_action();
|
||||||
} else {
|
} else {
|
||||||
let mut selections = self.selections(ctx.app()).to_vec();
|
let mut selections = self.selections(ctx.as_ref()).to_vec();
|
||||||
{
|
{
|
||||||
let app = ctx.app();
|
let app = ctx.as_ref();
|
||||||
let map = self.display_map.read(app);
|
let map = self.display_map.read(app);
|
||||||
for selection in &mut selections {
|
for selection in &mut selections {
|
||||||
let start = selection.start.to_display_point(map, app).unwrap();
|
let start = selection.start.to_display_point(map, app).unwrap();
|
||||||
|
@ -824,9 +835,9 @@ impl BufferView {
|
||||||
if self.single_line {
|
if self.single_line {
|
||||||
ctx.propagate_action();
|
ctx.propagate_action();
|
||||||
} else {
|
} else {
|
||||||
let mut selections = self.selections(ctx.app()).to_vec();
|
let mut selections = self.selections(ctx.as_ref()).to_vec();
|
||||||
{
|
{
|
||||||
let app = ctx.app();
|
let app = ctx.as_ref();
|
||||||
let buffer = self.buffer.read(app);
|
let buffer = self.buffer.read(app);
|
||||||
let map = self.display_map.read(app);
|
let map = self.display_map.read(app);
|
||||||
for selection in &mut selections {
|
for selection in &mut selections {
|
||||||
|
@ -969,7 +980,7 @@ impl BufferView {
|
||||||
|
|
||||||
let mut fold_ranges = Vec::new();
|
let mut fold_ranges = Vec::new();
|
||||||
|
|
||||||
let app = ctx.app();
|
let app = ctx.as_ref();
|
||||||
let map = self.display_map.read(app);
|
let map = self.display_map.read(app);
|
||||||
for selection in self.selections(app) {
|
for selection in self.selections(app) {
|
||||||
let (start, end) = selection.display_range(map, app).sorted();
|
let (start, end) = selection.display_range(map, app).sorted();
|
||||||
|
@ -999,7 +1010,7 @@ impl BufferView {
|
||||||
pub fn unfold(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
|
pub fn unfold(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
|
||||||
use super::RangeExt;
|
use super::RangeExt;
|
||||||
|
|
||||||
let app = ctx.app();
|
let app = ctx.as_ref();
|
||||||
let map = self.display_map.read(app);
|
let map = self.display_map.read(app);
|
||||||
let buffer = self.buffer.read(app);
|
let buffer = self.buffer.read(app);
|
||||||
let ranges = self
|
let ranges = self
|
||||||
|
@ -1083,7 +1094,7 @@ impl BufferView {
|
||||||
self.display_map.update(ctx, |map, ctx| {
|
self.display_map.update(ctx, |map, ctx| {
|
||||||
let buffer = self.buffer.read(ctx);
|
let buffer = self.buffer.read(ctx);
|
||||||
let ranges = self
|
let ranges = self
|
||||||
.selections(ctx.app())
|
.selections(ctx.as_ref())
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| s.range(buffer))
|
.map(|s| s.range(buffer))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
@ -1601,7 +1612,7 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
view.fold(&(), ctx);
|
view.fold(&(), ctx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
view.text(ctx.app()),
|
view.text(ctx.as_ref()),
|
||||||
"
|
"
|
||||||
impl Foo {
|
impl Foo {
|
||||||
// Hello!
|
// Hello!
|
||||||
|
@ -1622,7 +1633,7 @@ mod tests {
|
||||||
|
|
||||||
view.fold(&(), ctx);
|
view.fold(&(), ctx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
view.text(ctx.app()),
|
view.text(ctx.as_ref()),
|
||||||
"
|
"
|
||||||
impl Foo {…
|
impl Foo {…
|
||||||
}
|
}
|
||||||
|
@ -1632,7 +1643,7 @@ mod tests {
|
||||||
|
|
||||||
view.unfold(&(), ctx);
|
view.unfold(&(), ctx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
view.text(ctx.app()),
|
view.text(ctx.as_ref()),
|
||||||
"
|
"
|
||||||
impl Foo {
|
impl Foo {
|
||||||
// Hello!
|
// Hello!
|
||||||
|
@ -1652,7 +1663,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
view.unfold(&(), ctx);
|
view.unfold(&(), ctx);
|
||||||
assert_eq!(view.text(ctx.app()), buffer.read(ctx).text());
|
assert_eq!(view.text(ctx.as_ref()), buffer.read(ctx).text());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1679,12 +1690,12 @@ mod tests {
|
||||||
view.update(app, |view, ctx| {
|
view.update(app, |view, ctx| {
|
||||||
view.move_down(&(), ctx);
|
view.move_down(&(), ctx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
view.selection_ranges(ctx.app()),
|
view.selection_ranges(ctx.as_ref()),
|
||||||
&[DisplayPoint::new(1, 0)..DisplayPoint::new(1, 0)]
|
&[DisplayPoint::new(1, 0)..DisplayPoint::new(1, 0)]
|
||||||
);
|
);
|
||||||
view.move_right(&(), ctx);
|
view.move_right(&(), ctx);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
view.selection_ranges(ctx.app()),
|
view.selection_ranges(ctx.as_ref()),
|
||||||
&[DisplayPoint::new(1, 4)..DisplayPoint::new(1, 4)]
|
&[DisplayPoint::new(1, 4)..DisplayPoint::new(1, 4)]
|
||||||
);
|
);
|
||||||
Ok::<(), Error>(())
|
Ok::<(), Error>(())
|
||||||
|
|
|
@ -29,7 +29,7 @@ impl DisplayMap {
|
||||||
|
|
||||||
DisplayMap {
|
DisplayMap {
|
||||||
buffer: buffer.clone(),
|
buffer: buffer.clone(),
|
||||||
fold_map: FoldMap::new(buffer, ctx.app()),
|
fold_map: FoldMap::new(buffer, ctx.as_ref()),
|
||||||
tab_size,
|
tab_size,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ impl DisplayMap {
|
||||||
ranges: impl IntoIterator<Item = Range<T>>,
|
ranges: impl IntoIterator<Item = Range<T>>,
|
||||||
ctx: &mut ModelContext<Self>,
|
ctx: &mut ModelContext<Self>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.fold_map.fold(ranges, ctx.app())?;
|
self.fold_map.fold(ranges, ctx.as_ref())?;
|
||||||
ctx.notify();
|
ctx.notify();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ impl DisplayMap {
|
||||||
ranges: impl IntoIterator<Item = Range<T>>,
|
ranges: impl IntoIterator<Item = Range<T>>,
|
||||||
ctx: &mut ModelContext<Self>,
|
ctx: &mut ModelContext<Self>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.fold_map.unfold(ranges, ctx.app())?;
|
self.fold_map.unfold(ranges, ctx.as_ref())?;
|
||||||
ctx.notify();
|
ctx.notify();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,7 @@ impl DisplayMap {
|
||||||
|
|
||||||
fn handle_buffer_event(&mut self, event: &buffer::Event, ctx: &mut ModelContext<Self>) {
|
fn handle_buffer_event(&mut self, event: &buffer::Event, ctx: &mut ModelContext<Self>) {
|
||||||
match event {
|
match event {
|
||||||
buffer::Event::Edited(edits) => self.fold_map.apply_edits(edits, ctx.app()).unwrap(),
|
buffer::Event::Edited(edits) => self.fold_map.apply_edits(edits, ctx.as_ref()).unwrap(),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,7 +287,7 @@ impl FileFinder {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn workspace_updated(&mut self, _: ModelHandle<Workspace>, ctx: &mut ViewContext<Self>) {
|
fn workspace_updated(&mut self, _: ModelHandle<Workspace>, ctx: &mut ViewContext<Self>) {
|
||||||
self.spawn_search(self.query_buffer.read(ctx).text(ctx.app()), ctx);
|
self.spawn_search(self.query_buffer.read(ctx).text(ctx.as_ref()), ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_query_buffer_event(
|
fn on_query_buffer_event(
|
||||||
|
@ -299,7 +299,7 @@ impl FileFinder {
|
||||||
use buffer_view::Event::*;
|
use buffer_view::Event::*;
|
||||||
match event {
|
match event {
|
||||||
Edited => {
|
Edited => {
|
||||||
let query = self.query_buffer.read(ctx).text(ctx.app());
|
let query = self.query_buffer.read(ctx).text(ctx.as_ref());
|
||||||
if query.is_empty() {
|
if query.is_empty() {
|
||||||
self.latest_search_id = util::post_inc(&mut self.search_count);
|
self.latest_search_id = util::post_inc(&mut self.search_count);
|
||||||
self.matches.clear();
|
self.matches.clear();
|
||||||
|
@ -345,7 +345,7 @@ impl FileFinder {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn_search(&mut self, query: String, ctx: &mut ViewContext<Self>) {
|
fn spawn_search(&mut self, query: String, ctx: &mut ViewContext<Self>) {
|
||||||
let worktrees = self.worktrees(ctx.app());
|
let worktrees = self.worktrees(ctx.as_ref());
|
||||||
let search_id = util::post_inc(&mut self.search_count);
|
let search_id = util::post_inc(&mut self.search_count);
|
||||||
let task = ctx.background_executor().spawn(async move {
|
let task = ctx.background_executor().spawn(async move {
|
||||||
let matches = match_paths(worktrees.as_slice(), &query, false, false, 100);
|
let matches = match_paths(worktrees.as_slice(), &query, false, false, 100);
|
||||||
|
|
|
@ -51,8 +51,8 @@ fn open_paths(params: &OpenParams, app: &mut MutableAppContext) {
|
||||||
for window_id in app.window_ids().collect::<Vec<_>>() {
|
for window_id in app.window_ids().collect::<Vec<_>>() {
|
||||||
if let Some(handle) = app.root_view::<WorkspaceView>(window_id) {
|
if let Some(handle) = app.root_view::<WorkspaceView>(window_id) {
|
||||||
if handle.update(app, |view, ctx| {
|
if handle.update(app, |view, ctx| {
|
||||||
if view.contains_paths(¶ms.paths, ctx.app()) {
|
if view.contains_paths(¶ms.paths, ctx.as_ref()) {
|
||||||
view.open_paths(¶ms.paths, ctx.app_mut());
|
view.open_paths(¶ms.paths, ctx.as_mut());
|
||||||
log::info!("open paths on existing workspace");
|
log::info!("open paths on existing workspace");
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -110,11 +110,10 @@ impl Pane {
|
||||||
entry_id: (usize, usize),
|
entry_id: (usize, usize),
|
||||||
ctx: &mut ViewContext<Self>,
|
ctx: &mut ViewContext<Self>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if let Some(index) = self
|
if let Some(index) = self.items.iter().position(|item| {
|
||||||
.items
|
item.entry_id(ctx.as_ref())
|
||||||
.iter()
|
.map_or(false, |id| id == entry_id)
|
||||||
.position(|item| item.entry_id(ctx.app()).map_or(false, |id| id == entry_id))
|
}) {
|
||||||
{
|
|
||||||
self.activate_item(index, ctx);
|
self.activate_item(index, ctx);
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -153,8 +153,8 @@ impl Workspace {
|
||||||
.ok_or(anyhow!("worktree {} does not exist", entry.0,))?;
|
.ok_or(anyhow!("worktree {} does not exist", entry.0,))?;
|
||||||
|
|
||||||
let replica_id = self.replica_id;
|
let replica_id = self.replica_id;
|
||||||
let file = worktree.file(entry.1, ctx.app())?;
|
let file = worktree.file(entry.1, ctx.as_ref())?;
|
||||||
let history = file.load_history(ctx.app());
|
let history = file.load_history(ctx.as_ref());
|
||||||
let buffer = async move { Ok(Buffer::from_history(replica_id, file, history.await?)) };
|
let buffer = async move { Ok(Buffer::from_history(replica_id, file, history.await?)) };
|
||||||
|
|
||||||
let (mut tx, rx) = watch::channel(None);
|
let (mut tx, rx) = watch::channel(None);
|
||||||
|
|
|
@ -214,7 +214,7 @@ impl WorkspaceView {
|
||||||
me.loading_entries.remove(&entry);
|
me.loading_entries.remove(&entry);
|
||||||
match item {
|
match item {
|
||||||
Ok(item) => {
|
Ok(item) => {
|
||||||
let item_view = item.add_view(ctx.window_id(), settings, ctx.app_mut());
|
let item_view = item.add_view(ctx.window_id(), settings, ctx.as_mut());
|
||||||
me.add_item(item_view, ctx);
|
me.add_item(item_view, ctx);
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
|
@ -243,7 +243,7 @@ impl WorkspaceView {
|
||||||
pub fn save_active_item(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
|
pub fn save_active_item(&mut self, _: &(), ctx: &mut ViewContext<Self>) {
|
||||||
self.active_pane.update(ctx, |pane, ctx| {
|
self.active_pane.update(ctx, |pane, ctx| {
|
||||||
if let Some(item) = pane.active_item() {
|
if let Some(item) = pane.active_item() {
|
||||||
let task = item.save(ctx.app_mut());
|
let task = item.save(ctx.as_mut());
|
||||||
ctx.spawn(task, |_, result, _| {
|
ctx.spawn(task, |_, result, _| {
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
// TODO - present this error to the user
|
// TODO - present this error to the user
|
||||||
|
@ -259,7 +259,7 @@ impl WorkspaceView {
|
||||||
match to_string_pretty(&ctx.debug_elements()) {
|
match to_string_pretty(&ctx.debug_elements()) {
|
||||||
Ok(json) => {
|
Ok(json) => {
|
||||||
let kib = json.len() as f32 / 1024.;
|
let kib = json.len() as f32 / 1024.;
|
||||||
ctx.app_mut().write_to_clipboard(ClipboardItem::new(json));
|
ctx.as_mut().write_to_clipboard(ClipboardItem::new(json));
|
||||||
log::info!(
|
log::info!(
|
||||||
"copied {:.1} KiB of element debug JSON to the clipboard",
|
"copied {:.1} KiB of element debug JSON to the clipboard",
|
||||||
kib
|
kib
|
||||||
|
@ -324,7 +324,7 @@ impl WorkspaceView {
|
||||||
let new_pane = self.add_pane(ctx);
|
let new_pane = self.add_pane(ctx);
|
||||||
self.activate_pane(new_pane.clone(), ctx);
|
self.activate_pane(new_pane.clone(), ctx);
|
||||||
if let Some(item) = pane.read(ctx).active_item() {
|
if let Some(item) = pane.read(ctx).active_item() {
|
||||||
if let Some(clone) = item.clone_on_split(ctx.app_mut()) {
|
if let Some(clone) = item.clone_on_split(ctx.as_mut()) {
|
||||||
self.add_item(clone, ctx);
|
self.add_item(clone, ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -352,7 +352,7 @@ impl WorkspaceView {
|
||||||
|
|
||||||
fn add_item(&self, item: Box<dyn ItemViewHandle>, ctx: &mut ViewContext<Self>) {
|
fn add_item(&self, item: Box<dyn ItemViewHandle>, ctx: &mut ViewContext<Self>) {
|
||||||
let active_pane = self.active_pane();
|
let active_pane = self.active_pane();
|
||||||
item.set_parent_pane(&active_pane, ctx.app_mut());
|
item.set_parent_pane(&active_pane, ctx.as_mut());
|
||||||
active_pane.update(ctx, |pane, ctx| {
|
active_pane.update(ctx, |pane, ctx| {
|
||||||
let item_idx = pane.add_item(item, ctx);
|
let item_idx = pane.add_item(item, ctx);
|
||||||
pane.activate_item(item_idx, ctx);
|
pane.activate_item(item_idx, ctx);
|
||||||
|
|
|
@ -710,7 +710,7 @@ mod test {
|
||||||
let file_id = entry.entry_id;
|
let file_id = entry.entry_id;
|
||||||
|
|
||||||
tree.update(&mut app, |tree, ctx| {
|
tree.update(&mut app, |tree, ctx| {
|
||||||
smol::block_on(tree.save(file_id, buffer.snapshot(), ctx.app())).unwrap()
|
smol::block_on(tree.save(file_id, buffer.snapshot(), ctx.as_ref())).unwrap()
|
||||||
});
|
});
|
||||||
|
|
||||||
let history = app
|
let history = app
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue