Преглед изворни кода

Absolute relative line numbers

Johan Rong пре 1 недеља
родитељ
комит
22184d93ee
2 измењених фајлова са 10 додато и 17 уклоњено
  1. 3 2
      internal/editor/draw.go
  2. 7 15
      internal/layout/layout.go

+ 3 - 2
internal/editor/draw.go

@@ -9,6 +9,7 @@ import (
 	"strconv"
 	"github.com/gdamore/tcell/v3/color"
 	"slices"
+	"math"
 )
 
 func (m *Model) Draw() {
@@ -186,7 +187,7 @@ func (m *Model) DrawContainerTabs(c *layout.ContainerBuffers, rect layout.Rect)
 			style = style.Foreground(color.White)
 		}
 
-		tabStr := strconv.Itoa((activeTabIdx - i) * -1) + ": " + tab
+		tabStr := strconv.Itoa(int(math.Abs(float64((activeTabIdx - i))))) + ": " + tab
 
 		m.Screen.PutStrStyled(rect.X + length, rect.Y, tabStr, style)
 		length += len(tabStr) + 1
@@ -222,7 +223,7 @@ func (m *Model) DrawBuffer(buf *buffer.Buffer, isActive bool, rect layout.Rect)
 
 		lineNum := j + buf.TopLine
 		relLine := lineNum - curLine
-		nums := fmt.Sprintf("%4d ", relLine)
+		nums := fmt.Sprintf("%4d ", int(math.Abs(float64(relLine))))
 		r := []rune(nums + expandTabs(line))
 		if len(r) + 1 > rect.Width {
 			r = r[:rect.Width]

+ 7 - 15
internal/layout/layout.go

@@ -41,17 +41,6 @@ type ContainerBuffers struct {
 
 func (ContainerBuffers) isContainerNode() {}
 
-func (cb *ContainerBuffers) SelectBufferNumber(bufferNumber int) bool {
-    for idx, bufferIdx := range cb.Buffers {
-        if bufferIdx == bufferNumber {
-            cb.ActiveIdx = idx
-            return true
-        }
-    }
-
-    return false
-}
-
 type Container struct {
 	Children       [2]ContainerNode
 	Split          SplitType
@@ -285,10 +274,13 @@ func (c *Container) ActivateBufferIdx(target int) bool {
     for i, child := range c.Children {
         switch n := child.(type) {
         case ContainerBuffers:
-            if n.SelectBufferNumber(target) {
-                c.ActiveChildIdx = i
-                c.Children[i] = n
-                return true
+            for j, idx := range n.Buffers {
+                if idx == target {
+                    c.ActiveChildIdx = i
+                    n.ActiveIdx = j
+                    c.Children[i] = n
+                    return true
+                }
             }
         case Container:
             if n.ActivateBufferIdx(target) {