diff --git a/data/lib/red/keys.lua b/data/lib/red/keys.lua index 9da1099..ad780f0 100644 --- a/data/lib/red/keys.lua +++ b/data/lib/red/keys.lua @@ -1,13 +1,14 @@ 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', @@ -15,6 +16,17 @@ return { 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() @@ -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', diff --git a/data/lib/red/win.lua b/data/lib/red/win.lua index 3b4b9b2..742366f 100644 --- a/data/lib/red/win.lua +++ b/data/lib/red/win.lua @@ -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 @@ -1149,6 +1155,7 @@ 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 @@ -1156,7 +1163,9 @@ function win:event(r, v, a, b) 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 @@ -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