]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/view.go
Fix some issues with unicode handling
[micro.git] / cmd / micro / view.go
index af40fb95a4ad6d4063188297d39aa31132a23b7e..4080fa1642dd2f109cf73b3fae3259b828942c1f 100644 (file)
@@ -1,14 +1,11 @@
 package main
 
 import (
-       "reflect"
-       "runtime"
        "strconv"
        "strings"
        "time"
 
        "github.com/mattn/go-runewidth"
-       "github.com/yuin/gopher-lua"
        "github.com/zyedidia/tcell"
 )
 
@@ -173,7 +170,7 @@ func (v *View) CanClose(msg string) bool {
                        if strings.ToLower(quit) == "yes" || strings.ToLower(quit) == "y" {
                                return true
                        } else if strings.ToLower(quit) == "save" || strings.ToLower(quit) == "s" {
-                               v.Save()
+                               v.Save(true)
                                return true
                        }
                }
@@ -333,28 +330,7 @@ func (v *View) HandleEvent(event tcell.Event) {
                                        if e.Modifiers() == key.modifiers {
                                                relocate = false
                                                for _, action := range actions {
-                                                       executeAction := true
-                                                       funcName := strings.Split(runtime.FuncForPC(reflect.ValueOf(action).Pointer()).Name(), ".")
-                                                       for _, pl := range loadedPlugins {
-                                                               ret, err := Call(pl+".pre"+funcName[len(funcName)-1], nil)
-                                                               if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") {
-                                                                       TermMessage(err)
-                                                                       continue
-                                                               }
-                                                               if ret == lua.LFalse {
-                                                                       executeAction = false
-                                                               }
-                                                       }
-                                                       if executeAction {
-                                                               relocate = action(v) || relocate
-                                                               for _, pl := range loadedPlugins {
-                                                                       _, err := Call(pl+".on"+funcName[len(funcName)-1], nil)
-                                                                       if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") {
-                                                                               TermMessage(err)
-                                                                               continue
-                                                                       }
-                                                               }
-                                                       }
+                                                       relocate = action(v, true) || relocate
                                                }
                                        }
                                }
@@ -488,6 +464,20 @@ func (v *View) ClearAllGutterMessages() {
        }
 }
 
+// Opens the given help page in a new horizontal split
+func (v *View) openHelp(helpPage string) {
+       if v.Help {
+               helpBuffer := NewBuffer([]byte(helpPages[helpPage]), helpPage+".md")
+               helpBuffer.Name = "Help"
+               v.OpenBuffer(helpBuffer)
+       } else {
+               helpBuffer := NewBuffer([]byte(helpPages[helpPage]), helpPage+".md")
+               helpBuffer.Name = "Help"
+               v.HSplit(helpBuffer)
+               CurView().Help = true
+       }
+}
+
 func (v *View) drawCell(x, y int, ch rune, combc []rune, style tcell.Style) {
        if x >= v.x && x < v.x+v.width && y >= v.y && y < v.y+v.height {
                screen.SetContent(x, y, ch, combc, style)
@@ -609,6 +599,11 @@ func (v *View) DisplayView() {
                        if style, ok := colorscheme["line-number"]; ok {
                                lineNumStyle = style
                        }
+                       if style, ok := colorscheme["current-line-number"]; ok {
+                               if curLineN == v.Cursor.Y {
+                                       lineNumStyle = style
+                               }
+                       }
 
                        lineNum := strconv.Itoa(curLineN + 1)
 
@@ -629,7 +624,8 @@ func (v *View) DisplayView() {
                }
 
                // Now we actually draw the line
-               for colN, ch := range line {
+               colN := 0
+               for _, ch := range line {
                        lineStyle := defStyle
 
                        if settings["syntax"].(bool) {
@@ -714,6 +710,7 @@ func (v *View) DisplayView() {
                        }
                        charNum = charNum.Move(1, v.Buf)
                        screenX++
+                       colN++
                }
                // Here we are at a newline