Skip to content

Commit

Permalink
fix updating width logic
Browse files Browse the repository at this point in the history
  • Loading branch information
szktkfm committed Apr 6, 2024
1 parent 6376f53 commit f5174d5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"
"github.com/mattn/go-runewidth"
)

// TableModel defines a state for the table widget.
Expand Down Expand Up @@ -380,17 +381,18 @@ func (m *TableModel) switchMode(mode int) {
}

func (m TableModel) UpdateWidth(msg WidthMsg) {
// insert modeの場合
log.Debug(msg.width)
m.cols[m.cursor.x].Width = max(msg.width, m.cols[m.cursor.x].Width)
maxWidth := msg.width
for _, r := range m.rows {
maxWidth = max(runewidth.StringWidth(r[m.cursor.x].Value())+2, maxWidth)
}
maxWidth = max(runewidth.StringWidth(m.cols[m.cursor.x].Title.Value())+2, maxWidth)
m.cols[m.cursor.x].Width = maxWidth
}

func (m *TableModel) Copy() {
if len(m.rows) == 0 {
return
}
//TODO
// Rowのコピーだけを考える。今のところ
var row Row
for _, cell := range m.rows[m.cursor.y] {
row = append(row, NewCell(cell.Value()))
Expand All @@ -399,8 +401,6 @@ func (m *TableModel) Copy() {
}

func (m *TableModel) Paste() {
//TODO
// Rowのペーストだけを考える。今のところ
if m.register != nil {
m.insertRow(m.cursor.y+1, m.register.(Row))

Expand Down

0 comments on commit f5174d5

Please sign in to comment.