mirror of
https://github.com/Hopiu/micro.git
synced 2026-05-09 23:34:42 +00:00
Add horizontal splits
This commit is contained in:
parent
7e0286b621
commit
bcbef1c633
2 changed files with 41 additions and 10 deletions
|
|
@ -19,6 +19,7 @@ var commandActions = map[string]func([]string){
|
||||||
"Save": Save,
|
"Save": Save,
|
||||||
"Replace": Replace,
|
"Replace": Replace,
|
||||||
"VSplit": VSplit,
|
"VSplit": VSplit,
|
||||||
|
"HSplit": HSplit,
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitCommands initializes the default commands
|
// InitCommands initializes the default commands
|
||||||
|
|
@ -58,12 +59,16 @@ func DefaultCommands() map[string]string {
|
||||||
"save": "Save",
|
"save": "Save",
|
||||||
"replace": "Replace",
|
"replace": "Replace",
|
||||||
"vsplit": "VSplit",
|
"vsplit": "VSplit",
|
||||||
|
"hsplit": "HSplit",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func VSplit(args []string) {
|
func VSplit(args []string) {
|
||||||
CurView().VSplit()
|
CurView().VSplit()
|
||||||
}
|
}
|
||||||
|
func HSplit(args []string) {
|
||||||
|
CurView().HSplit()
|
||||||
|
}
|
||||||
|
|
||||||
// Set sets an option
|
// Set sets an option
|
||||||
func Set(args []string) {
|
func Set(args []string) {
|
||||||
|
|
|
||||||
|
|
@ -123,13 +123,13 @@ func NewViewWidthHeight(buf *Buffer, w, h int) *View {
|
||||||
func (v *View) Resize(w, h int) {
|
func (v *View) Resize(w, h int) {
|
||||||
// Always include 1 line for the command line at the bottom
|
// Always include 1 line for the command line at the bottom
|
||||||
h--
|
h--
|
||||||
if len(tabs) > 1 {
|
// if len(tabs) > 1 {
|
||||||
// Include one line for the tab bar at the top
|
// // Include one line for the tab bar at the top
|
||||||
h--
|
// h--
|
||||||
v.y = 1
|
// v.y = 1
|
||||||
} else {
|
// } else {
|
||||||
v.y = 0
|
// v.y = 0
|
||||||
}
|
// }
|
||||||
v.width = int(float32(w) * float32(v.widthPercent) / 100)
|
v.width = int(float32(w) * float32(v.widthPercent) / 100)
|
||||||
// We subtract 1 for the statusline
|
// We subtract 1 for the statusline
|
||||||
v.height = int(float32(h) * float32(v.heightPercent) / 100)
|
v.height = int(float32(h) * float32(v.heightPercent) / 100)
|
||||||
|
|
@ -218,12 +218,28 @@ func (v *View) ReOpen() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *View) HSplit() bool {
|
||||||
|
v.heightPercent /= 2
|
||||||
|
v.Resize(screen.Size())
|
||||||
|
|
||||||
|
newView := NewViewWidthHeight(NewBuffer([]byte{}, ""), v.widthPercent, v.heightPercent)
|
||||||
|
newView.TabNum = v.TabNum
|
||||||
|
newView.y = v.y + v.height + 1
|
||||||
|
newView.x = v.x
|
||||||
|
tab := tabs[v.TabNum]
|
||||||
|
tab.curView++
|
||||||
|
newView.Num = len(tab.views)
|
||||||
|
tab.views = append(tab.views, newView)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (v *View) VSplit() bool {
|
func (v *View) VSplit() bool {
|
||||||
v.widthPercent /= 2
|
v.widthPercent /= 2
|
||||||
v.Resize(screen.Size())
|
v.Resize(screen.Size())
|
||||||
|
|
||||||
newView := NewViewWidthHeight(NewBuffer([]byte{}, ""), v.widthPercent, v.heightPercent)
|
newView := NewViewWidthHeight(NewBuffer([]byte{}, ""), v.widthPercent, v.heightPercent)
|
||||||
newView.TabNum = v.TabNum
|
newView.TabNum = v.TabNum
|
||||||
|
newView.y = v.y
|
||||||
newView.x = v.x + v.width
|
newView.x = v.x + v.width
|
||||||
tab := tabs[v.TabNum]
|
tab := tabs[v.TabNum]
|
||||||
tab.curView++
|
tab.curView++
|
||||||
|
|
@ -497,12 +513,22 @@ func (v *View) DisplayView() {
|
||||||
v.lineNumOffset += 2
|
v.lineNumOffset += 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v.x != 0 {
|
||||||
|
// One space for the extra split divider
|
||||||
|
v.lineNumOffset++
|
||||||
|
}
|
||||||
|
|
||||||
for lineN := 0; lineN < v.height; lineN++ {
|
for lineN := 0; lineN < v.height; lineN++ {
|
||||||
x := v.x
|
x := v.x
|
||||||
|
if v.x != 0 {
|
||||||
|
// Draw the split divider
|
||||||
|
screen.SetContent(x, lineN+v.y, ' ', nil, defStyle.Reverse(true))
|
||||||
|
x++
|
||||||
|
}
|
||||||
// If the buffer is smaller than the view height
|
// If the buffer is smaller than the view height
|
||||||
if lineN+v.Topline >= v.Buf.NumLines {
|
if lineN+v.Topline >= v.Buf.NumLines {
|
||||||
// We have to clear all this space
|
// We have to clear all this space
|
||||||
for i := v.x; i < v.width; i++ {
|
for i := x; i < v.x+v.width; i++ {
|
||||||
screen.SetContent(i, lineN+v.y, ' ', nil, defStyle)
|
screen.SetContent(i, lineN+v.y, ' ', nil, defStyle)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -642,12 +668,12 @@ func (v *View) DisplayView() {
|
||||||
}
|
}
|
||||||
} else if runewidth.RuneWidth(ch) > 1 {
|
} else if runewidth.RuneWidth(ch) > 1 {
|
||||||
if x-v.leftCol >= v.lineNumOffset {
|
if x-v.leftCol >= v.lineNumOffset {
|
||||||
screen.SetContent(x-v.leftCol, lineN, ch, nil, lineStyle)
|
screen.SetContent(x-v.leftCol, lineN+v.y, ch, nil, lineStyle)
|
||||||
}
|
}
|
||||||
for i := 0; i < runewidth.RuneWidth(ch)-1; i++ {
|
for i := 0; i < runewidth.RuneWidth(ch)-1; i++ {
|
||||||
x++
|
x++
|
||||||
if x-v.leftCol >= v.lineNumOffset {
|
if x-v.leftCol >= v.lineNumOffset {
|
||||||
screen.SetContent(x-v.leftCol, lineN, ' ', nil, lineStyle)
|
screen.SetContent(x-v.leftCol, lineN+v.y, ' ', nil, lineStyle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue