Fixes. Ready for testing.

This commit is contained in:
Oliver 2022-08-27 11:27:13 +02:00
parent f2c8ab440f
commit 0ded991cb4
1 changed files with 28 additions and 19 deletions

View File

@ -120,7 +120,7 @@ type textAreaUndoItem struct {
// //
// - Enter: Insert a newline character (see [NewLine]). // - Enter: Insert a newline character (see [NewLine]).
// - Tab: Insert a tab character (\t). It will be rendered like [TabSize] // - Tab: Insert a tab character (\t). It will be rendered like [TabSize]
// spaces. // spaces. (This may eventually be changed to behave like regular tabs.)
// - Ctrl-H, Backspace: Delete one character to the left of the cursor. // - Ctrl-H, Backspace: Delete one character to the left of the cursor.
// - Ctrl-D, Delete: Delete the character under the cursor (or the first // - Ctrl-D, Delete: Delete the character under the cursor (or the first
// character on the next line if the cursor is at the end of a line). // character on the next line if the cursor is at the end of a line).
@ -577,7 +577,7 @@ func (t *TextArea) replace(deleteStart, deleteEnd [3]int, insert string, continu
after: len(t.spans) + 1, after: len(t.spans) + 1,
originalBefore: before, originalBefore: before,
originalAfter: after, originalAfter: after,
pos: deleteEnd, pos: t.cursor.pos,
continuation: continuation, continuation: continuation,
}) })
t.spans = append(t.spans, t.spans[before]) t.spans = append(t.spans, t.spans[before])
@ -1415,6 +1415,10 @@ func (t *TextArea) InputHandler() func(event *tcell.EventKey, setFocus func(p Pr
t.cursor = t.selectionStart t.cursor = t.selectionStart
} }
t.findCursor(true, t.cursor.row) t.findCursor(true, t.cursor.row)
} else if event.Modifiers()&tcell.ModMeta != 0 {
// On some systems, the Meta flag is set here when Alt
// is pressed (and Shift at the same time).
t.moveWordLeft(true)
} else if t.cursor.actualColumn == 0 { } else if t.cursor.actualColumn == 0 {
// Move to the end of the previous row. // Move to the end of the previous row.
if t.cursor.row > 0 { if t.cursor.row > 0 {
@ -1427,7 +1431,7 @@ func (t *TextArea) InputHandler() func(event *tcell.EventKey, setFocus func(p Pr
if event.Modifiers()&tcell.ModShift == 0 { if event.Modifiers()&tcell.ModShift == 0 {
t.selectionStart = t.cursor t.selectionStart = t.cursor
} }
} else if !t.wrap { } else if !t.wrap { // This doesn't work on all terminals.
// Just scroll. // Just scroll.
t.columnOffset-- t.columnOffset--
if t.columnOffset < 0 { if t.columnOffset < 0 {
@ -1444,26 +1448,33 @@ func (t *TextArea) InputHandler() func(event *tcell.EventKey, setFocus func(p Pr
} }
t.findCursor(true, t.cursor.row) t.findCursor(true, t.cursor.row)
} else if t.cursor.pos[0] != 1 { } else if t.cursor.pos[0] != 1 {
var clusterWidth int if event.Modifiers()&tcell.ModMeta != 0 {
_, _, _, clusterWidth, t.cursor.pos, _ = t.step("", t.cursor.pos, t.cursor.pos) // On some systems, the Meta flag is set here when Alt
if len(t.lineStarts) <= t.cursor.row+1 { // is pressed (and Shift at the same time).
t.extendLines(t.lastWidth, t.cursor.row+1) t.moveWordRight(true)
}
if t.cursor.row+1 < len(t.lineStarts) && t.lineStarts[t.cursor.row+1] == t.cursor.pos {
// We've reached the end of the line.
t.cursor.row++
t.cursor.actualColumn = 0
t.cursor.column = 0
t.findCursor(true, t.cursor.row)
} else { } else {
// Move one character to the right. // Move one grapheme cluster to the right.
t.moveCursor(t.cursor.row, t.cursor.actualColumn+clusterWidth) var clusterWidth int
_, _, _, clusterWidth, t.cursor.pos, _ = t.step("", t.cursor.pos, t.cursor.pos)
if len(t.lineStarts) <= t.cursor.row+1 {
t.extendLines(t.lastWidth, t.cursor.row+1)
}
if t.cursor.row+1 < len(t.lineStarts) && t.lineStarts[t.cursor.row+1] == t.cursor.pos {
// We've reached the end of the line.
t.cursor.row++
t.cursor.actualColumn = 0
t.cursor.column = 0
t.findCursor(true, t.cursor.row)
} else {
// Move one character to the right.
t.moveCursor(t.cursor.row, t.cursor.actualColumn+clusterWidth)
}
} }
} }
if event.Modifiers()&tcell.ModShift == 0 { if event.Modifiers()&tcell.ModShift == 0 {
t.selectionStart = t.cursor t.selectionStart = t.cursor
} }
} else if !t.wrap { } else if !t.wrap { // This doesn't work on all terminals.
// Just scroll. // Just scroll.
t.columnOffset++ t.columnOffset++
if t.columnOffset >= t.widestLine { if t.columnOffset >= t.widestLine {
@ -1873,5 +1884,3 @@ func (t *TextArea) MouseHandler() func(action MouseAction, event *tcell.EventMou
return return
}) })
} }
//TODO: Don't replace tab with spaces.