mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-30 14:47:16 +09:00
Add a scroll bar option
The option is `scrollbar` and is off by default. The scroll bar is not interactive (you can't click and drag it) but this will likely be fixed in the future. Ref #869
This commit is contained in:
@@ -476,6 +476,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for event != nil {
|
for event != nil {
|
||||||
|
didAction := false
|
||||||
|
|
||||||
switch e := event.(type) {
|
switch e := event.(type) {
|
||||||
case *tcell.EventResize:
|
case *tcell.EventResize:
|
||||||
for _, t := range tabs {
|
for _, t := range tabs {
|
||||||
@@ -505,24 +507,36 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if e.Buttons() == tcell.WheelUp || e.Buttons() == tcell.WheelDown {
|
||||||
|
var view *View
|
||||||
|
x, y := e.Position()
|
||||||
|
for _, v := range tabs[curTab].views {
|
||||||
|
if x >= v.x && x < v.x+v.Width && y >= v.y && y < v.y+v.Height {
|
||||||
|
view = tabs[curTab].views[v.Num]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
view.HandleEvent(e)
|
||||||
|
didAction = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function checks the mouse event for the possibility of changing the current tab
|
if !didAction {
|
||||||
// If the tab was changed it returns true
|
// This function checks the mouse event for the possibility of changing the current tab
|
||||||
if TabbarHandleMouseEvent(event) {
|
// If the tab was changed it returns true
|
||||||
break
|
if TabbarHandleMouseEvent(event) {
|
||||||
}
|
break
|
||||||
|
}
|
||||||
|
|
||||||
if searching {
|
if searching {
|
||||||
// Since searching is done in real time, we need to redraw every time
|
// Since searching is done in real time, we need to redraw every time
|
||||||
// there is a new event in the search bar so we need a special function
|
// there is a new event in the search bar so we need a special function
|
||||||
// to run instead of the standard HandleEvent.
|
// to run instead of the standard HandleEvent.
|
||||||
HandleSearchEvent(event, CurView())
|
HandleSearchEvent(event, CurView())
|
||||||
} else {
|
} else {
|
||||||
// Send it to the view
|
// Send it to the view
|
||||||
CurView().HandleEvent(event)
|
CurView().HandleEvent(event)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
18
cmd/micro/scrollbar.go
Normal file
18
cmd/micro/scrollbar.go
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
type ScrollBar struct {
|
||||||
|
view *View
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sb *ScrollBar) Display() {
|
||||||
|
style := defStyle.Reverse(true)
|
||||||
|
screen.SetContent(sb.view.x+sb.view.Width-1, sb.view.y+sb.Pos(), ' ', nil, style)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sb *ScrollBar) Pos() int {
|
||||||
|
numlines := sb.view.Buf.NumLines
|
||||||
|
h := sb.view.Height
|
||||||
|
filepercent := float32(sb.view.Topline) / float32(numlines)
|
||||||
|
|
||||||
|
return int(filepercent * float32(h))
|
||||||
|
}
|
||||||
@@ -213,6 +213,7 @@ func DefaultGlobalSettings() map[string]interface{} {
|
|||||||
"savecursor": false,
|
"savecursor": false,
|
||||||
"savehistory": true,
|
"savehistory": true,
|
||||||
"saveundo": false,
|
"saveundo": false,
|
||||||
|
"scrollbar": false,
|
||||||
"scrollmargin": float64(3),
|
"scrollmargin": float64(3),
|
||||||
"scrollspeed": float64(2),
|
"scrollspeed": float64(2),
|
||||||
"softwrap": false,
|
"softwrap": false,
|
||||||
@@ -248,6 +249,7 @@ func DefaultLocalSettings() map[string]interface{} {
|
|||||||
"ruler": true,
|
"ruler": true,
|
||||||
"savecursor": false,
|
"savecursor": false,
|
||||||
"saveundo": false,
|
"saveundo": false,
|
||||||
|
"scrollbar": false,
|
||||||
"scrollmargin": float64(3),
|
"scrollmargin": float64(3),
|
||||||
"scrollspeed": float64(2),
|
"scrollspeed": float64(2),
|
||||||
"softwrap": false,
|
"softwrap": false,
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ type View struct {
|
|||||||
// The buffer
|
// The buffer
|
||||||
Buf *Buffer
|
Buf *Buffer
|
||||||
// The statusline
|
// The statusline
|
||||||
sline Statusline
|
sline *Statusline
|
||||||
|
|
||||||
// Since tcell doesn't differentiate between a mouse release event
|
// Since tcell doesn't differentiate between a mouse release event
|
||||||
// and a mouse move event with no keys pressed, we need to keep
|
// and a mouse move event with no keys pressed, we need to keep
|
||||||
@@ -92,6 +92,8 @@ type View struct {
|
|||||||
cellview *CellView
|
cellview *CellView
|
||||||
|
|
||||||
splitNode *LeafNode
|
splitNode *LeafNode
|
||||||
|
|
||||||
|
scrollbar *ScrollBar
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewView returns a new fullscreen view
|
// NewView returns a new fullscreen view
|
||||||
@@ -117,7 +119,11 @@ func NewViewWidthHeight(buf *Buffer, w, h int) *View {
|
|||||||
|
|
||||||
v.messages = make(map[string][]GutterMessage)
|
v.messages = make(map[string][]GutterMessage)
|
||||||
|
|
||||||
v.sline = Statusline{
|
v.sline = &Statusline{
|
||||||
|
view: v,
|
||||||
|
}
|
||||||
|
|
||||||
|
v.scrollbar = &ScrollBar{
|
||||||
view: v,
|
view: v,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1008,6 +1014,11 @@ func (v *View) Display() {
|
|||||||
screen.HideCursor()
|
screen.HideCursor()
|
||||||
}
|
}
|
||||||
_, screenH := screen.Size()
|
_, screenH := screen.Size()
|
||||||
|
|
||||||
|
if v.Buf.Settings["scrollbar"].(bool) {
|
||||||
|
v.scrollbar.Display()
|
||||||
|
}
|
||||||
|
|
||||||
if v.Buf.Settings["statusline"].(bool) {
|
if v.Buf.Settings["statusline"].(bool) {
|
||||||
v.sline.Display()
|
v.sline.Display()
|
||||||
} else if (v.y + v.Height) != screenH-1 {
|
} else if (v.y + v.Height) != screenH-1 {
|
||||||
|
|||||||
@@ -146,6 +146,10 @@ Here are the options that you can set:
|
|||||||
|
|
||||||
default value: `off`
|
default value: `off`
|
||||||
|
|
||||||
|
* `scrollbar`: display a scroll bar
|
||||||
|
|
||||||
|
default value: `off`
|
||||||
|
|
||||||
* `scrollmargin`: amount of lines you would like to see above and below the
|
* `scrollmargin`: amount of lines you would like to see above and below the
|
||||||
cursor.
|
cursor.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user