Skip to content

Commit

Permalink
Add a check to shrink in Align mode
Browse files Browse the repository at this point in the history
Add a shrinking column or judgment function.
Add functions other than the shrink and expansion tooggle.
  • Loading branch information
noborus committed Sep 8, 2024
1 parent e2d9c06 commit d4826a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions oviewer/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,24 +771,39 @@ func (root *Root) bottomSectionLN(ctx context.Context) int {

// ShrinkColumn shrinks the specified column.
func (root *Root) ShrinkColumn(ctx context.Context, cursor int) error {
return root.Doc.shrinkColumn(ctx, cursor, true)
return root.Doc.shrinkColumn(cursor, true)
}

// ExpandColumn expands the specified column.
func (root *Root) ExpandColumn(ctx context.Context, cursor int) error {
return root.Doc.shrinkColumn(ctx, cursor, false)
return root.Doc.shrinkColumn(cursor, false)
}

// toggleColumnShrink shrinks or expands the current cursor column.
func (root *Root) toggleColumnShrink(ctx context.Context) {
cursor := root.Doc.columnCursor
if err := root.Doc.shrinkColumn(ctx, cursor, !root.Doc.alignConv.columnAttrs[cursor].shrink); err != nil {
shrink, err := root.Doc.isColumnShink(cursor)
if err != nil {
root.setMessage(err.Error())
}
if err := root.Doc.shrinkColumn(cursor, !shrink); err != nil {
root.setMessage(err.Error())
}
}

// isColumnShink returns whether the specified column is shrink.
func (m *Document) isColumnShink(cursor int) (bool, error) {
if m.Converter != convAlign {
return false, ErrNotAlignMode
}
if cursor >= len(m.alignConv.columnAttrs) {
return false, ErrNoColumnSelected
}
return m.alignConv.columnAttrs[cursor].shrink, nil
}

// shinkColumn shrinks or expands the specified column.
func (m *Document) shrinkColumn(ctx context.Context, cursor int, shrink bool) error {
func (m *Document) shrinkColumn(cursor int, shrink bool) error {
if m.Converter != convAlign {
return ErrNotAlignMode
}
Expand Down
2 changes: 1 addition & 1 deletion oviewer/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1623,7 +1623,7 @@ func TestRoot_ShrinkColumn(t *testing.T) {
root.Doc.Converter = tt.fields.converter
root.Doc.ColumnDelimiter = ","
root.prepareDraw(ctx)
if err := root.Doc.shrinkColumn(ctx, tt.args.cursor, tt.args.shrink); (err != nil) != tt.wantErr {
if err := root.Doc.shrinkColumn(tt.args.cursor, tt.args.shrink); (err != nil) != tt.wantErr {
t.Errorf("Root.ShrinkColumn() error = %v, wantErr %v", err, tt.wantErr)
}
})
Expand Down

0 comments on commit d4826a2

Please sign in to comment.