mirror of
https://github.com/felixangell/phi.git
synced 2024-09-11 15:55:25 +03:00
caps lock and some super combos handled
This commit is contained in:
parent
ae7ed6d973
commit
8832ff8a8f
@ -107,6 +107,12 @@ var shiftAlternative = map[rune]rune{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Buffer) processTextInput(r rune) bool {
|
func (b *Buffer) processTextInput(r rune) bool {
|
||||||
|
if CAPS_LOCK {
|
||||||
|
if unicode.IsLetter(r) {
|
||||||
|
r = unicode.ToUpper(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if SHIFT_DOWN {
|
if SHIFT_DOWN {
|
||||||
// if it's a letter convert to uppercase
|
// if it's a letter convert to uppercase
|
||||||
if unicode.IsLetter(r) {
|
if unicode.IsLetter(r) {
|
||||||
@ -202,7 +208,16 @@ func (b *Buffer) deleteLine() {
|
|||||||
// was a key that MODIFIED the buffer.
|
// was a key that MODIFIED the buffer.
|
||||||
func (b *Buffer) processActionKey(key int) bool {
|
func (b *Buffer) processActionKey(key int) bool {
|
||||||
switch key {
|
switch key {
|
||||||
|
case sdl.K_CAPSLOCK:
|
||||||
|
CAPS_LOCK = !CAPS_LOCK
|
||||||
|
return true
|
||||||
case sdl.K_RETURN:
|
case sdl.K_RETURN:
|
||||||
|
if SUPER_DOWN {
|
||||||
|
// in sublime this goes
|
||||||
|
// into the next block
|
||||||
|
// nicely indented!
|
||||||
|
}
|
||||||
|
|
||||||
initial_x := b.curs.x
|
initial_x := b.curs.x
|
||||||
prevLineLen := b.contents[b.curs.y].Len()
|
prevLineLen := b.contents[b.curs.y].Len()
|
||||||
|
|
||||||
@ -248,6 +263,14 @@ func (b *Buffer) processActionKey(key int) bool {
|
|||||||
return true
|
return true
|
||||||
case sdl.K_RIGHT:
|
case sdl.K_RIGHT:
|
||||||
currLineLength := b.contents[b.curs.y].Len()
|
currLineLength := b.contents[b.curs.y].Len()
|
||||||
|
|
||||||
|
if SUPER_DOWN {
|
||||||
|
for b.curs.x < currLineLength {
|
||||||
|
b.curs.move(1, 0)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
if b.curs.x >= currLineLength && b.curs.y < len(b.contents)-1 {
|
if b.curs.x >= currLineLength && b.curs.y < len(b.contents)-1 {
|
||||||
// we're at the end of the line and we have
|
// we're at the end of the line and we have
|
||||||
// some lines after, let's wrap around
|
// some lines after, let's wrap around
|
||||||
@ -259,6 +282,13 @@ func (b *Buffer) processActionKey(key int) bool {
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
case sdl.K_LEFT:
|
case sdl.K_LEFT:
|
||||||
|
if SUPER_DOWN {
|
||||||
|
// TODO go to the nearest \t
|
||||||
|
// if no \t (i.e. start of line) go to
|
||||||
|
// the start of the line!
|
||||||
|
b.curs.gotoStart()
|
||||||
|
}
|
||||||
|
|
||||||
if b.curs.x == 0 && b.curs.y > 0 {
|
if b.curs.x == 0 && b.curs.y > 0 {
|
||||||
b.curs.move(b.contents[b.curs.y-1].Len(), -1)
|
b.curs.move(b.contents[b.curs.y-1].Len(), -1)
|
||||||
|
|
||||||
@ -267,6 +297,17 @@ func (b *Buffer) processActionKey(key int) bool {
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
case sdl.K_UP:
|
case sdl.K_UP:
|
||||||
|
if SUPER_DOWN {
|
||||||
|
// go to the start of the file
|
||||||
|
}
|
||||||
|
|
||||||
|
// as well as normally moving
|
||||||
|
// upwards, this moves the cursor
|
||||||
|
// to the start of the line
|
||||||
|
if ALT_DOWN {
|
||||||
|
b.curs.gotoStart()
|
||||||
|
}
|
||||||
|
|
||||||
if b.curs.y > 0 {
|
if b.curs.y > 0 {
|
||||||
offs := 0
|
offs := 0
|
||||||
prevLineLen := b.contents[b.curs.y-1].Len()
|
prevLineLen := b.contents[b.curs.y-1].Len()
|
||||||
@ -278,6 +319,20 @@ func (b *Buffer) processActionKey(key int) bool {
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
case sdl.K_DOWN:
|
case sdl.K_DOWN:
|
||||||
|
if SUPER_DOWN {
|
||||||
|
// go to the end of the file
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME this doesnt work properly
|
||||||
|
if ALT_DOWN {
|
||||||
|
currLineLength := b.contents[b.curs.y].Len()
|
||||||
|
// in sublime this goes to the end
|
||||||
|
// of every line
|
||||||
|
for b.curs.x < currLineLength {
|
||||||
|
b.curs.move(1, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if b.curs.y < len(b.contents)-1 {
|
if b.curs.y < len(b.contents)-1 {
|
||||||
offs := 0
|
offs := 0
|
||||||
nextLineLen := b.contents[b.curs.y+1].Len()
|
nextLineLen := b.contents[b.curs.y+1].Len()
|
||||||
@ -320,7 +375,7 @@ func (b *Buffer) processActionKey(key int) bool {
|
|||||||
case sdl.K_LSHIFT:
|
case sdl.K_LSHIFT:
|
||||||
fallthrough
|
fallthrough
|
||||||
case sdl.K_RSHIFT:
|
case sdl.K_RSHIFT:
|
||||||
return b.processShift()
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
@ -331,12 +386,9 @@ var (
|
|||||||
SUPER_DOWN = false // cmd on mac, ctrl on windows
|
SUPER_DOWN = false // cmd on mac, ctrl on windows
|
||||||
CONTROL_DOWN = false // what is this on windows?
|
CONTROL_DOWN = false // what is this on windows?
|
||||||
ALT_DOWN = false // option on mac
|
ALT_DOWN = false // option on mac
|
||||||
|
CAPS_LOCK = false
|
||||||
)
|
)
|
||||||
|
|
||||||
func (b *Buffer) processShift() bool {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(Felix) this is really stupid
|
// TODO(Felix) this is really stupid
|
||||||
func (b *Buffer) makeTab() string {
|
func (b *Buffer) makeTab() string {
|
||||||
blah := []rune{}
|
blah := []rune{}
|
||||||
|
@ -5,6 +5,12 @@ type Cursor struct {
|
|||||||
rx, ry int
|
rx, ry int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Cursor) gotoStart() {
|
||||||
|
for c.x > 1 {
|
||||||
|
c.move(-1, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Cursor) move(x, y int) {
|
func (c *Cursor) move(x, y int) {
|
||||||
c.moveRender(x, y, x, y)
|
c.moveRender(x, y, x, y)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user