Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabs support #1836

Merged
merged 17 commits into from May 8, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 7 additions & 16 deletions widget/textgrid.go
Expand Up @@ -15,7 +15,6 @@ const (
textAreaSpaceSymbol = '·'
textAreaTabSymbol = '→'
textAreaNewLineSymbol = '↵'
textTabIndent = " "
)

var (
Expand Down Expand Up @@ -68,7 +67,7 @@ type TextGrid struct {

ShowLineNumbers bool
ShowWhitespace bool
tabWidth int
TabWidth int // If set to 0 the fyne.DefaultTabWidth is used
}

// MinSize returns the smallest size this widget can shrink to
Expand Down Expand Up @@ -96,7 +95,7 @@ func (t *TextGrid) SetText(text string) {
cells = append(cells, TextGridCell{Rune: r})
if r == '\t' {
col := len(cells)
next := nextTab(col-1, t.TabWidth())
next := nextTab(col-1, t.tabWidth())
for i := col; i < next; i++ {
cells = append(cells, TextGridCell{Rune: ' '})
}
Expand All @@ -109,20 +108,12 @@ func (t *TextGrid) SetText(text string) {
t.Refresh()
}

// TabWidth either returns the set tab width or if not set the returns the DefaultTabWidth
func (t *TextGrid) TabWidth() int {
if t.tabWidth == 0 {
// tabWidth either returns the set tab width or if not set the returns the DefaultTabWidth
func (t *TextGrid) tabWidth() int {
adrianre12 marked this conversation as resolved.
Show resolved Hide resolved
if t.TabWidth == 0 {
return fyne.DefaultTabWidth
}
return t.tabWidth
}

// SetTabWidth sets the tab width if the supplied value is greater than 0
// This has to be set prior to calling SetText.
func (t *TextGrid) SetTabWidth(tabWidth int) {
if tabWidth > 0 {
t.tabWidth = tabWidth
}
return t.TabWidth
}

// Text returns the contents of the buffer as a single string (with no style information).
Expand All @@ -148,7 +139,7 @@ func (t *TextGrid) Text() string {
}
runes = append(runes, r.Rune)
if r.Rune == '\t' {
next = nextTab(c, t.TabWidth())
next = nextTab(c, t.tabWidth())
}
}
if i < len(t.Rows)-1 {
Expand Down