Take a mutable context when resolving selections (#19948)

This is a behavior-preserving change, but lays the groundwork for
expanding selections when the cursor lands inside of a "replace" block.

Release Notes:

- N/A
This commit is contained in:
Antonio Scandurra 2024-10-30 15:21:51 +01:00 committed by GitHub
parent 83e2889d63
commit c8003c0697
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 288 additions and 257 deletions

View file

@ -5,7 +5,7 @@ use std::sync::Arc;
use anyhow::{Context, Result};
use editor::Editor;
use gpui::{prelude::*, AppContext, Entity, View, WeakView, WindowContext};
use gpui::{prelude::*, Entity, View, WeakView, WindowContext};
use language::{BufferSnapshot, Language, LanguageName, Point};
use crate::repl_store::ReplStore;
@ -103,7 +103,7 @@ pub enum SessionSupport {
Unsupported,
}
pub fn session(editor: WeakView<Editor>, cx: &mut AppContext) -> SessionSupport {
pub fn session(editor: WeakView<Editor>, cx: &mut WindowContext) -> SessionSupport {
let store = ReplStore::global(cx);
let entity_id = editor.entity_id();
@ -311,17 +311,21 @@ fn language_supported(language: &Arc<Language>) -> bool {
}
}
fn get_language(editor: WeakView<Editor>, cx: &mut AppContext) -> Option<Arc<Language>> {
let editor = editor.upgrade()?;
let selection = editor.read(cx).selections.newest::<usize>(cx);
let buffer = editor.read(cx).buffer().read(cx).snapshot(cx);
buffer.language_at(selection.head()).cloned()
fn get_language(editor: WeakView<Editor>, cx: &mut WindowContext) -> Option<Arc<Language>> {
editor
.update(cx, |editor, cx| {
let selection = editor.selections.newest::<usize>(cx);
let buffer = editor.buffer().read(cx).snapshot(cx);
buffer.language_at(selection.head()).cloned()
})
.ok()
.flatten()
}
#[cfg(test)]
mod tests {
use super::*;
use gpui::Context;
use gpui::{AppContext, Context};
use indoc::indoc;
use language::{Buffer, Language, LanguageConfig, LanguageRegistry};