improve flip-bool
This commit is contained in:
parent
2da9d27e54
commit
07a58afaff
2 changed files with 13 additions and 16 deletions
|
@ -102,7 +102,7 @@
|
|||
d = "@<C-w>vgd";
|
||||
f = "@<C-w>vgy";
|
||||
h = ":toggle-option lsp.display-inlay-hints";
|
||||
t = "@|flip-bool<ret>";
|
||||
t = ":pipe flip-bool";
|
||||
};
|
||||
};
|
||||
insert = {
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#![feature(pattern)]
|
||||
|
||||
use std::{
|
||||
hint::black_box,
|
||||
io::{Read, Write},
|
||||
str::pattern::Pattern,
|
||||
};
|
||||
|
@ -86,29 +85,27 @@ fn find_bools(input: &str) -> [[Vec<usize>; 2]; BOOL_COUNT] {
|
|||
input
|
||||
.match_indices(it)
|
||||
.filter_map(|it| {
|
||||
let char_guard = |c: char| !(c.is_alphanumeric() || c.is_contained_in("-_"));
|
||||
let mut allow = true;
|
||||
fn char_guard(c: char) -> bool {
|
||||
!(c.is_alphanumeric() || c.is_contained_in("-_"))
|
||||
}
|
||||
|
||||
if it.0 > 0 {
|
||||
allow &= char_guard(
|
||||
let last_idx = it.0 + it.1.len();
|
||||
|
||||
(it.0 > 0
|
||||
&& last_idx < input.len()
|
||||
&& char_guard(
|
||||
input[it.1.floor_char_boundary(it.0 - 1)..it.0]
|
||||
.chars()
|
||||
.last()
|
||||
.unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
let last_idx = it.0 + it.1.len();
|
||||
if last_idx < input.len() {
|
||||
allow &= char_guard(
|
||||
)
|
||||
&& char_guard(
|
||||
input[(last_idx)..(input.ceil_char_boundary(last_idx + 1))]
|
||||
.chars()
|
||||
.last()
|
||||
.unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
allow.then_some(it.0)
|
||||
))
|
||||
.then_some(it.0)
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue