summaryrefslogtreecommitdiff
path: root/yazi-enter.yazi
diff options
context:
space:
mode:
authorJackson Moore <jacksonmoore@tuta.io>2026-09-18 09:53:27 +0200
committerJackson Moore <jacksonmoore@tuta.io>2026-09-18 09:53:27 +0200
commite8797fd2a5c5bc30ff628e124e3a6ebfd982b59a (patch)
tree22256c23a0944670231f6a87a54e9e148ecfed04 /yazi-enter.yazi
parent1ede8bd35314d85021db0ca98f23dd4ea44eb9fa (diff)
Sort alpha transiently during selectionHEADmain
Diffstat (limited to 'yazi-enter.yazi')
-rw-r--r--yazi-enter.yazi/README.txt32
-rw-r--r--yazi-enter.yazi/main.lua89
2 files changed, 112 insertions, 9 deletions
diff --git a/yazi-enter.yazi/README.txt b/yazi-enter.yazi/README.txt
index 6454872..cb8d57e 100644
--- a/yazi-enter.yazi/README.txt
+++ b/yazi-enter.yazi/README.txt
@@ -1,8 +1,8 @@
YAZI-ENTER
Find an entry in the current Yazi view and activate the Hovered match.
-Matching, cursor movement, directory entry, and file opening use Yazi's
-built-in actions.
+Matching, sorting, cursor movement, directory entry, and file opening use Yazi's
+built-in manager actions.
REQUIREMENTS
@@ -10,8 +10,7 @@ REQUIREMENTS
- Yazi's bundled Lua runtime.
The runtime contract is verified against Yazi 26.9.1. Review compatibility
-before using a later Yazi release. Find behavior runs entirely through Yazi's
-native finder.
+before you use a later Yazi release.
INSTALLATION
@@ -47,7 +46,7 @@ keys and activates either entry type:
Use one TOML keymap form consistently. If the file already has an
[mgr] prepend_keymap array, add equivalent mapping objects to that array.
-Restart Yazi after changing the plugin or keymap files.
+Restart Yazi after you change the plugin or keymap files.
Choose any keys and any of these actions:
@@ -74,6 +73,27 @@ the action after submission. A type mismatch produces a zero-action result.
File opening targets only the Hovered match and uses the current Yazi opener
rules. Persistent selections stay separate from that target.
+TRANSIENT SORTING
+
+Each valid invocation saves the active tab's complete sort preference. It then
+applies forward alphabetical sorting before it opens the prompt. This is the
+same sort request as Yazi's default `,a` binding:
+
+ sort alphabetical --reverse=no
+
+The temporary request changes only the sort method and reverse flag. The
+current directory-first, case-sensitivity, transliteration, and fallback
+settings stay active during the prompt.
+
+The plugin restores all six saved sort fields when the session ends. Restore
+runs after directory entry, hovered-file opening, a zero-action result, Cancel,
+input closure, a failed final Find, or a caught runtime error. Directory entry
+and file opening are queued before restore.
+
+Overlapping yazi-enter prompts share one sort lease. The first prompt saves the
+original preference. Alphabetical order stays active until the final prompt
+closes. The final release restores the original preference once.
+
OPTIONS
- --previous searches in current-then-backward order and wraps.
@@ -94,7 +114,7 @@ input history.
Queries are unanchored Rust regular expressions. Plain text normally acts as a
substring query. Escape regular-expression characters when they must be
-literal. During typing, a malformed expression can be corrected in the same
+literal. During typing, you can correct a malformed expression in the same
prompt.
A successful query moves the cursor with Yazi's native find behavior. Submit
diff --git a/yazi-enter.yazi/main.lua b/yazi-enter.yazi/main.lua
index b31a7b0..c14d16b 100644
--- a/yazi-enter.yazi/main.lua
+++ b/yazi-enter.yazi/main.lua
@@ -9,6 +9,8 @@ local CASE_SENSITIVE = "sensitive"
local CASE_INSENSITIVE = "insensitive"
local CASE_SMART = "smart"
local FIND_ACTION = "find_do"
+local SORT_ACTION = "sort"
+local SORT_ALPHABETICAL = "alphabetical"
local ACTION_ENTER = "enter"
local ACTION_OPEN_HOVERED = "open-hovered"
local ACTION_NONE = "none"
@@ -131,6 +133,49 @@ local function decide_target(mode, is_dir)
return ACTION_NONE
end
+local function new_alphabetical_sort_request()
+ return {
+ by = SORT_ALPHABETICAL,
+ reverse = false,
+ }
+end
+
+local acquire_transient_sort = ya.sync(function(state)
+ local lease = state.transient_sort_lease
+ if lease ~= nil then
+ lease.count = lease.count + 1
+ return
+ end
+
+ local preference = cx.active.pref
+ state.transient_sort_lease = {
+ count = 1,
+ restore = {
+ by = tostring(preference.sort_by),
+ reverse = preference.sort_reverse,
+ dir_first = preference.sort_dir_first,
+ sensitive = preference.sort_sensitive,
+ translit = preference.sort_translit,
+ fallback = tostring(preference.sort_fallback),
+ },
+ }
+end)
+
+local release_transient_sort = ya.sync(function(state)
+ local lease = state.transient_sort_lease
+ if lease == nil or type(lease.count) ~= "number" or lease.count < 1 then
+ error("yazi-enter: transient sort lease is invalid", 0)
+ end
+
+ if lease.count > 1 then
+ lease.count = lease.count - 1
+ return
+ end
+
+ ya.emit(SORT_ACTION, lease.restore)
+ state.transient_sort_lease = nil
+end)
+
local commit = ya.sync(function(_, mode, submitted_query)
local tab = cx.active
local finder = tab.finder
@@ -177,6 +222,10 @@ local function apply_find(query, search_policy)
return UPDATE_FAILURE, reply_or_error
end
+local function apply_alphabetical_sort()
+ return ya.exec(SORT_ACTION, new_alphabetical_sort_request())
+end
+
local function new_prompt_specification(direction)
return {
name = COMMON_PROMPT_DATA.name,
@@ -248,7 +297,10 @@ local function new_application_boundaries(
prompt_capability,
find_update_capability,
commit_capability,
- target_dispatch_capability
+ target_dispatch_capability,
+ sort_acquire_capability,
+ alphabetical_sort_capability,
+ sort_release_capability
)
return {
prompt = function(prompt_data)
@@ -287,6 +339,15 @@ local function new_application_boundaries(
end
target_dispatch_capability(decision)
end,
+ sort_acquire = function()
+ return sort_acquire_capability()
+ end,
+ sort_alphabetically = function()
+ return alphabetical_sort_capability()
+ end,
+ sort_release = function()
+ return sort_release_capability()
+ end,
}
end
@@ -336,6 +397,25 @@ local function run_selection_session(intent, boundaries)
end
end
+local function run_transiently_sorted_session(intent, boundaries)
+ boundaries.sort_acquire()
+
+ local session_ok, result_or_error = pcall(function()
+ boundaries.sort_alphabetically()
+ return run_selection_session(intent, boundaries)
+ end)
+
+ local release_ok, release_error = pcall(boundaries.sort_release)
+ if not release_ok then
+ error(release_error, 0)
+ end
+ if not session_ok then
+ error(result_or_error, 0)
+ end
+
+ return result_or_error
+end
+
local function run_entry(job)
local intent = parse_invocation_intent(job.args)
local boundaries = new_application_boundaries(
@@ -344,9 +424,12 @@ local function run_entry(job)
commit,
function()
error("yazi-enter: target dispatch is owned by the commit transaction", 0)
- end
+ end,
+ acquire_transient_sort,
+ apply_alphabetical_sort,
+ release_transient_sort
)
- return run_selection_session(intent, boundaries)
+ return run_transiently_sorted_session(intent, boundaries)
end
return {