Add shortcuts for copying to clipboard
This commit is contained in:
parent
37edc728a9
commit
7169a89591
@ -64,7 +64,7 @@ Keyboard controls
|
||||
========================= ===========================
|
||||
Action Shortcut
|
||||
========================= ===========================
|
||||
Quit :kbd:`Q`, :kbd:`Ctrl+C`, :kbd:`Esc`
|
||||
Quit :kbd:`Q`, :kbd:`Esc`
|
||||
Scroll line up :kbd:`K`, :kbd:`Up`
|
||||
Scroll line down :kbd:`J`, :kbd:`Down`
|
||||
Scroll page up :kbd:`PgUp`
|
||||
@ -84,6 +84,8 @@ Search backwards :kbd:`?`
|
||||
Clear search :kbd:`Esc`
|
||||
Scroll to next match :kbd:`>`, :kbd:`.`
|
||||
Scroll to previous match :kbd:`<`, :kbd:`,`
|
||||
Copy selection to clipboard :kbd:`y`
|
||||
Copy selection or exit :kbd:`Ctrl+C`
|
||||
========================= ===========================
|
||||
|
||||
|
||||
|
||||
@ -266,6 +266,10 @@ map('Search forward (no regex)',
|
||||
map('Search backward (no regex)',
|
||||
'search_backward_simple b start_search substring backward',
|
||||
)
|
||||
|
||||
map('Copy selection to clipboard', 'copy_to_clipboard y copy_to_clipboard')
|
||||
map('Copy selection to clipboard or exit if no selection is present', 'copy_to_clipboard_or_exit ctrl+c copy_to_clipboard_or_exit')
|
||||
|
||||
egr() # }}}
|
||||
|
||||
OPTIONS = partial('''\
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"kitty"
|
||||
"kitty/tools/config"
|
||||
@ -19,6 +20,7 @@ var _ = fmt.Print
|
||||
|
||||
type KittyOpts struct {
|
||||
Wheel_scroll_multiplier int
|
||||
Copy_on_select bool
|
||||
}
|
||||
|
||||
func read_relevant_kitty_opts(path string) KittyOpts {
|
||||
@ -30,6 +32,8 @@ func read_relevant_kitty_opts(path string) KittyOpts {
|
||||
if err == nil {
|
||||
ans.Wheel_scroll_multiplier = v
|
||||
}
|
||||
case "copy_on_select":
|
||||
ans.Copy_on_select = strings.ToLower(val) == "clipboard"
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -188,9 +192,13 @@ func (self *Handler) finish_mouse_selection(ev *loop.MouseEvent) {
|
||||
self.mouse_selection.Finish()
|
||||
text := self.text_for_current_mouse_selection()
|
||||
if text != "" {
|
||||
if RelevantKittyOpts().Copy_on_select {
|
||||
self.lp.CopyTextToClipboard(text)
|
||||
} else {
|
||||
self.lp.CopyTextToPrimarySelection(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (self *Handler) add_mouse_selection_to_line(line_pos ScrollPos, y int) string {
|
||||
if self.mouse_selection.IsEmpty() {
|
||||
|
||||
@ -474,6 +474,7 @@ func (self *Handler) on_key_event(ev *loop.KeyEvent) error {
|
||||
}
|
||||
ac := self.shortcut_tracker.Match(ev, conf.KeyboardShortcuts)
|
||||
if ac != nil {
|
||||
ev.Handled = true
|
||||
return self.dispatch_action(ac.Name, ac.Args)
|
||||
}
|
||||
return nil
|
||||
@ -572,6 +573,20 @@ func (self *Handler) dispatch_action(name, args string) error {
|
||||
switch name {
|
||||
case `quit`:
|
||||
self.lp.Quit(0)
|
||||
case `copy_to_clipboard`:
|
||||
text := self.text_for_current_mouse_selection()
|
||||
if text == "" {
|
||||
self.lp.Beep()
|
||||
} else {
|
||||
self.lp.CopyTextToClipboard(text)
|
||||
}
|
||||
case `copy_to_clipboard_or_exit`:
|
||||
text := self.text_for_current_mouse_selection()
|
||||
if text == "" {
|
||||
self.lp.Quit(0)
|
||||
} else {
|
||||
self.lp.CopyTextToClipboard(text)
|
||||
}
|
||||
case `scroll_by`:
|
||||
if args == "" {
|
||||
args = "1"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user