Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ var defaultCommonSettings = map[string]interface{}{
"tabstospaces": false,
"useprimary": true,
"wordwrap": false,
"wrapindent": float64(-1),
}

// a list of settings that should only be globally modified and their
Expand Down
17 changes: 17 additions & 0 deletions internal/display/bufwindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ func (w *BufWindow) displayBuffer() {

softwrap := b.Settings["softwrap"].(bool)
wordwrap := softwrap && b.Settings["wordwrap"].(bool)
wrapindent := util.IntOpt(w.Buf.Settings["wrapindent"])

tabsize := util.IntOpt(b.Settings["tabsize"])
colorcolumn := util.IntOpt(b.Settings["colorcolumn"])
Expand Down Expand Up @@ -688,11 +689,19 @@ func (w *BufWindow) displayBuffer() {
if !softwrap {
break
} else {
// Get leading whitespaces before we wrap the line
ws := util.GetLeadingWhitespace(b.LineBytes(bloc.Y))

vloc.Y++
if vloc.Y >= w.bufHeight {
break
}
wrap()

// After we wrapped the line, add the visual width of the leading whitespaces to the visual X column
if wrapindent > -1 {
vloc.X += util.StringWidth(ws, len(ws), tabsize) + wrapindent
}
}
}

Expand Down Expand Up @@ -721,11 +730,19 @@ func (w *BufWindow) displayBuffer() {
if !softwrap {
break
} else {
// Get leading whitespaces before we wrap the line
ws := util.GetLeadingWhitespace(b.LineBytes(bloc.Y))

vloc.Y++
if vloc.Y >= w.bufHeight {
break
}
wrap()

// After we wrapped the line, add the visual width of the leading whitespaces to the visual X column
if wrapindent > -1 {
vloc.X += util.StringWidth(ws, len(ws), tabsize) + wrapindent
}
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions internal/display/softwrap.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package display

import (
"bytes"

runewidth "github.com/mattn/go-runewidth"
"github.com/zyedidia/micro/v2/internal/buffer"
"github.com/zyedidia/micro/v2/internal/util"
Expand Down Expand Up @@ -80,6 +82,7 @@ func (w *BufWindow) getVLocFromLoc(loc buffer.Loc) VLoc {

wordwrap := w.Buf.Settings["wordwrap"].(bool)
tabsize := util.IntOpt(w.Buf.Settings["tabsize"])
leadingvisualspaces := w.getLeadingVisualSpaces(vloc)

line := w.Buf.LineBytes(loc.Y)
x := 0
Expand Down Expand Up @@ -121,6 +124,7 @@ func (w *BufWindow) getVLocFromLoc(loc buffer.Loc) VLoc {
if vloc.VisualX+wordwidth > w.bufWidth && vloc.VisualX > 0 {
vloc.Row++
vloc.VisualX = 0
vloc.VisualX += leadingvisualspaces
}

if x == loc.X {
Expand All @@ -137,6 +141,7 @@ func (w *BufWindow) getVLocFromLoc(loc buffer.Loc) VLoc {
if vloc.VisualX >= w.bufWidth {
vloc.Row++
vloc.VisualX = 0
vloc.VisualX += leadingvisualspaces
}
}
return vloc
Expand All @@ -151,6 +156,7 @@ func (w *BufWindow) getLocFromVLoc(svloc VLoc) buffer.Loc {

wordwrap := w.Buf.Settings["wordwrap"].(bool)
tabsize := util.IntOpt(w.Buf.Settings["tabsize"])
leadingvisualspaces := w.getLeadingVisualSpaces(svloc)

line := w.Buf.LineBytes(svloc.Line)
vloc := VLoc{SLoc: SLoc{svloc.Line, 0}, VisualX: 0}
Expand Down Expand Up @@ -202,6 +208,7 @@ func (w *BufWindow) getLocFromVLoc(svloc VLoc) buffer.Loc {
}
vloc.Row++
vloc.VisualX = 0
vloc.VisualX += leadingvisualspaces
}

for i := range widths {
Expand All @@ -218,11 +225,24 @@ func (w *BufWindow) getLocFromVLoc(svloc VLoc) buffer.Loc {
if vloc.VisualX >= w.bufWidth {
vloc.Row++
vloc.VisualX = 0
vloc.VisualX += leadingvisualspaces
}
}
return loc
}

// For wrapindent, count leading space to set correct VisualX on up, down action
func (w *BufWindow) getLeadingVisualSpaces(vloc VLoc) int {
wrapindent := util.IntOpt(w.Buf.Settings["wrapindent"])
if wrapindent < 0 {
return 0
}
line := w.Buf.LineBytes(vloc.Line)
leadingwhitespace := util.GetLeadingWhitespace(line)
leadingtabscount := bytes.Count(leadingwhitespace, []byte{'\t'})
return wrapindent + leadingtabscount*int(w.Buf.Settings["tabsize"].(float64)) + (len(leadingwhitespace) - leadingtabscount)
}

func (w *BufWindow) getRowCount(line int) int {
eol := buffer.Loc{X: util.CharacterCount(w.Buf.LineBytes(line)), Y: line}
return w.getVLocFromLoc(eol).Row + 1
Expand Down
7 changes: 7 additions & 0 deletions runtime/help/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,13 @@ Here are the available options:

default value: `false`

* `wrapindent`: maintain indentation of wrapped lines
* `-1`: disabled, wrapped lines begin in the first column
* `0`: wrapped lines inherit indentation from parent
* `4`: creates additional hanging indent by this width

default value: `-1`

* `xterm`: micro will assume that the terminal it is running in conforms to
`xterm-256color` regardless of what the `$TERM` variable actually contains.
Enabling this option may cause unwanted effects if your terminal in fact
Expand Down