A simple CPU rendered GUI IDE experience.
remove bracket pair
bendn 6 weeks ago
parent f24813c · commit 4b412b4
-rw-r--r--src/commands.rs1
-rw-r--r--src/edi.rs28
-rw-r--r--src/edi/st.rs1
-rw-r--r--src/lsp.rs34
-rw-r--r--src/menu/generic.rs3
-rw-r--r--src/text/cursor.rs3
6 files changed, 56 insertions, 14 deletions
diff --git a/src/commands.rs b/src/commands.rs
index 316462e..fdd4efa 100644
--- a/src/commands.rs
+++ b/src/commands.rs
@@ -1,4 +1,3 @@
-use std::borrow::Cow;
use std::iter::repeat;
use std::path::Path;
use std::process::Stdio;
diff --git a/src/edi.rs b/src/edi.rs
index 42803fb..5cb395f 100644
--- a/src/edi.rs
+++ b/src/edi.rs
@@ -950,6 +950,34 @@ impl Editor {
l.matching_brace(f, &mut self.text);
}
}
+ Some(Do::DeleteBracketPair) => {
+ if let Some((l, f)) = lsp!(self + p) {
+ if let Ok(x) = l.matching_brace_at(
+ f,
+ self.text.cursor.positions(&self.text.rope),
+ ) {
+ use itertools::Itertools;
+ for p in
+ // self.text.cursor.iter()
+ x
+ .iter()
+ .flatten()
+ .flat_map(|(a, b)| {
+ [a, b].map(|c| {
+ self.text
+ .rope
+ .l_position(*c)
+ .unwrap()
+ })
+ })
+ .sorted()
+ .rev()
+ {
+ self.text.remove(p..p + 1).unwrap();
+ }
+ }
+ }
+ }
Some(Do::Symbols) =>
if let Some(lsp) = lsp!(self) {
let mut q = Rq::new(
diff --git a/src/edi/st.rs b/src/edi/st.rs
index 11e3cca..c6fbdbb 100644
--- a/src/edi/st.rs
+++ b/src/edi/st.rs
@@ -52,6 +52,7 @@ Default => {
K(Key::Character(x) if x == "`" && ctrl()) => _ [SpawnTerminal],
K(Key::Character(y) if y == "/" && ctrl()) => Default [Comment(State => State::Default)],
K(Key::Character(x) if x == "p" && ctrl()) => Command(Commands => Commands::default()),
+ K(Key::Named(Backspace) if alt()) => _ [DeleteBracketPair],
K(Key::Named(F1)) => Procure((default(), InputRequest::RenameSymbol)),
K(Key::Named(k @ (ArrowUp | ArrowDown)) if alt()) => _ [InsertCursor(Direction => {
if k == ArrowUp {Direction::Above} else { Direction::Below }
diff --git a/src/lsp.rs b/src/lsp.rs
index 1c88d04..9351e87 100644
--- a/src/lsp.rs
+++ b/src/lsp.rs
@@ -479,22 +479,34 @@ impl Client {
.unwrap()
.0
}
+
+ pub fn matching_brace_at(
+ &self,
+ f: &Path,
+ x: Vec<Position>,
+ ) -> Result<
+ Vec<Option<(Position, Position)>>,
+ RequestError<MatchingBrace>,
+ > {
+ self.request_immediate::<MatchingBrace>(&MatchingBraceParams {
+ text_document: f.tid(),
+ positions: x,
+ })
+ }
+
pub fn matching_brace<'a>(
&'static self,
f: &Path,
t: &'a mut TextArea,
) {
- if let Ok([x]) = self.runtime.block_on(
- self.request::<MatchingBrace>(&MatchingBraceParams {
- text_document: f.tid(),
- positions: vec![
- t.to_l_position(*t.cursor.first()).unwrap(),
- ],
- })
- .unwrap()
- .0,
- ) {
- t.cursor.first_mut().position = t.l_position(x).unwrap();
+ if let Ok(x) =
+ self.matching_brace_at(f, t.cursor.positions(&t.rope))
+ {
+ for (c, p) in t.cursor.inner.iter_mut().zip(x) {
+ if let Some(p) = p {
+ c.position = t.rope.l_position(p.1).unwrap();
+ }
+ }
}
}
diff --git a/src/menu/generic.rs b/src/menu/generic.rs
index b9bf5bf..90daa33 100644
--- a/src/menu/generic.rs
+++ b/src/menu/generic.rs
@@ -1,4 +1,3 @@
-use std::borrow::Cow;
use std::fmt::Debug;
use std::path::Path;
@@ -57,7 +56,7 @@ pub trait MenuData: Sized {
type Element<'a>: Key<'a>;
type E = !;
- fn complete_or_accept<'a>(x: Self::Element<'a>) -> CorA {
+ fn complete_or_accept<'a>(_x: Self::Element<'a>) -> CorA {
CorA::Accept
}
fn map<'a>(
diff --git a/src/text/cursor.rs b/src/text/cursor.rs
index 37f6937..79514ff 100644
--- a/src/text/cursor.rs
+++ b/src/text/cursor.rs
@@ -396,6 +396,9 @@ impl Cursor {
}
}
impl Cursors {
+ pub fn positions(&self, r: &Rope) -> Vec<lsp_types::Position> {
+ self.iter().map(|x| r.to_l_position(*x).unwrap()).collect()
+ }
pub fn clear_selections(&mut self) {
self.each(|x| x.sel = None);
}