diff options
| -rw-r--r-- | tui/layout.go | 24 | ||||
| -rw-r--r-- | tui/text_input.go | 3 |
2 files changed, 26 insertions, 1 deletions
diff --git a/tui/layout.go b/tui/layout.go index 9dea37d..f195048 100644 --- a/tui/layout.go +++ b/tui/layout.go @@ -202,6 +202,8 @@ func (b *Box) computeText(axis int) { if g.Str() == "\n" { maxLine = max(maxLine, line) line = 0 + } else if g.Str() == "\t" { + line += 4 - line % 4 } else { line += g.Width() } @@ -225,14 +227,27 @@ func (b *Box) computeText(axis int) { for g.Next() { if !b.NoWrap { word.add(g.Str(), run.style) + var moreWidth int + if g.Str() == "\t" { + moreWidth = 4 - line.width % 4 + } + + if line.width >= limit { + b.computedLines = append(b.computedLines, line.flush()) + } if word.width >= limit { line.addRuns(word.flush()) - } else if line.width + word.width > limit { + } + if line.width + word.width + moreWidth > limit { b.computedLines = append(b.computedLines, line.flush()) } + if unicode.IsSpace(g.Runes()[0]) { line.addRuns(word.flush()) } + if g.Str() == "\t" { + line.width += 4 - line.width % 4 + } } else { line.add(g.Str(), run.style) } @@ -393,6 +408,13 @@ func (b *Box) drawComputed(parentRect rect, parentStyle Style) { } g := uniseg.NewGraphemes(t.text) for g.Next() { + if g.Str() == "\t" { + base := b.computedRect.min[0] + b.Margins[0] + width := 4 - (x - base) % 4 + for i := 0; i < width && x <= b.computedRect.max[0]; i++ { + x += WriteAt(x, y, " ", s) + } + } if x + g.Width() <= b.computedRect.max[0] { x += WriteAt(x, y, g.Str(), s) } else { diff --git a/tui/text_input.go b/tui/text_input.go index c861f96..b5d2748 100644 --- a/tui/text_input.go +++ b/tui/text_input.go @@ -180,6 +180,9 @@ func (t *TextInput) Update(ev Event) (usedKeybind bool) { if ev.TextInput != 0 { t.Write(string(ev.TextInput)) } + if ev.Key == keys.Tab { + t.Write("\t") + } selection := ev.Key & keys.Shift != 0 word := ev.Key & keys.Ctrl != 0 |
