This commit is contained in:
Luke I. Wilson 2021-03-15 16:07:50 -05:00
parent e2a4fc7e7c
commit 5fef5598de
2 changed files with 23 additions and 23 deletions

View File

@ -36,8 +36,8 @@ type TextEdit struct {
prevCurCol int // Previous maximum column the cursor was at, when the user pressed left or right prevCurCol int // Previous maximum column the cursor was at, when the user pressed left or right
scrollx, scrolly int // X and Y offset of view, known as scroll scrollx, scrolly int // X and Y offset of view, known as scroll
selection Selection // Selection: nil is no selection selection Selection // Selection: nil is no selection
selectMode bool // Whether the user is actively selecting text selectMode bool // Whether the user is actively selecting text
Theme *Theme Theme *Theme
} }
@ -289,7 +289,7 @@ func (t *TextEdit) CursorUp() {
if t.UseHardTabs { // When using hard tabs, subtract offsets produced by tabs if t.UseHardTabs { // When using hard tabs, subtract offsets produced by tabs
tabOffset := t.getTabOffsetInLineAtCol(t.cury-1, t.prevCurCol) tabOffset := t.getTabOffsetInLineAtCol(t.cury-1, t.prevCurCol)
hardTabs := tabOffset / t.TabSize hardTabs := tabOffset / t.TabSize
col -= tabOffset-hardTabs // We still want to count each \t in the col col -= tabOffset - hardTabs // We still want to count each \t in the col
} }
line, col := t.clampLineCol(t.cury-1, col) line, col := t.clampLineCol(t.cury-1, col)
t.SetLineCol(line, col) t.SetLineCol(line, col)
@ -305,7 +305,7 @@ func (t *TextEdit) CursorDown() {
if t.UseHardTabs { if t.UseHardTabs {
tabOffset := t.getTabOffsetInLineAtCol(t.cury+1, t.prevCurCol) tabOffset := t.getTabOffsetInLineAtCol(t.cury+1, t.prevCurCol)
hardTabs := tabOffset / t.TabSize hardTabs := tabOffset / t.TabSize
col -= tabOffset-hardTabs // We still want to count each \t in the col col -= tabOffset - hardTabs // We still want to count each \t in the col
} }
line, col := t.clampLineCol(t.cury+1, col) line, col := t.clampLineCol(t.cury+1, col)
t.SetLineCol(line, col) // Go to line below t.SetLineCol(line, col) // Go to line below
@ -320,7 +320,7 @@ func (t *TextEdit) CursorLeft() {
t.SetLineCol(t.cury, t.curx-1) t.SetLineCol(t.cury, t.curx-1)
} }
tabOffset := t.getTabOffsetInLineAtCol(t.cury, t.curx) tabOffset := t.getTabOffsetInLineAtCol(t.cury, t.curx)
t.prevCurCol = t.curx+tabOffset t.prevCurCol = t.curx + tabOffset
} }
// CursorRight moves the cursor right a column. // CursorRight moves the cursor right a column.
@ -457,10 +457,10 @@ func (t *TextEdit) HandleEvent(event tcell.Event) bool {
// Reset the selection to cursor pos // Reset the selection to cursor pos
t.selection.StartLine, t.selection.StartCol = t.cury, t.curx t.selection.StartLine, t.selection.StartCol = t.cury, t.curx
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
} }
t.CursorRight() // Advance the cursor t.CursorRight() // Advance the cursor
t.selection.EndLine, t.selection.EndCol = t.cury, t.curx t.selection.EndLine, t.selection.EndCol = t.cury, t.curx
} else { } else {
if t.selectMode { if t.selectMode {
t.selectMode = false t.selectMode = false

View File

@ -29,20 +29,20 @@ func (theme *Theme) GetOrDefault(key string) tcell.Style {
// DefaultTheme uses only the first 16 colors present in most colored terminals. // DefaultTheme uses only the first 16 colors present in most colored terminals.
var DefaultTheme = Theme{ var DefaultTheme = Theme{
"Normal": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack), "Normal": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
"Button": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorWhite), "Button": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorWhite),
"InputField": tcell.Style{}.Foreground(tcell.ColorWhite).Background(tcell.ColorBlack), "InputField": tcell.Style{}.Foreground(tcell.ColorWhite).Background(tcell.ColorBlack),
"MenuBar": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver), "MenuBar": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver),
"MenuBarSelected": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack), "MenuBarSelected": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
"Menu": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver), "Menu": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver),
"MenuSelected": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack), "MenuSelected": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
"QuickChar": tcell.Style{}.Foreground(tcell.ColorYellow).Background(tcell.ColorBlack), "QuickChar": tcell.Style{}.Foreground(tcell.ColorYellow).Background(tcell.ColorBlack),
"Tab": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack), "Tab": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
"TabContainer": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack), "TabContainer": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
"TabSelected": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver), "TabSelected": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver),
"TextEdit": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack), "TextEdit": tcell.Style{}.Foreground(tcell.ColorSilver).Background(tcell.ColorBlack),
"TextEditColumn": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorGray), "TextEditColumn": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorGray),
"TextEditSelected":tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver), "TextEditSelected": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver),
"Window": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver), "Window": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorSilver),
"WindowHeader": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorWhite), "WindowHeader": tcell.Style{}.Foreground(tcell.ColorBlack).Background(tcell.ColorWhite),
} }