From 847c475d8c396678dd726bff7677703be4212b21 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sun, 5 Nov 2023 00:37:43 +0800 Subject: [PATCH] fix: completion won't closing when there are no candidates --- cspell.json | 2 +- yazi-core/src/completion/commands/show.rs | 15 ++++++++------- yazi-core/src/tab/commands/hidden.rs | 2 +- yazi-core/src/tab/commands/linemode.rs | 2 +- yazi-core/src/tab/commands/sort.rs | 2 +- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/cspell.json b/cspell.json index b2751baa..5bfa99dd 100644 --- a/cspell.json +++ b/cspell.json @@ -1 +1 @@ -{"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit"],"flagWords":[],"version":"0.2","language":"en"} +{"flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","USERPROFILE"],"version":"0.2","language":"en"} diff --git a/yazi-core/src/completion/commands/show.rs b/yazi-core/src/completion/commands/show.rs index 7040200a..204e5ab9 100644 --- a/yazi-core/src/completion/commands/show.rs +++ b/yazi-core/src/completion/commands/show.rs @@ -1,4 +1,4 @@ -use std::ops::ControlFlow; +use std::{mem, ops::ControlFlow}; use yazi_config::keymap::Exec; @@ -46,17 +46,18 @@ impl Completion { ControlFlow::Continue(v) }); + self.ticket = opt.ticket; self.cands = match flow { ControlFlow::Continue(v) => v, ControlFlow::Break(v) => v, }; - self.ticket = opt.ticket; - - if !self.cands.is_empty() { - self.offset = 0; - self.cursor = 0; - self.visible = true; + if self.cands.is_empty() { + return mem::replace(&mut self.visible, false); } + + self.offset = 0; + self.cursor = 0; + self.visible = true; true } } diff --git a/yazi-core/src/tab/commands/hidden.rs b/yazi-core/src/tab/commands/hidden.rs index 8770f98b..2d192b59 100644 --- a/yazi-core/src/tab/commands/hidden.rs +++ b/yazi-core/src/tab/commands/hidden.rs @@ -4,7 +4,7 @@ use crate::{emit, tab::Tab}; impl Tab { pub fn hidden(&mut self, e: &Exec) -> bool { - self.conf.show_hidden = match e.args.get(0).map(|s| s.as_bytes()) { + self.conf.show_hidden = match e.args.first().map(|s| s.as_bytes()) { Some(b"show") => true, Some(b"hide") => false, _ => !self.conf.show_hidden, diff --git a/yazi-core/src/tab/commands/linemode.rs b/yazi-core/src/tab/commands/linemode.rs index f54f737f..36feab95 100644 --- a/yazi-core/src/tab/commands/linemode.rs +++ b/yazi-core/src/tab/commands/linemode.rs @@ -5,7 +5,7 @@ use crate::tab::Tab; impl Tab { pub fn linemode(&mut self, e: &Exec) -> bool { self.conf.patch(|c| { - let Some(mode) = e.args.get(0) else { + let Some(mode) = e.args.first() else { return; }; if !mode.is_empty() && mode.len() <= 20 { diff --git a/yazi-core/src/tab/commands/sort.rs b/yazi-core/src/tab/commands/sort.rs index ea430bdb..73793607 100644 --- a/yazi-core/src/tab/commands/sort.rs +++ b/yazi-core/src/tab/commands/sort.rs @@ -6,7 +6,7 @@ use crate::tab::Tab; impl Tab { pub fn sort(&mut self, e: &Exec) -> bool { - if let Some(by) = e.args.get(0) { + if let Some(by) = e.args.first() { self.conf.sort_by = SortBy::from_str(by).unwrap_or_default(); } self.conf.sort_sensitive = e.named.contains_key("sensitive");