mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
Mark selected files
This commit is contained in:
@@ -166,6 +166,7 @@ func (s State) WindowTitle() string {
|
|||||||
}
|
}
|
||||||
return s.window_title
|
return s.window_title
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) AddSelection(abspath string) bool {
|
func (s *State) AddSelection(abspath string) bool {
|
||||||
if !slices.Contains(s.selections, abspath) {
|
if !slices.Contains(s.selections, abspath) {
|
||||||
s.selections = append(s.selections, abspath)
|
s.selections = append(s.selections, abspath)
|
||||||
@@ -182,6 +183,14 @@ func (s *State) ToggleSelection(abspath string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *State) IsSelected(x *ResultItem) bool {
|
||||||
|
if len(s.selections) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
q := filepath.Join(s.CurrentDir(), x.text)
|
||||||
|
return slices.Contains(s.selections, q)
|
||||||
|
}
|
||||||
|
|
||||||
type ScreenSize struct {
|
type ScreenSize struct {
|
||||||
width, height, cell_width, cell_height, width_px, height_px int
|
width, height, cell_width, cell_height, width_px, height_px int
|
||||||
}
|
}
|
||||||
@@ -270,14 +279,6 @@ func (h *Handler) current_abspath() string {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) add_selection_if_possible() bool {
|
|
||||||
m := h.current_abspath()
|
|
||||||
if m != "" {
|
|
||||||
return h.state.AddSelection(m)
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Handler) toggle_selection() bool {
|
func (h *Handler) toggle_selection() bool {
|
||||||
m := h.current_abspath()
|
m := h.current_abspath()
|
||||||
if m != "" {
|
if m != "" {
|
||||||
@@ -380,8 +381,11 @@ func (h *Handler) dispatch_action(name, args string) (err error) {
|
|||||||
}
|
}
|
||||||
case "accept":
|
case "accept":
|
||||||
m := h.current_abspath()
|
m := h.current_abspath()
|
||||||
|
if m == "" {
|
||||||
|
h.lp.Beep()
|
||||||
|
return
|
||||||
|
}
|
||||||
if h.state.mode.SelectFiles() {
|
if h.state.mode.SelectFiles() {
|
||||||
if m != "" {
|
|
||||||
var s os.FileInfo
|
var s os.FileInfo
|
||||||
if s, err = os.Stat(m); err != nil {
|
if s, err = os.Stat(m); err != nil {
|
||||||
h.lp.Beep()
|
h.lp.Beep()
|
||||||
@@ -391,21 +395,11 @@ func (h *Handler) dispatch_action(name, args string) (err error) {
|
|||||||
return h.change_to_current_dir_if_possible()
|
return h.change_to_current_dir_if_possible()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
h.state.AddSelection(m)
|
||||||
if h.add_selection_if_possible() {
|
|
||||||
if len(h.state.selections) > 0 {
|
if len(h.state.selections) > 0 {
|
||||||
return h.finish_selection()
|
return h.finish_selection()
|
||||||
}
|
}
|
||||||
return h.draw_screen()
|
return h.draw_screen()
|
||||||
} else {
|
|
||||||
if h.state.mode.CanSelectNonExistent() {
|
|
||||||
t := h.state.SearchText()
|
|
||||||
h.initialize_save_file_name(utils.IfElse(t == "", h.state.suggested_save_file_name, t))
|
|
||||||
return h.draw_screen()
|
|
||||||
} else {
|
|
||||||
h.lp.Beep()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "cd":
|
case "cd":
|
||||||
switch args {
|
switch args {
|
||||||
case "current":
|
case "current":
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ func (h *Handler) draw_no_matches_message(in_progress bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const matching_position_style = "fg=green"
|
const matching_position_style = "fg=green"
|
||||||
|
const selected_style = "fg=magenta"
|
||||||
const current_style = "fg=intense-white bold"
|
const current_style = "fg=intense-white bold"
|
||||||
|
|
||||||
func (h *Handler) render_match_with_positions(text string, add_ellipsis bool, positions []int, is_current bool) {
|
func (h *Handler) render_match_with_positions(text string, add_ellipsis bool, positions []int, is_current bool) {
|
||||||
@@ -127,7 +128,13 @@ func (h *Handler) draw_column_of_matches(matches ResultsType, current_idx int, x
|
|||||||
for i, m := range matches {
|
for i, m := range matches {
|
||||||
h.lp.QueueWriteString("\r")
|
h.lp.QueueWriteString("\r")
|
||||||
h.lp.MoveCursorHorizontally(x)
|
h.lp.MoveCursorHorizontally(x)
|
||||||
icon := icon_for(filepath.Join(root_dir, m.text), m.ftype)
|
is_selected := h.state.IsSelected(m)
|
||||||
|
var icon string
|
||||||
|
if is_selected {
|
||||||
|
icon = " "
|
||||||
|
} else {
|
||||||
|
icon = icon_for(filepath.Join(root_dir, m.text), m.ftype)
|
||||||
|
}
|
||||||
text := m.text
|
text := m.text
|
||||||
add_ellipsis := false
|
add_ellipsis := false
|
||||||
if wcswidth.Stringwidth(text) > available_width-3 {
|
if wcswidth.Stringwidth(text) > available_width-3 {
|
||||||
@@ -137,9 +144,13 @@ func (h *Handler) draw_column_of_matches(matches ResultsType, current_idx int, x
|
|||||||
is_current := i == current_idx
|
is_current := i == current_idx
|
||||||
if is_current {
|
if is_current {
|
||||||
h.lp.QueueWriteString(h.lp.SprintStyled(matching_position_style, icon+" "))
|
h.lp.QueueWriteString(h.lp.SprintStyled(matching_position_style, icon+" "))
|
||||||
|
} else {
|
||||||
|
if is_selected {
|
||||||
|
h.lp.QueueWriteString(h.lp.SprintStyled(selected_style, icon+" "))
|
||||||
} else {
|
} else {
|
||||||
h.lp.QueueWriteString(icon + " ")
|
h.lp.QueueWriteString(icon + " ")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
h.render_match_with_positions(text, add_ellipsis, m.sorted_positions(), is_current)
|
h.render_match_with_positions(text, add_ellipsis, m.sorted_positions(), is_current)
|
||||||
h.lp.MoveCursorVertically(1)
|
h.lp.MoveCursorVertically(1)
|
||||||
}
|
}
|
||||||
@@ -255,22 +266,3 @@ func (h *Handler) move_sideways(leftwards bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) handle_result_list_keys(ev *loop.KeyEvent) bool {
|
|
||||||
switch {
|
|
||||||
case ev.MatchesPressOrRepeat("down"):
|
|
||||||
h.next_result(1)
|
|
||||||
return true
|
|
||||||
case ev.MatchesPressOrRepeat("up"):
|
|
||||||
h.next_result(-1)
|
|
||||||
return true
|
|
||||||
case ev.MatchesPressOrRepeat("left") || ev.MatchesPressOrRepeat("pgup"):
|
|
||||||
h.move_sideways(true)
|
|
||||||
return true
|
|
||||||
case ev.MatchesPressOrRepeat("right") || ev.MatchesPressOrRepeat("pgdn"):
|
|
||||||
h.move_sideways(false)
|
|
||||||
return true
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user