Skip to content

Commit

Permalink
red: better selection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hugeping committed Sep 4, 2024
1 parent 9cbd2dd commit e73aef5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
39 changes: 33 additions & 6 deletions data/lib/red/keys.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
local proc = require "red/proc"
return {
{ 'home',
{ 'shift+home',
function(self)
self:linestart()
self:movesel()
end
},
{ 'insert',
{ 'home',
function(self)
self.buf:insmode(not self.buf:insmode())
self:linestart()
end
},
{ 'end',
function(self)
self:lineend()
end
},
{ 'shift+end',
function(self)
self:lineend()
self:movesel()
end
},
{ 'insert',
function(self)
self.buf:insmode(not self.buf:insmode())
end
},
{ 'escape',
function(self)
self:escape()
Expand All @@ -32,22 +44,37 @@ return {
self.frame:menu():exec 'i-'
end
},
{ 'ctrl+escape',
function(self)
self:setsel(1, #self.buf.text+1)
end
},
{ 'ctrl+home',
function(self)
self:cur(1)
self:visible()
end
},
{ 'ctrl+escape',
{ 'ctrl+end',
function(self)
self:setsel(1, #self.buf.text+1)
self:cur(#self.buf.text)
self:lineend()
self:visible()
end
},
{ 'ctrl+end',
{ 'shift+ctrl+home',
function(self)
self:cur(1)
self:visible()
self:movesel()
end
},
{ 'shift+ctrl+end',
function(self)
self:cur(#self.buf.text)
self:lineend()
self:visible()
self:movesel()
end
},
{ 'ctrl+s',
Expand Down
13 changes: 12 additions & 1 deletion data/lib/red/win.lua
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,12 @@ function win:file(fname)
end

function win:curvisible()
local sel = self.buf:getsel()
if sel and sel.s then
return self.epos and ((sel.s >= self.pos and
sel.s <= self.epos) or
(sel.e-1 >= self.pos and sel.e-1 <= self.epos))
end
return self.epos and self.buf.cur >= self.pos and
self.buf.cur <= self.epos
end
Expand Down Expand Up @@ -1149,14 +1155,17 @@ function win:event(r, v, a, b)
self.buf.cur = self.pos
self:tox(self.autox)
self:movesel(true)
self:visible()
elseif v == 'pagedown' or v == 'keypad 3' then
if self:nextpage() then
self.buf.cur = self.pos
self:tox(self.autox)
else
self:cur(#self.buf.text+1)
end
self:movesel(true)
if self:movesel(true) then
self:visible()
end
elseif v == 'return' then
self:newline()
elseif v == 'backspace' then
Expand All @@ -1169,8 +1178,10 @@ function win:event(r, v, a, b)
end
elseif v == 'e' and input.keydown 'ctrl' then
self:lineend()
self:movesel()
elseif v == 'a' and input.keydown 'ctrl' then
self:linestart()
self:movesel()
elseif v == 'z' and input.keydown 'ctrl' then
self:undo()
elseif v == 'y' and input.keydown 'ctrl' then
Expand Down

0 comments on commit e73aef5

Please sign in to comment.