docview: support gutter click selection, fixes #1116 (#1169)

* docview: support gutter click selection, fixes #1116

* Added missing call to parent on_mouse_pressed

Also fixed call to selections when `shift` is pressed.

* change to arrow instead of hand

Co-authored-by: Adam <adamdharrison@gmail.com>
This commit is contained in:
Jefferson González 2022-11-01 19:34:23 -04:00 committed by GitHub
parent ed226c476e
commit 69bccf6fcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 30 additions and 0 deletions

View File

@ -62,6 +62,7 @@ function DocView:new(doc)
self.font = "code_font"
self.last_x_offset = {}
self.ime_selection = { from = 0, size = 0 }
self.hovering_gutter = false
self.v_scrollbar:set_forced_status(config.force_scrollbar_status)
self.h_scrollbar:set_forced_status(config.force_scrollbar_status)
end
@ -247,8 +248,14 @@ end
function DocView:on_mouse_moved(x, y, ...)
DocView.super.on_mouse_moved(self, x, y, ...)
self.hovering_gutter = false
local gw = self:get_gutter_width()
if self:scrollbar_hovering() or self:scrollbar_dragging() then
self.cursor = "arrow"
elseif gw > 0 and x >= self.position.x and x <= (self.position.x + gw) then
self.cursor = "arrow"
self.hovering_gutter = true
else
self.cursor = "ibeam"
end
@ -290,6 +297,29 @@ function DocView:mouse_selection(doc, snap_type, line1, col1, line2, col2)
end
function DocView:on_mouse_pressed(button, x, y, clicks)
if button ~= "left" or not self.hovering_gutter then
return DocView.super.on_mouse_pressed(self, button, x, y, clicks)
end
local line = self:resolve_screen_position(x, y)
if keymap.modkeys["shift"] then
local sline, scol, sline2, scol2 = self.doc:get_selection(true)
if line > sline then
self.doc:set_selection(sline, 1, line, #self.doc.lines[line])
else
self.doc:set_selection(line, 1, sline2, #self.doc.lines[sline2])
end
else
if clicks == 1 then
self.doc:set_selection(line, 1, line, 1)
elseif clicks == 2 then
self.doc:set_selection(line, 1, line, #self.doc.lines[line])
end
end
return true
end
function DocView:on_mouse_released(...)
DocView.super.on_mouse_released(self, ...)
self.mouse_selecting = nil