More work on mouse selections
This commit is contained in:
parent
a22933afbc
commit
d33b83e6ea
@ -506,10 +506,11 @@ var DocTitleMap = map[string]string{serialize_go_dict(ref_map['doc'])}
|
||||
var AllowedShellIntegrationValues = []string{{ {str(sorted(allowed_shell_integration_values))[1:-1].replace("'", '"')} }}
|
||||
var KittyConfigDefaults = struct {{
|
||||
Term, Shell_integration, Select_by_word_characters string
|
||||
Wheel_scroll_multiplier int
|
||||
Url_prefixes []string
|
||||
}}{{
|
||||
Term: "{Options.term}", Shell_integration: "{' '.join(Options.shell_integration)}", Url_prefixes: []string{{ {url_prefixes} }},
|
||||
Select_by_word_characters: `{Options.select_by_word_characters}`,
|
||||
Select_by_word_characters: `{Options.select_by_word_characters}`, Wheel_scroll_multiplier: {Options.wheel_scroll_multiplier},
|
||||
}}
|
||||
''' # }}}
|
||||
|
||||
|
||||
61
kittens/diff/mouse.go
Normal file
61
kittens/diff/mouse.go
Normal file
@ -0,0 +1,61 @@
|
||||
// License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
|
||||
|
||||
package diff
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"kitty"
|
||||
"kitty/tools/config"
|
||||
"kitty/tools/tui/loop"
|
||||
"kitty/tools/utils"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
type MouseSelection struct {
|
||||
start_line, end_line ScrollPos
|
||||
}
|
||||
|
||||
type KittyOpts struct {
|
||||
Wheel_scroll_multiplier int
|
||||
}
|
||||
|
||||
func read_relevant_kitty_opts(path string) KittyOpts {
|
||||
ans := KittyOpts{Wheel_scroll_multiplier: kitty.KittyConfigDefaults.Wheel_scroll_multiplier}
|
||||
handle_line := func(key, val string) error {
|
||||
switch key {
|
||||
case "wheel_scroll_multiplier":
|
||||
v, err := strconv.Atoi(val)
|
||||
if err == nil {
|
||||
ans.Wheel_scroll_multiplier = v
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
cp := config.ConfigParser{LineHandler: handle_line}
|
||||
cp.ParseFiles(path)
|
||||
return ans
|
||||
}
|
||||
|
||||
var RelevantKittyOpts = (&utils.Once[KittyOpts]{Run: func() KittyOpts {
|
||||
return read_relevant_kitty_opts(filepath.Join(utils.ConfigDir(), "kitty.conf"))
|
||||
}}).Get
|
||||
|
||||
func (self *Handler) handle_wheel_event(up bool) {
|
||||
amt := RelevantKittyOpts().Wheel_scroll_multiplier
|
||||
if up {
|
||||
amt *= -1
|
||||
}
|
||||
self.dispatch_action(`scroll_by`, strconv.Itoa(amt))
|
||||
}
|
||||
|
||||
func (self *Handler) start_mouse_selection(ev *loop.MouseEvent) {
|
||||
}
|
||||
|
||||
func (self *Handler) update_mouse_selection(ev *loop.MouseEvent) {
|
||||
}
|
||||
|
||||
func (self *Handler) finish_mouse_selection(ev *loop.MouseEvent) {
|
||||
}
|
||||
@ -54,6 +54,7 @@ var image_collection *graphics.ImageCollection
|
||||
type screen_size struct{ rows, columns, num_lines, cell_width, cell_height int }
|
||||
type Handler struct {
|
||||
async_results chan AsyncResult
|
||||
mouse_selection MouseSelection
|
||||
shortcut_tracker config.ShortcutTracker
|
||||
left, right string
|
||||
collection *Collection
|
||||
@ -628,20 +629,25 @@ func (self *Handler) dispatch_action(name, args string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *Handler) handle_wheel_event(up bool) {
|
||||
if self.logical_lines != nil {
|
||||
amt := 2
|
||||
if up {
|
||||
amt *= -1
|
||||
}
|
||||
self.dispatch_action(`scroll_by`, strconv.Itoa(amt))
|
||||
}
|
||||
}
|
||||
|
||||
func (self *Handler) on_mouse_event(ev *loop.MouseEvent) error {
|
||||
if self.logical_lines == nil {
|
||||
return nil
|
||||
}
|
||||
if ev.Event_type == loop.MOUSE_PRESS && ev.Buttons&(loop.MOUSE_WHEEL_UP|loop.MOUSE_WHEEL_DOWN) != 0 {
|
||||
self.handle_wheel_event(ev.Buttons&(loop.MOUSE_WHEEL_UP) != 0)
|
||||
return nil
|
||||
}
|
||||
if ev.Event_type == loop.MOUSE_PRESS && ev.Buttons&loop.LEFT_MOUSE_BUTTON != 0 {
|
||||
self.start_mouse_selection(ev)
|
||||
return nil
|
||||
}
|
||||
if ev.Event_type == loop.MOUSE_MOVE {
|
||||
self.update_mouse_selection(ev)
|
||||
return nil
|
||||
}
|
||||
if ev.Event_type == loop.MOUSE_RELEASE && ev.Buttons&loop.LEFT_MOUSE_BUTTON != 0 {
|
||||
self.finish_mouse_selection(ev)
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user