Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
kokoISnoTarget committed Apr 11, 2024
1 parent a3524e9 commit 780a91d
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,28 +453,44 @@ impl TextBox {
match mode {
SelectionMode::Word => {
let text = line.text();

let mut start_index = None;
let mut end_index = None;

match cursor.affinity {
Affinity::Before => {
if cursor.index == 0 { return None; }
if text.get(cursor.index-1..cursor.index)?.contains(|c: char| c.is_whitespace()) {
if cursor.index == 0 {
return None;
}
if text
.get(cursor.index - 1..cursor.index)?
.contains(|c: char| c.is_whitespace())
{
cursor.index += 1;
} else if cursor.index == text.len() || text.get(cursor.index..cursor.index+1)?.contains(|c: char| c.is_whitespace()){
} else if cursor.index == text.len()
|| text
.get(cursor.index..cursor.index + 1)?
.contains(|c: char| c.is_whitespace())
{
end_index = Some(cursor.index);
}
}
Affinity::After => {
if text.get(cursor.index..cursor.index+1)?.contains(|c: char| c.is_whitespace()) {
if text
.get(cursor.index..cursor.index + 1)?
.contains(|c: char| c.is_whitespace())
{
cursor.index -= 1;
} else if cursor.index == 0 || text.get(cursor.index-1..cursor.index)?.contains(|c: char| c.is_whitespace()){
} else if cursor.index == 0
|| text
.get(cursor.index - 1..cursor.index)?
.contains(|c: char| c.is_whitespace())
{
start_index = Some(cursor.index)
}
}
}

if end_index.is_none() {
let end_text = text
.get(cursor.index..)
Expand All @@ -488,8 +504,10 @@ impl TextBox {
start_index = Some(cursor.index - start_text.len());
}

let start = Cursor::new(cursor.line, start_index.expect("Should have an value"));
let end = Cursor::new(cursor.line, end_index.expect("Should have an value"));
let start =
Cursor::new(cursor.line, start_index.expect("Should have an value"));
let end =
Cursor::new(cursor.line, end_index.expect("Should have an value"));

(start, end, position.1, position.1)
}
Expand Down

0 comments on commit 780a91d

Please sign in to comment.