mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 14:51:03 +00:00
feat: new casefy command for case conversion (#3235)
Co-authored-by: sxyazi <sxyazi@gmail.com>
This commit is contained in:
parent
782ecb16b2
commit
4e32044450
8 changed files with 70 additions and 7 deletions
|
|
@ -1 +1 @@
|
|||
{"version":"0.2","flagWords":[],"language":"en","words":["Punct","KEYMAP","splitn","crossterm","YAZI","peekable","ratatui","syntect","pbpaste","pbcopy","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","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","Konsole","Überzug","pkgs","pdftoppm","poppler","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","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink","linemodes","SIGSTOP","sevenzip","rsplitn","replacen","DECSET","DECRQM","repeek","cwds","tcsi","Hyprland","Wayfire","SWAYSOCK","btime","nsec","codegen","gethostname","fchmod","fdfind","Rustc","rustc","ffprobe","vframes","luma","obase","outln","errln","tmtheme","twox","cfgs","fstype","objc","rdev","runloop","exfat","rclone","DECRQSS","DECSCUSR","libvterm","Uninit","lockin","rposition","resvg","foldhash","tilded","futs","chdir","hashbrown","JEMALLOC","RUSTFLAGS","RDONLY","GETPATH","fcntl","casefold","inodes","Splatable"]}
|
||||
{"language":"en","flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","peekable","ratatui","syntect","pbpaste","pbcopy","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","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","Konsole","Überzug","pkgs","pdftoppm","poppler","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","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink","linemodes","SIGSTOP","sevenzip","rsplitn","replacen","DECSET","DECRQM","repeek","cwds","tcsi","Hyprland","Wayfire","SWAYSOCK","btime","nsec","codegen","gethostname","fchmod","fdfind","Rustc","rustc","ffprobe","vframes","luma","obase","outln","errln","tmtheme","twox","cfgs","fstype","objc","rdev","runloop","exfat","rclone","DECRQSS","DECSCUSR","libvterm","Uninit","lockin","rposition","resvg","foldhash","tilded","futs","chdir","hashbrown","JEMALLOC","RUSTFLAGS","RDONLY","GETPATH","fcntl","casefold","inodes","Splatable","casefied"],"version":"0.2"}
|
||||
|
|
@ -301,9 +301,10 @@ keymap = [
|
|||
{ on = "p", run = "paste", desc = "Paste copied characters after the cursor" },
|
||||
{ on = "P", run = "paste --before", desc = "Paste copied characters before the cursor" },
|
||||
|
||||
# Undo/Redo
|
||||
{ on = "u", run = "undo", desc = "Undo the last operation" },
|
||||
{ on = "<C-r>", run = "redo", desc = "Redo the last operation" },
|
||||
# Undo/Redo/Casefy
|
||||
{ on = "u", run = [ "undo", "casefy lower" ], desc = "Undo, or lowercase if in visual mode" },
|
||||
{ on = "U", run = "casefy upper", desc = "Uppercase" },
|
||||
{ on = "<C-r>", run = "redo", desc = "Redo the last operation" },
|
||||
|
||||
# Help
|
||||
{ on = "~", run = "help", desc = "Open help" },
|
||||
|
|
|
|||
25
yazi-parser/src/input/casefy.rs
Normal file
25
yazi-parser/src/input/casefy.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value};
|
||||
use yazi_shared::event::CmdCow;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CasefyOpt {
|
||||
pub upper: bool,
|
||||
}
|
||||
|
||||
impl From<CmdCow> for CasefyOpt {
|
||||
fn from(c: CmdCow) -> Self { Self { upper: c.str(0) == "upper" } }
|
||||
}
|
||||
|
||||
impl FromLua for CasefyOpt {
|
||||
fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) }
|
||||
}
|
||||
|
||||
impl IntoLua for CasefyOpt {
|
||||
fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) }
|
||||
}
|
||||
|
||||
impl CasefyOpt {
|
||||
pub fn transform(&self, s: &str) -> String {
|
||||
if self.upper { s.to_ascii_uppercase() } else { s.to_ascii_lowercase() }
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +1 @@
|
|||
yazi_macro::mod_flat!(backspace backward close complete delete forward insert kill paste r#move show);
|
||||
yazi_macro::mod_flat!(backspace backward casefy close complete delete forward insert kill paste r#move show);
|
||||
|
|
|
|||
31
yazi-widgets/src/input/commands/casefy.rs
Normal file
31
yazi-widgets/src/input/commands/casefy.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
use std::ops::Range;
|
||||
|
||||
use anyhow::Result;
|
||||
use yazi_macro::{act, render, succ};
|
||||
use yazi_parser::input::CasefyOpt;
|
||||
use yazi_shared::data::Data;
|
||||
|
||||
use crate::input::{Input, op::InputOp};
|
||||
|
||||
impl Input {
|
||||
pub fn casefy(&mut self, opt: CasefyOpt) -> Result<Data> {
|
||||
let snap = self.snap_mut();
|
||||
if !matches!(snap.op, InputOp::Select(_)) {
|
||||
succ!();
|
||||
}
|
||||
|
||||
let range = snap.op.range(snap.cursor, true).unwrap();
|
||||
let Range { start, end } = snap.idx(range.start)..snap.idx(range.end);
|
||||
|
||||
let (start, end) = (start.unwrap(), end.unwrap());
|
||||
let casefied = opt.transform(&snap.value[start..end]);
|
||||
|
||||
snap.value.replace_range(start..end, &casefied);
|
||||
snap.op = InputOp::None;
|
||||
snap.cursor = range.start;
|
||||
self.snaps.tag(self.limit).then(|| self.flush_value());
|
||||
|
||||
act!(r#move, self)?;
|
||||
succ!(render!());
|
||||
}
|
||||
}
|
||||
|
|
@ -35,6 +35,8 @@ impl Input {
|
|||
|
||||
on!(undo);
|
||||
on!(redo);
|
||||
|
||||
on!(casefy);
|
||||
}
|
||||
InputMode::Insert => {
|
||||
on!(visual);
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
yazi_macro::mod_flat!(backspace backward commands complete delete escape forward insert kill paste r#move r#type redo replace undo visual yank);
|
||||
yazi_macro::mod_flat!(backspace backward casefy commands complete delete escape forward insert kill paste r#move r#type redo replace undo visual yank);
|
||||
|
|
|
|||
|
|
@ -3,10 +3,14 @@ use yazi_macro::{act, render, succ};
|
|||
use yazi_parser::VoidOpt;
|
||||
use yazi_shared::data::Data;
|
||||
|
||||
use crate::input::{Input, InputMode};
|
||||
use crate::input::{Input, InputMode, InputOp};
|
||||
|
||||
impl Input {
|
||||
pub fn undo(&mut self, _: VoidOpt) -> Result<Data> {
|
||||
if self.snap().op != InputOp::None {
|
||||
succ!();
|
||||
}
|
||||
|
||||
if !self.snaps.undo() {
|
||||
succ!();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue