matching brackets

This commit is contained in:
Dongdong Zhou 2020-11-12 22:15:36 +00:00
parent 2343a4ea5a
commit cab675b5fb
4 changed files with 23 additions and 15 deletions

View File

@ -995,15 +995,14 @@ fn matching_char(&self, c: char) -> Option<char> {
pub fn next_unmatched(&mut self, c: char) -> Option<usize> {
let other = self.matching_char(c)?;
let mut n = 0;
let mut candidate = self.inner.pos();
while let Some(current) = self.inner.next_codepoint() {
if current == c {
if n == 0 {
return Some(self.inner.pos());
}
if current == c && n == 0 {
return Some(self.inner.pos());
}
if current == other {
n += 1;
} else if current == c {
n -= 1;
}
}
None
@ -1020,6 +1019,8 @@ pub fn previous_unmatched(&mut self, c: char) -> Option<usize> {
}
if current == other {
n += 1;
} else if current == c {
n -= 1;
}
}
None

View File

@ -298,14 +298,17 @@ fn move_command(
LapceCommand::WordBackward => Some(Movement::WordBackward),
LapceCommand::WordFoward => Some(Movement::WordForward),
LapceCommand::WordEndForward => Some(Movement::WordEndForward),
LapceCommand::NextUnmatchedRightBracket =>
Some(Movement::NextUnmatched(')')),
LapceCommand::PreviousUnmatchedLeftBracket =>
Some(Movement::PreviousUnmatched('(')),
LapceCommand::NextUnmatchedRightCurlyBracket =>
Some(Movement::NextUnmatched('}')),
LapceCommand::PreviousUnmatchedLeftCurlyBracket =>
Some(Movement::PreviousUnmatched('{')),
LapceCommand::NextUnmatchedRightBracket => {
Some(Movement::NextUnmatched(')'))
}
LapceCommand::PreviousUnmatchedLeftBracket => {
Some(Movement::PreviousUnmatched('('))
}
LapceCommand::NextUnmatchedRightCurlyBracket => {
Some(Movement::NextUnmatched('}'))
}
LapceCommand::PreviousUnmatchedLeftCurlyBracket => {
Some(Movement::PreviousUnmatched('{'))
}
_ => None,
}

View File

@ -3,6 +3,7 @@
use std::{fs::File, sync::Arc};
use anyhow::{anyhow, Result};
use druid::KbKey;
use druid::{
Color, Data, Env, EventCtx, ExtEventSink, KeyEvent, Modifiers, Target, WidgetId,
WindowId,
@ -152,6 +153,9 @@ pub fn key_down(
key_event: &KeyEvent,
env: &Env,
) {
if key_event.key == KbKey::Shift {
return;
}
let mut mods = key_event.mods.clone();
mods.set(Modifiers::SHIFT, false);
let keypress = KeyPress {

View File

@ -478,8 +478,8 @@ pub fn update_region(
Movement::NextUnmatched(c) => {
let mut end = region.end;
for i in 0..count {
if let Some(new) = buffer.next_unmmatched(end, *c) {
end = new;
if let Some(new) = buffer.next_unmmatched(end + 1, *c) {
end = new - 1;
} else {
break;
}