mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-29 22:27:13 +09:00
Split improvements
This commit is contained in:
@@ -219,12 +219,14 @@ func (h *BufHandler) vsplit(buf *buffer.Buffer) {
|
|||||||
e.splitID = MainTab.GetNode(h.splitID).VSplit(h.Buf.Settings["splitright"].(bool))
|
e.splitID = MainTab.GetNode(h.splitID).VSplit(h.Buf.Settings["splitright"].(bool))
|
||||||
MainTab.Panes = append(MainTab.Panes, e)
|
MainTab.Panes = append(MainTab.Panes, e)
|
||||||
MainTab.Resize()
|
MainTab.Resize()
|
||||||
|
MainTab.SetActive(len(MainTab.Panes) - 1)
|
||||||
}
|
}
|
||||||
func (h *BufHandler) hsplit(buf *buffer.Buffer) {
|
func (h *BufHandler) hsplit(buf *buffer.Buffer) {
|
||||||
e := NewBufEditPane(0, 0, 0, 0, buf)
|
e := NewBufEditPane(0, 0, 0, 0, buf)
|
||||||
e.splitID = MainTab.GetNode(h.splitID).HSplit(h.Buf.Settings["splitbottom"].(bool))
|
e.splitID = MainTab.GetNode(h.splitID).HSplit(h.Buf.Settings["splitbottom"].(bool))
|
||||||
MainTab.Panes = append(MainTab.Panes, e)
|
MainTab.Panes = append(MainTab.Panes, e)
|
||||||
MainTab.Resize()
|
MainTab.Resize()
|
||||||
|
MainTab.SetActive(len(MainTab.Panes) - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BufKeyActions contains the list of all possible key actions the bufhandler could execute
|
// BufKeyActions contains the list of all possible key actions the bufhandler could execute
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package action
|
package action
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/zyedidia/micro/cmd/micro/views"
|
"github.com/zyedidia/micro/cmd/micro/views"
|
||||||
"github.com/zyedidia/tcell"
|
"github.com/zyedidia/tcell"
|
||||||
)
|
)
|
||||||
@@ -16,12 +14,40 @@ type TabPane struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TabPane) HandleEvent(event tcell.Event) {
|
func (t *TabPane) HandleEvent(event tcell.Event) {
|
||||||
|
switch e := event.(type) {
|
||||||
|
case *tcell.EventMouse:
|
||||||
|
switch e.Buttons() {
|
||||||
|
case tcell.Button1:
|
||||||
|
mx, my := e.Position()
|
||||||
|
|
||||||
|
for i, p := range t.Panes {
|
||||||
|
v := p.GetView()
|
||||||
|
inpane := mx >= v.X && mx < v.X+v.Width && my >= v.Y && my < v.Y+v.Height
|
||||||
|
if inpane {
|
||||||
|
t.active = i
|
||||||
|
p.SetActive(true)
|
||||||
|
} else {
|
||||||
|
p.SetActive(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
t.Panes[t.active].HandleEvent(event)
|
t.Panes[t.active].HandleEvent(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *TabPane) SetActive(i int) {
|
||||||
|
t.active = i
|
||||||
|
for j, p := range t.Panes {
|
||||||
|
if j == i {
|
||||||
|
p.SetActive(true)
|
||||||
|
} else {
|
||||||
|
p.SetActive(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (t *TabPane) Resize() {
|
func (t *TabPane) Resize() {
|
||||||
for _, p := range t.Panes {
|
for _, p := range t.Panes {
|
||||||
log.Println(p.splitID)
|
|
||||||
v := t.GetNode(p.splitID).GetView()
|
v := t.GetNode(p.splitID).GetView()
|
||||||
pv := p.GetView()
|
pv := p.GetView()
|
||||||
pv.X, pv.Y = v.X, v.Y
|
pv.X, pv.Y = v.X, v.Y
|
||||||
|
|||||||
@@ -81,9 +81,10 @@ func (i *InfoWindow) Resize(w, h int) {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
func (i *InfoWindow) Relocate() bool { return false }
|
func (i *InfoWindow) Relocate() bool { return false }
|
||||||
func (i *InfoWindow) GetView() *View { return i.View }
|
func (i *InfoWindow) GetView() *View { return i.View }
|
||||||
func (i *InfoWindow) SetView(v *View) {}
|
func (i *InfoWindow) SetView(v *View) {}
|
||||||
|
func (i *InfoWindow) SetActive(b bool) {}
|
||||||
|
|
||||||
func (i *InfoWindow) GetMouseLoc(vloc buffer.Loc) buffer.Loc {
|
func (i *InfoWindow) GetMouseLoc(vloc buffer.Loc) buffer.Loc {
|
||||||
c := i.Buffer.GetActiveCursor()
|
c := i.Buffer.GetActiveCursor()
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package display
|
package display
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
@@ -31,6 +30,7 @@ type Window interface {
|
|||||||
SetView(v *View)
|
SetView(v *View)
|
||||||
GetMouseLoc(vloc buffer.Loc) buffer.Loc
|
GetMouseLoc(vloc buffer.Loc) buffer.Loc
|
||||||
Resize(w, h int)
|
Resize(w, h int)
|
||||||
|
SetActive(b bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The BufWindow provides a way of displaying a certain section
|
// The BufWindow provides a way of displaying a certain section
|
||||||
@@ -41,6 +41,8 @@ type BufWindow struct {
|
|||||||
// Buffer being shown in this window
|
// Buffer being shown in this window
|
||||||
Buf *buffer.Buffer
|
Buf *buffer.Buffer
|
||||||
|
|
||||||
|
active bool
|
||||||
|
|
||||||
sline *StatusLine
|
sline *StatusLine
|
||||||
|
|
||||||
lineHeight []int
|
lineHeight []int
|
||||||
@@ -53,6 +55,7 @@ func NewBufWindow(x, y, width, height int, buf *buffer.Buffer) *BufWindow {
|
|||||||
w.View = new(View)
|
w.View = new(View)
|
||||||
w.X, w.Y, w.Width, w.Height, w.Buf = x, y, width, height, buf
|
w.X, w.Y, w.Width, w.Height, w.Buf = x, y, width, height, buf
|
||||||
w.lineHeight = make([]int, height)
|
w.lineHeight = make([]int, height)
|
||||||
|
w.active = true
|
||||||
|
|
||||||
w.sline = NewStatusLine(w)
|
w.sline = NewStatusLine(w)
|
||||||
|
|
||||||
@@ -72,6 +75,10 @@ func (w *BufWindow) Resize(width, height int) {
|
|||||||
w.lineHeight = make([]int, height)
|
w.lineHeight = make([]int, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *BufWindow) SetActive(b bool) {
|
||||||
|
w.active = b
|
||||||
|
}
|
||||||
|
|
||||||
func (w *BufWindow) getStartInfo(n, lineN int) ([]byte, int, int, *tcell.Style) {
|
func (w *BufWindow) getStartInfo(n, lineN int) ([]byte, int, int, *tcell.Style) {
|
||||||
tabsize := util.IntOpt(w.Buf.Settings["tabsize"])
|
tabsize := util.IntOpt(w.Buf.Settings["tabsize"])
|
||||||
width := 0
|
width := 0
|
||||||
@@ -226,11 +233,11 @@ func (w *BufWindow) GetMouseLoc(svloc buffer.Loc) buffer.Loc {
|
|||||||
|
|
||||||
totalwidth := w.StartCol - nColsBeforeStart
|
totalwidth := w.StartCol - nColsBeforeStart
|
||||||
|
|
||||||
if svloc.X <= vloc.X && vloc.Y == svloc.Y {
|
if svloc.X <= vloc.X+w.X && vloc.Y+w.Y == svloc.Y {
|
||||||
return bloc
|
return bloc
|
||||||
}
|
}
|
||||||
for len(line) > 0 {
|
for len(line) > 0 {
|
||||||
if vloc.X == svloc.X && vloc.Y == svloc.Y {
|
if vloc.X+w.X == svloc.X && vloc.Y+w.Y == svloc.Y {
|
||||||
return bloc
|
return bloc
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,7 +256,7 @@ func (w *BufWindow) GetMouseLoc(svloc buffer.Loc) buffer.Loc {
|
|||||||
// Draw any extra characters either spaces for tabs or @ for incomplete wide runes
|
// Draw any extra characters either spaces for tabs or @ for incomplete wide runes
|
||||||
if width > 1 {
|
if width > 1 {
|
||||||
for i := 1; i < width; i++ {
|
for i := 1; i < width; i++ {
|
||||||
if vloc.X == svloc.X && vloc.Y == svloc.Y {
|
if vloc.X+w.X == svloc.X && vloc.Y+w.Y == svloc.Y {
|
||||||
return bloc
|
return bloc
|
||||||
}
|
}
|
||||||
draw()
|
draw()
|
||||||
@@ -276,7 +283,7 @@ func (w *BufWindow) GetMouseLoc(svloc buffer.Loc) buffer.Loc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if vloc.Y == svloc.Y {
|
if vloc.Y+w.Y == svloc.Y {
|
||||||
return bloc
|
return bloc
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,7 +294,7 @@ func (w *BufWindow) GetMouseLoc(svloc buffer.Loc) buffer.Loc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer.Loc{X: -1, Y: -1}
|
return buffer.Loc{}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
@@ -324,11 +331,13 @@ func (w *BufWindow) getStyle(style tcell.Style, bloc buffer.Loc, r rune) (tcell.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *BufWindow) showCursor(x, y int, main bool) {
|
func (w *BufWindow) showCursor(x, y int, main bool) {
|
||||||
if main {
|
if w.active {
|
||||||
screen.Screen.ShowCursor(x, y)
|
if main {
|
||||||
} else {
|
screen.Screen.ShowCursor(x, y)
|
||||||
r, _, _, _ := screen.Screen.GetContent(x, y)
|
} else {
|
||||||
screen.Screen.SetContent(x, y, r, nil, config.DefStyle.Reverse(true))
|
r, _, _, _ := screen.Screen.GetContent(x, y)
|
||||||
|
screen.Screen.SetContent(x, y, r, nil, config.DefStyle.Reverse(true))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,7 +394,7 @@ func (w *BufWindow) displayBuffer() {
|
|||||||
if b.Settings["ruler"].(bool) {
|
if b.Settings["ruler"].(bool) {
|
||||||
s := lineNumStyle
|
s := lineNumStyle
|
||||||
for _, c := range cursors {
|
for _, c := range cursors {
|
||||||
if bloc.Y == c.Y {
|
if bloc.Y == c.Y && w.active {
|
||||||
s = curNumStyle
|
s = curNumStyle
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -415,7 +424,7 @@ func (w *BufWindow) displayBuffer() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.Settings["cursorline"].(bool) &&
|
if b.Settings["cursorline"].(bool) && w.active &&
|
||||||
!c.HasSelection() && c.Y == bloc.Y {
|
!c.HasSelection() && c.Y == bloc.Y {
|
||||||
if s, ok := config.Colorscheme["cursor-line"]; ok {
|
if s, ok := config.Colorscheme["cursor-line"]; ok {
|
||||||
fg, _, _ := s.Decompose()
|
fg, _, _ := s.Decompose()
|
||||||
@@ -438,7 +447,6 @@ func (w *BufWindow) displayBuffer() {
|
|||||||
nColsBeforeStart--
|
nColsBeforeStart--
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println(len(w.lineHeight), vloc.Y)
|
|
||||||
w.lineHeight[vloc.Y] = bloc.Y
|
w.lineHeight[vloc.Y] = bloc.Y
|
||||||
|
|
||||||
totalwidth := w.StartCol - nColsBeforeStart
|
totalwidth := w.StartCol - nColsBeforeStart
|
||||||
@@ -489,7 +497,7 @@ func (w *BufWindow) displayBuffer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cursors {
|
for _, c := range cursors {
|
||||||
if b.Settings["cursorline"].(bool) &&
|
if b.Settings["cursorline"].(bool) && w.active &&
|
||||||
!c.HasSelection() && c.Y == bloc.Y {
|
!c.HasSelection() && c.Y == bloc.Y {
|
||||||
style := config.DefStyle
|
style := config.DefStyle
|
||||||
if s, ok := config.Colorscheme["cursor-line"]; ok {
|
if s, ok := config.Colorscheme["cursor-line"]; ok {
|
||||||
@@ -497,7 +505,7 @@ func (w *BufWindow) displayBuffer() {
|
|||||||
style = style.Background(fg)
|
style = style.Background(fg)
|
||||||
}
|
}
|
||||||
for i := vloc.X; i < w.Width; i++ {
|
for i := vloc.X; i < w.Width; i++ {
|
||||||
screen.Screen.SetContent(i, vloc.Y, ' ', nil, style)
|
screen.Screen.SetContent(i+w.X, vloc.Y+w.Y, ' ', nil, style)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ func main() {
|
|||||||
if action.InfoBar.HasPrompt {
|
if action.InfoBar.HasPrompt {
|
||||||
action.InfoBar.HandleEvent(event)
|
action.InfoBar.HandleEvent(event)
|
||||||
} else {
|
} else {
|
||||||
action.MainTab.Panes[0].HandleEvent(event)
|
action.MainTab.HandleEvent(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user