Merge pull request #443 from kinode-dao/dr/delete-key-delete

fix: delete key should delete
This commit is contained in:
doria 2024-07-15 20:37:02 +09:00 committed by GitHub
commit ce00af0f61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 4 deletions

View File

@ -149,8 +149,13 @@ fn fetch_most_recent_blog_posts(n: usize) -> Vec<KinodeBlogPost> {
60, 60,
vec![], vec![],
) { ) {
Ok(response) => serde_json::from_slice::<Vec<KinodeBlogPost>>(response.body()) Ok(response) => match serde_json::from_slice::<Vec<KinodeBlogPost>>(response.body()) {
.expect("Invalid UTF-8 from kinode.org"), Ok(posts) => posts,
Err(e) => {
println!("Failed to parse blog posts: {e:?}");
vec![]
}
},
Err(e) => { Err(e) => {
println!("Failed to fetch blog posts: {e:?}"); println!("Failed to fetch blog posts: {e:?}");
vec![] vec![]

View File

@ -444,9 +444,9 @@ pub async fn terminal(
)?; )?;
}, },
// //
// BACKSPACE or DELETE: delete a single character at cursor // BACKSPACE: delete a single character at cursor
// //
KeyCode::Backspace | KeyCode::Delete => { KeyCode::Backspace => {
if line_col == prompt_len { if line_col == prompt_len {
continue; continue;
} }
@ -477,6 +477,35 @@ pub async fn terminal(
)?; )?;
}, },
// //
// DELETE: delete a single character at right of cursor
//
KeyCode::Delete => {
if line_col == current_line.len() {
continue;
}
current_line.remove(line_col);
if search_mode {
utils::execute_search(
&our,
&mut stdout,
&current_line,
prompt_len,
(win_cols, win_rows),
(line_col, cursor_col),
&mut command_history,
search_depth,
)?;
continue;
}
execute!(
stdout,
cursor::MoveTo(0, win_rows),
terminal::Clear(ClearType::CurrentLine),
Print(utils::truncate_in_place(&current_line, prompt_len, win_cols, (line_col, cursor_col))),
cursor::MoveTo(cursor_col, win_rows),
)?;
}
//
// LEFT: move cursor one spot left // LEFT: move cursor one spot left
// //
KeyCode::Left => { KeyCode::Left => {