]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/view.go
Merge pull request #112 from onodera-punpun/customizable_scrolling
[micro.git] / cmd / micro / view.go
index 1a685407f87f66651e88a981b9a861a6db545ab8..cd6353d109ac85168cf0d5fdb3afe313b5a31ffa 100644 (file)
@@ -110,7 +110,11 @@ func (v *View) Resize(w, h int) {
        h--
        v.width = int(float32(w) * float32(v.widthPercent) / 100)
        // We subtract 1 for the statusline
-       v.height = int(float32(h)*float32(v.heightPercent)/100) - 1
+       v.height = int(float32(h) * float32(v.heightPercent) / 100)
+       if settings["statusline"].(bool) {
+               // Make room for the status line if it is enabled
+               v.height--
+       }
 }
 
 // ScrollUp scrolls the view up n lines (if possible)
@@ -138,7 +142,7 @@ func (v *View) ScrollDown(n int) {
 // causing them to lose the unsaved changes
 // The message is what to print after saying "You have unsaved changes. "
 func (v *View) CanClose(msg string) bool {
-       if v.Buf.IsDirty() {
+       if v.Buf.IsModified {
                quit, canceled := messenger.Prompt("You have unsaved changes. " + msg)
                if !canceled {
                        if strings.ToLower(quit) == "yes" || strings.ToLower(quit) == "y" {
@@ -362,13 +366,15 @@ func (v *View) HandleEvent(event tcell.Event) {
                        // every time the user moves the cursor
                        relocate = false
                case tcell.WheelUp:
-                       // Scroll up two lines
-                       v.ScrollUp(2)
+                       // Scroll up
+                       scrollSpeed := int(settings["scrollspeed"].(float64))
+                       v.ScrollUp(scrollSpeed)
                        // We don't want to relocate if the user is scrolling
                        relocate = false
                case tcell.WheelDown:
-                       // Scroll down two lines
-                       v.ScrollDown(2)
+                       // Scroll down
+                       scrollSpeed := int(settings["scrollspeed"].(float64))
+                       v.ScrollDown(scrollSpeed)
                        // We don't want to relocate if the user is scrolling
                        relocate = false
                }
@@ -406,6 +412,13 @@ func (v *View) ClearGutterMessages(section string) {
        v.messages[section] = []GutterMessage{}
 }
 
+// ClearAllGutterMessages clears all the gutter messages
+func (v *View) ClearAllGutterMessages() {
+       for k := range v.messages {
+               v.messages[k] = []GutterMessage{}
+       }
+}
+
 // DisplayView renders the view to the screen
 func (v *View) DisplayView() {
        // The character number of the character in the top left of the screen
@@ -574,5 +587,7 @@ func (v *View) DisplayView() {
 func (v *View) Display() {
        v.DisplayView()
        v.Cursor.Display()
-       v.sline.Display()
+       if settings["statusline"].(bool) {
+               v.sline.Display()
+       }
 }