Ran go fmt *.go
on all sources
This commit is contained in:
parent
e115855491
commit
3982628653
8
main.go
8
main.go
@ -4,9 +4,9 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
@ -186,7 +186,7 @@ func main() {
|
|||||||
tabContainer.AddTab("noname", textEdit)
|
tabContainer.AddTab("noname", textEdit)
|
||||||
|
|
||||||
changeFocus(tabContainer)
|
changeFocus(tabContainer)
|
||||||
tabContainer.FocusTab(tabContainer.GetTabCount()-1)
|
tabContainer.FocusTab(tabContainer.GetTabCount() - 1)
|
||||||
}}, &ui.ItemEntry{Name: "Open...", Shortcut: "Ctrl+O", Callback: func() {
|
}}, &ui.ItemEntry{Name: "Open...", Shortcut: "Ctrl+O", Callback: func() {
|
||||||
callback := func(filePaths []string) {
|
callback := func(filePaths []string) {
|
||||||
var errOccurred bool
|
var errOccurred bool
|
||||||
@ -214,7 +214,7 @@ func main() {
|
|||||||
dialog = nil // Hide the file selector
|
dialog = nil // Hide the file selector
|
||||||
changeFocus(tabContainer)
|
changeFocus(tabContainer)
|
||||||
if tabContainer.GetTabCount() > 0 {
|
if tabContainer.GetTabCount() > 0 {
|
||||||
tabContainer.FocusTab(tabContainer.GetTabCount()-1)
|
tabContainer.FocusTab(tabContainer.GetTabCount() - 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -426,7 +426,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ev.Modifiers() & tcell.ModCtrl != 0 {
|
if ev.Modifiers()&tcell.ModCtrl != 0 {
|
||||||
handled := menuBar.HandleEvent(ev)
|
handled := menuBar.HandleEvent(ev)
|
||||||
if handled {
|
if handled {
|
||||||
continue // Avoid passing the event to the focusedComponent
|
continue // Avoid passing the event to the focusedComponent
|
||||||
|
@ -62,7 +62,6 @@ type Buffer interface {
|
|||||||
// the last rune before the line delimiter.
|
// the last rune before the line delimiter.
|
||||||
ClampLineCol(line, col int) (int, int)
|
ClampLineCol(line, col int) (int, int)
|
||||||
|
|
||||||
|
|
||||||
// LineColToPos returns the index of the byte at line, col. If line is less than
|
// LineColToPos returns the index of the byte at line, col. If line is less than
|
||||||
// zero, or more than the number of available lines, the function will panic. If
|
// zero, or more than the number of available lines, the function will panic. If
|
||||||
// col is less than zero, the function will panic. If col is greater than the
|
// col is less than zero, the function will panic. If col is greater than the
|
||||||
|
@ -23,7 +23,7 @@ func (c *Colorscheme) GetStyle(s Syntax) tcell.Style {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return tcell.StyleDefault; // No value for Default; use default style.
|
return tcell.StyleDefault // No value for Default; use default style.
|
||||||
}
|
}
|
||||||
|
|
||||||
type RegexpRegion struct {
|
type RegexpRegion struct {
|
||||||
@ -111,9 +111,9 @@ func (h *Highlighter) updateLines(startLine, endLine int) {
|
|||||||
if indexes != nil {
|
if indexes != nil {
|
||||||
for i := range indexes {
|
for i := range indexes {
|
||||||
startLine, startCol := h.Buffer.PosToLineCol(indexes[i][0] + startPos)
|
startLine, startCol := h.Buffer.PosToLineCol(indexes[i][0] + startPos)
|
||||||
endLine, endCol := h.Buffer.PosToLineCol(indexes[i][1]-1 + startPos)
|
endLine, endCol := h.Buffer.PosToLineCol(indexes[i][1] - 1 + startPos)
|
||||||
|
|
||||||
match := Match { startCol, endLine, endCol, v }
|
match := Match{startCol, endLine, endCol, v}
|
||||||
|
|
||||||
h.lineMatches[startLine] = append(h.lineMatches[startLine], match) // Unsorted
|
h.lineMatches[startLine] = append(h.lineMatches[startLine], match) // Unsorted
|
||||||
}
|
}
|
||||||
@ -138,7 +138,7 @@ func (h *Highlighter) UpdateInvalidatedLines(startLine, endLine int) {
|
|||||||
|
|
||||||
// Keep endLine clamped
|
// Keep endLine clamped
|
||||||
if endLine >= len(h.lineMatches) {
|
if endLine >= len(h.lineMatches) {
|
||||||
endLine = len(h.lineMatches)-1
|
endLine = len(h.lineMatches) - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move endLine back to first line at or before endLine with invalidated changes
|
// Move endLine back to first line at or before endLine with invalidated changes
|
||||||
|
@ -99,7 +99,7 @@ func (b *RopeBuffer) Line(line int) []byte {
|
|||||||
func (b *RopeBuffer) Slice(startLine, startCol, endLine, endCol int) []byte {
|
func (b *RopeBuffer) Slice(startLine, startCol, endLine, endCol int) []byte {
|
||||||
endPos := b.LineColToPos(endLine, endCol)
|
endPos := b.LineColToPos(endLine, endCol)
|
||||||
if length := (*rope.Node)(b).Len(); endPos >= length {
|
if length := (*rope.Node)(b).Len(); endPos >= length {
|
||||||
endPos = length-1
|
endPos = length - 1
|
||||||
}
|
}
|
||||||
return (*rope.Node)(b).Slice(b.LineColToPos(startLine, startCol), endPos+1)
|
return (*rope.Node)(b).Slice(b.LineColToPos(startLine, startCol), endPos+1)
|
||||||
}
|
}
|
||||||
@ -275,7 +275,7 @@ func (b *RopeBuffer) RunesInLine(line int) int {
|
|||||||
func (b *RopeBuffer) ClampLineCol(line, col int) (int, int) {
|
func (b *RopeBuffer) ClampLineCol(line, col int) (int, int) {
|
||||||
if line < 0 {
|
if line < 0 {
|
||||||
line = 0
|
line = 0
|
||||||
} else if lines := b.Lines()-1; line > lines {
|
} else if lines := b.Lines() - 1; line > lines {
|
||||||
line = lines
|
line = lines
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ func TestRopePosToLineCol(t *testing.T) {
|
|||||||
t.Errorf("Expected startCol == 0, got %v", startCol)
|
t.Errorf("Expected startCol == 0, got %v", startCol)
|
||||||
}
|
}
|
||||||
|
|
||||||
endPos := buf.Len()-1
|
endPos := buf.Len() - 1
|
||||||
endLine, endCol := buf.PosToLineCol(endPos)
|
endLine, endCol := buf.PosToLineCol(endPos)
|
||||||
t.Logf("endPos = %v", endPos)
|
t.Logf("endPos = %v", endPos)
|
||||||
if endLine != 3 {
|
if endLine != 3 {
|
||||||
|
@ -90,7 +90,7 @@ func DrawWindow(s tcell.Screen, x, y, width, height int, title string, theme *Th
|
|||||||
headerStyle := theme.GetOrDefault("WindowHeader")
|
headerStyle := theme.GetOrDefault("WindowHeader")
|
||||||
|
|
||||||
DrawRect(s, x, y, width, 1, ' ', headerStyle) // Draw header background
|
DrawRect(s, x, y, width, 1, ' ', headerStyle) // Draw header background
|
||||||
DrawStr(s, x + width/2 - len(title)/2, y, title, headerStyle) // Draw header title
|
DrawStr(s, x+width/2-len(title)/2, y, title, headerStyle) // Draw header title
|
||||||
|
|
||||||
DrawRect(s, x, y+1, width, height-1, ' ', theme.GetOrDefault("Window")) // Draw body
|
DrawRect(s, x, y+1, width, height-1, ' ', theme.GetOrDefault("Window")) // Draw body
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ func (f *InputField) insert(dst []byte, at int, src ...byte) []byte {
|
|||||||
copy(dstn[at:], src)
|
copy(dstn[at:], src)
|
||||||
return dstn
|
return dstn
|
||||||
}
|
}
|
||||||
dstn := make([]byte, len(dst) + len(src))
|
dstn := make([]byte, len(dst)+len(src))
|
||||||
copy(dstn, dst[:at])
|
copy(dstn, dst[:at])
|
||||||
copy(dstn[at:], src)
|
copy(dstn[at:], src)
|
||||||
copy(dstn[at+len(src):], dst[at:])
|
copy(dstn[at+len(src):], dst[at:])
|
||||||
|
@ -118,7 +118,7 @@ func (d *MessageDialog) SetPos(x, y int) {
|
|||||||
func (d *MessageDialog) GetMinSize() (int, int) {
|
func (d *MessageDialog) GetMinSize() (int, int) {
|
||||||
lines := strings.Count(d.messageWrapped, "\n") + 1
|
lines := strings.Count(d.messageWrapped, "\n") + 1
|
||||||
|
|
||||||
return Max(len(d.Title)+2, 30), 2+lines+2
|
return Max(len(d.Title)+2, 30), 2 + lines + 2
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *MessageDialog) GetSize() (int, int) {
|
func (d *MessageDialog) GetSize() (int, int) {
|
||||||
|
@ -9,9 +9,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/mattn/go-runewidth"
|
|
||||||
"github.com/fivemoreminix/qedit/ui/buffer"
|
"github.com/fivemoreminix/qedit/ui/buffer"
|
||||||
"github.com/gdamore/tcell/v2"
|
"github.com/gdamore/tcell/v2"
|
||||||
|
"github.com/mattn/go-runewidth"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Selection represents a region of the buffer to be selected for text editing
|
// A Selection represents a region of the buffer to be selected for text editing
|
||||||
@ -91,10 +91,10 @@ loop:
|
|||||||
t.Buffer = buffer.NewRopeBuffer(contents)
|
t.Buffer = buffer.NewRopeBuffer(contents)
|
||||||
|
|
||||||
// TODO: replace with automatic determination of language via filetype
|
// TODO: replace with automatic determination of language via filetype
|
||||||
lang := &buffer.Language {
|
lang := &buffer.Language{
|
||||||
Name: "Go",
|
Name: "Go",
|
||||||
Filetypes: []string{".go"},
|
Filetypes: []string{".go"},
|
||||||
Rules: map[*buffer.RegexpRegion]buffer.Syntax {
|
Rules: map[*buffer.RegexpRegion]buffer.Syntax{
|
||||||
&buffer.RegexpRegion{Start: regexp.MustCompile("\\/\\/.*")}: buffer.Comment,
|
&buffer.RegexpRegion{Start: regexp.MustCompile("\\/\\/.*")}: buffer.Comment,
|
||||||
&buffer.RegexpRegion{Start: regexp.MustCompile("\".*?\"")}: buffer.String,
|
&buffer.RegexpRegion{Start: regexp.MustCompile("\".*?\"")}: buffer.String,
|
||||||
&buffer.RegexpRegion{
|
&buffer.RegexpRegion{
|
||||||
@ -115,7 +115,7 @@ loop:
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
colorscheme := &buffer.Colorscheme {
|
colorscheme := &buffer.Colorscheme{
|
||||||
buffer.Default: tcell.Style{}.Foreground(tcell.ColorLightGray).Background(tcell.ColorBlack),
|
buffer.Default: tcell.Style{}.Foreground(tcell.ColorLightGray).Background(tcell.ColorBlack),
|
||||||
buffer.Comment: tcell.Style{}.Foreground(tcell.ColorGray).Background(tcell.ColorBlack),
|
buffer.Comment: tcell.Style{}.Foreground(tcell.ColorGray).Background(tcell.ColorBlack),
|
||||||
buffer.String: tcell.Style{}.Foreground(tcell.ColorOlive).Background(tcell.ColorBlack),
|
buffer.String: tcell.Style{}.Foreground(tcell.ColorOlive).Background(tcell.ColorBlack),
|
||||||
@ -275,7 +275,7 @@ func (t *TextEdit) SetLineCol(line, col int) {
|
|||||||
line, col = t.Buffer.ClampLineCol(line, col)
|
line, col = t.Buffer.ClampLineCol(line, col)
|
||||||
|
|
||||||
// Handle hard tabs
|
// Handle hard tabs
|
||||||
tabOffset := t.getTabCountInLineAtCol(line, col) * (t.TabSize-1) // Offset for the current line from hard tabs (temporary; purely visual)
|
tabOffset := t.getTabCountInLineAtCol(line, col) * (t.TabSize - 1) // Offset for the current line from hard tabs (temporary; purely visual)
|
||||||
|
|
||||||
// Scroll the screen when going to lines out of view
|
// Scroll the screen when going to lines out of view
|
||||||
if line >= t.scrolly+t.height-1 { // If the new line is below view...
|
if line >= t.scrolly+t.height-1 { // If the new line is below view...
|
||||||
@ -386,7 +386,7 @@ func (t *TextEdit) Draw(s tcell.Screen) {
|
|||||||
selectedStyle := t.Theme.GetOrDefault("TextEditSelected")
|
selectedStyle := t.Theme.GetOrDefault("TextEditSelected")
|
||||||
columnStyle := t.Theme.GetOrDefault("TextEditColumn")
|
columnStyle := t.Theme.GetOrDefault("TextEditColumn")
|
||||||
|
|
||||||
t.Highlighter.UpdateInvalidatedLines(t.scrolly, t.scrolly + (t.height-1))
|
t.Highlighter.UpdateInvalidatedLines(t.scrolly, t.scrolly+(t.height-1))
|
||||||
|
|
||||||
var tabBytes []byte
|
var tabBytes []byte
|
||||||
if t.UseHardTabs {
|
if t.UseHardTabs {
|
||||||
@ -410,20 +410,20 @@ func (t *TextEdit) Draw(s tcell.Screen) {
|
|||||||
|
|
||||||
// When iterating lineTabs: the value at i is
|
// When iterating lineTabs: the value at i is
|
||||||
// the rune index the tab was found at.
|
// the rune index the tab was found at.
|
||||||
// var lineTabs [128]int // Rune index for each hard tab '\t' in lineBytes
|
// var lineTabs [128]int // Rune index for each hard tab '\t' in lineBytes
|
||||||
// var tabs int // Length of lineTabs (number of hard tabs)
|
// var tabs int // Length of lineTabs (number of hard tabs)
|
||||||
if t.UseHardTabs {
|
if t.UseHardTabs {
|
||||||
// var ri int // rune index
|
// var ri int // rune index
|
||||||
// var i int
|
// var i int
|
||||||
// for i < len(lineBytes) {
|
// for i < len(lineBytes) {
|
||||||
// r, size := utf8.DecodeRune(lineBytes[i:])
|
// r, size := utf8.DecodeRune(lineBytes[i:])
|
||||||
// if r == '\t' {
|
// if r == '\t' {
|
||||||
// lineTabs[tabs] = ri
|
// lineTabs[tabs] = ri
|
||||||
// tabs++
|
// tabs++
|
||||||
// }
|
// }
|
||||||
// i += size
|
// i += size
|
||||||
// ri++
|
// ri++
|
||||||
// }
|
// }
|
||||||
lineBytes = bytes.ReplaceAll(lineBytes, []byte{'\t'}, tabBytes)
|
lineBytes = bytes.ReplaceAll(lineBytes, []byte{'\t'}, tabBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,7 +475,7 @@ func (t *TextEdit) Draw(s tcell.Screen) {
|
|||||||
return ridx
|
return ridx
|
||||||
}
|
}
|
||||||
|
|
||||||
for col < t.x + t.width { // For each column in view...
|
for col < t.x+t.width { // For each column in view...
|
||||||
var r rune = ' ' // Rune to draw this iteration
|
var r rune = ' ' // Rune to draw this iteration
|
||||||
var size int = 1 // Size of the rune (in bytes)
|
var size int = 1 // Size of the rune (in bytes)
|
||||||
var selected bool // Whether this rune should be styled as selected
|
var selected bool // Whether this rune should be styled as selected
|
||||||
|
Loading…
x
Reference in New Issue
Block a user