985
985
internal .colorscheme = function (opts )
986
986
local before_background = vim .o .background
987
987
local before_color = vim .api .nvim_exec2 (" colorscheme" , { output = true }).output
988
- local need_restore = true
988
+ local need_restore = not not opts . enable_preview
989
989
990
990
local colors = opts .colors or { before_color }
991
991
if not vim .tbl_contains (colors , before_color ) then
@@ -1049,30 +1049,10 @@ internal.colorscheme = function(opts)
1049
1049
return
1050
1050
end
1051
1051
1052
- actions .close (prompt_bufnr )
1053
1052
need_restore = false
1053
+ actions .close (prompt_bufnr )
1054
1054
vim .cmd .colorscheme (selection .value )
1055
1055
end )
1056
- action_set .shift_selection :enhance {
1057
- post = function ()
1058
- local selection = action_state .get_selected_entry ()
1059
- if selection == nil then
1060
- utils .__warn_no_selection " builtin.colorscheme"
1061
- return
1062
- end
1063
- need_restore = true
1064
- if opts .enable_preview then
1065
- vim .cmd .colorscheme (selection .value )
1066
- end
1067
- end ,
1068
- }
1069
- actions .close :enhance {
1070
- post = function ()
1071
- if need_restore then
1072
- vim .cmd .colorscheme (before_color )
1073
- end
1074
- end ,
1075
- }
1076
1056
return true
1077
1057
end ,
1078
1058
on_complete = {
@@ -1082,8 +1062,9 @@ internal.colorscheme = function(opts)
1082
1062
utils .__warn_no_selection " builtin.colorscheme"
1083
1063
return
1084
1064
end
1085
- need_restore = true
1086
- vim .cmd .colorscheme (selection .value )
1065
+ if opts .enable_preview then
1066
+ vim .cmd .colorscheme (selection .value )
1067
+ end
1087
1068
end ,
1088
1069
},
1089
1070
})
@@ -1098,6 +1079,21 @@ internal.colorscheme = function(opts)
1098
1079
vim .cmd .colorscheme (before_color )
1099
1080
end
1100
1081
end
1082
+
1083
+ -- rewrite picker.set_selection so that color schemes can be previewed when the current
1084
+ -- selection is shifted using the keyboard or if an item is clicked with the mouse
1085
+ local set_selection = picker .set_selection
1086
+ picker .set_selection = function (self , row )
1087
+ set_selection (self , row )
1088
+ local selection = action_state .get_selected_entry ()
1089
+ if selection == nil then
1090
+ utils .__warn_no_selection " builtin.colorscheme"
1091
+ return
1092
+ end
1093
+ if opts .enable_preview then
1094
+ vim .cmd .colorscheme (selection .value )
1095
+ end
1096
+ end
1101
1097
end
1102
1098
1103
1099
picker :find ()
0 commit comments