Improved modifying selection with cursor movement
This commit is contained in:
parent
7971ef16ab
commit
d5ec12c1c8
@ -471,11 +471,60 @@ func (t *TextEdit) HandleEvent(event tcell.Event) bool {
|
|||||||
switch ev.Key() {
|
switch ev.Key() {
|
||||||
// Cursor movement
|
// Cursor movement
|
||||||
case tcell.KeyUp:
|
case tcell.KeyUp:
|
||||||
t.CursorUp()
|
if ev.Modifiers() == tcell.ModShift {
|
||||||
|
if !t.selectMode {
|
||||||
|
t.selection.StartLine, t.selection.StartCol = t.cury, t.curx
|
||||||
|
t.selection.EndLine, t.selection.EndCol = t.cury, t.curx
|
||||||
|
t.selectMode = true
|
||||||
|
}
|
||||||
|
prevCurX, prevCurY := t.curx, t.cury
|
||||||
|
t.CursorUp()
|
||||||
|
//
|
||||||
|
if prevCurY <= t.selection.StartLine && prevCurX <= t.selection.StartCol {
|
||||||
|
t.selection.StartLine, t.selection.StartCol = t.cury, t.curx
|
||||||
|
} else {
|
||||||
|
t.selection.EndLine, t.selection.EndCol = t.cury, t.curx
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
t.selectMode = false
|
||||||
|
t.CursorUp()
|
||||||
|
}
|
||||||
case tcell.KeyDown:
|
case tcell.KeyDown:
|
||||||
t.CursorDown()
|
if ev.Modifiers() == tcell.ModShift {
|
||||||
|
if !t.selectMode {
|
||||||
|
t.selection.StartLine, t.selection.StartCol = t.cury, t.curx
|
||||||
|
t.selection.EndLine, t.selection.EndCol = t.cury, t.curx
|
||||||
|
t.selectMode = true
|
||||||
|
}
|
||||||
|
prevCurX, prevCurY := t.curx, t.cury
|
||||||
|
t.CursorDown()
|
||||||
|
if prevCurY >= t.selection.EndLine && prevCurX >= t.selection.EndCol {
|
||||||
|
t.selection.EndLine, t.selection.EndCol = t.cury, t.curx
|
||||||
|
} else {
|
||||||
|
t.selection.StartLine, t.selection.StartCol = t.cury, t.curx
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
t.selectMode = false
|
||||||
|
t.CursorDown()
|
||||||
|
}
|
||||||
case tcell.KeyLeft:
|
case tcell.KeyLeft:
|
||||||
t.CursorLeft()
|
if ev.Modifiers() == tcell.ModShift {
|
||||||
|
if !t.selectMode {
|
||||||
|
t.selection.StartLine, t.selection.StartCol = t.cury, t.curx
|
||||||
|
t.selection.EndLine, t.selection.EndCol = t.cury, t.curx
|
||||||
|
t.selectMode = true
|
||||||
|
}
|
||||||
|
prevCurX, prevCurY := t.curx, t.cury
|
||||||
|
t.CursorLeft()
|
||||||
|
if prevCurY == t.selection.StartLine && prevCurX == t.selection.StartCol { // We are moving the start...
|
||||||
|
t.selection.StartLine, t.selection.StartCol = t.cury, t.curx
|
||||||
|
} else {
|
||||||
|
t.selection.EndLine, t.selection.EndCol = t.cury, t.curx
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
t.selectMode = false
|
||||||
|
t.CursorLeft()
|
||||||
|
}
|
||||||
case tcell.KeyRight:
|
case tcell.KeyRight:
|
||||||
if ev.Modifiers() == tcell.ModShift {
|
if ev.Modifiers() == tcell.ModShift {
|
||||||
if !t.selectMode { // If we are not already selecting...
|
if !t.selectMode { // If we are not already selecting...
|
||||||
@ -484,12 +533,15 @@ func (t *TextEdit) HandleEvent(event tcell.Event) bool {
|
|||||||
t.selection.EndLine, t.selection.EndCol = t.cury, t.curx
|
t.selection.EndLine, t.selection.EndCol = t.cury, t.curx
|
||||||
t.selectMode = true
|
t.selectMode = true
|
||||||
}
|
}
|
||||||
|
prevCurX, prevCurY := t.curx, t.cury
|
||||||
t.CursorRight() // Advance the cursor
|
t.CursorRight() // Advance the cursor
|
||||||
t.selection.EndLine, t.selection.EndCol = t.cury, t.curx
|
if prevCurY == t.selection.EndLine && prevCurX == t.selection.EndCol {
|
||||||
} else {
|
t.selection.EndLine, t.selection.EndCol = t.cury, t.curx
|
||||||
if t.selectMode {
|
} else {
|
||||||
t.selectMode = false
|
t.selection.StartLine, t.selection.StartCol = t.cury, t.curx
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
t.selectMode = false
|
||||||
t.CursorRight()
|
t.CursorRight()
|
||||||
}
|
}
|
||||||
case tcell.KeyHome:
|
case tcell.KeyHome:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user