mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-24 09:47:19 +09:00
Added flag to introduce cursor starting positions
This commit is contained in:
@@ -8,6 +8,8 @@ import (
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
)
|
||||
@@ -85,10 +87,36 @@ func NewBuffer(txt []byte, path string) *Buffer {
|
||||
}
|
||||
|
||||
// Put the cursor at the first spot
|
||||
cursorStartX := 0
|
||||
cursorStartY := 0
|
||||
// If -cursor LINE,COL was passed, use start position LINE,COL
|
||||
if len(*flagLineColumn) > 0 {
|
||||
positions := strings.Split(*flagLineColumn, ",")
|
||||
if len(positions) == 2 {
|
||||
lineNum, errPos1 := strconv.Atoi(positions[0])
|
||||
colNum, errPos2 := strconv.Atoi(positions[1])
|
||||
if errPos1 == nil && errPos2 == nil {
|
||||
cursorStartX = colNum
|
||||
cursorStartY = lineNum - 1
|
||||
// Check to avoid line overflow
|
||||
if cursorStartY > b.NumLines {
|
||||
cursorStartY = b.NumLines - 1
|
||||
} else if cursorStartY < 0 {
|
||||
cursorStartY = 0
|
||||
}
|
||||
// Check to avoid column overflow
|
||||
if cursorStartX > len(b.Line(cursorStartY)) {
|
||||
cursorStartX = len(b.Line(cursorStartY))
|
||||
} else if cursorStartX < 0 {
|
||||
cursorStartX = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
b.Cursor = Cursor{
|
||||
Loc: Loc{
|
||||
X: 0,
|
||||
Y: 0,
|
||||
X: cursorStartX,
|
||||
Y: cursorStartY,
|
||||
},
|
||||
buf: b,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user