Added hybrid line numbers (#1690)

* Added hybrid line numbers

* Changed rulerhybrid to relativeruler, modified documentation accordingly.

* Reverted go.mod and go.sum
I don't know how they got changed but they are good now.

Co-authored-by: Colin Hughes <semilin@pop-os.localdomain>
This commit is contained in:
Colin Hughes
2020-05-28 19:24:09 -07:00
committed by GitHub
parent a95b17a4e7
commit 00edf0207f
3 changed files with 15 additions and 1 deletions

View File

@@ -203,6 +203,7 @@ var defaultCommonSettings = map[string]interface{}{
"readonly": false, "readonly": false,
"rmtrailingws": false, "rmtrailingws": false,
"ruler": true, "ruler": true,
"relativeruler": false,
"savecursor": false, "savecursor": false,
"saveundo": false, "saveundo": false,
"scrollbar": false, "scrollbar": false,

View File

@@ -335,7 +335,14 @@ func (w *BufWindow) drawDiffGutter(backgroundStyle tcell.Style, softwrapped bool
} }
func (w *BufWindow) drawLineNum(lineNumStyle tcell.Style, softwrapped bool, maxLineNumLength int, vloc *buffer.Loc, bloc *buffer.Loc) { func (w *BufWindow) drawLineNum(lineNumStyle tcell.Style, softwrapped bool, maxLineNumLength int, vloc *buffer.Loc, bloc *buffer.Loc) {
lineNum := strconv.Itoa(bloc.Y + 1) cursorLine := w.Buf.GetActiveCursor().Loc.Y
var lineInt int
if w.Buf.Settings["relativeruler"] == false || cursorLine == bloc.Y {
lineInt = bloc.Y + 1
} else {
lineInt = bloc.Y - cursorLine
}
lineNum := strconv.Itoa(util.Abs(lineInt))
// Write the spaces before the line number if necessary // Write the spaces before the line number if necessary
for i := 0; i < maxLineNumLength-len(lineNum); i++ { for i := 0; i < maxLineNumLength-len(lineNum); i++ {

View File

@@ -214,6 +214,12 @@ Here are the available options:
default value: `true` default value: `true`
* `relativeruler`: make line numbers display relatively. If set to true, all lines except
for the line that the cursor is located will display the distance from the
cursor's line.
default value: `false`
* `savecursor`: remember where the cursor was last time the file was opened and * `savecursor`: remember where the cursor was last time the file was opened and
put it there when you open the file again. Information is saved to put it there when you open the file again. Information is saved to
`~/.config/micro/buffers/` `~/.config/micro/buffers/`