]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/view.go
Use the new and updated version of tcell
[micro.git] / cmd / micro / view.go
index f44ee174f51c4336b9a02a289a5c18120c346ee4..078177b318d187b7ebc4cb547f631a7117980ea2 100644 (file)
@@ -273,13 +273,15 @@ func (v *View) HandleEvent(event tcell.Event) {
                        v.Cursor.Right()
                } else {
                        for key, action := range bindings {
-                               if e.Key() == key {
-                                       relocate = action(v)
-                                       for _, pl := range loadedPlugins {
-                                               funcName := strings.Split(runtime.FuncForPC(reflect.ValueOf(action).Pointer()).Name(), ".")
-                                               err := Call(pl + "_on" + funcName[len(funcName)-1])
-                                               if err != nil {
-                                                       TermMessage(err)
+                               if e.Key() == key.keyCode {
+                                       if e.Modifiers() == key.modifiers {
+                                               relocate = action(v)
+                                               for _, pl := range loadedPlugins {
+                                                       funcName := strings.Split(runtime.FuncForPC(reflect.ValueOf(action).Pointer()).Name(), ".")
+                                                       err := Call(pl + "_on" + funcName[len(funcName)-1])
+                                                       if err != nil {
+                                                               TermMessage(err)
+                                                       }
                                                }
                                        }
                                }
@@ -298,13 +300,15 @@ func (v *View) HandleEvent(event tcell.Event) {
                x, y := e.Position()
                x -= v.lineNumOffset - v.leftCol
                y += v.Topline
+               // Don't relocate for mouse events
+               relocate = false
 
                button := e.Buttons()
 
                switch button {
                case tcell.Button1:
                        // Left click
-                       if v.mouseReleased && !e.HasMotion() {
+                       if v.mouseReleased {
                                v.MoveToMouseClick(x, y)
                                if time.Since(v.lastClickTime)/time.Millisecond < doubleClickThreshold {
                                        if v.doubleClick {
@@ -362,19 +366,14 @@ func (v *View) HandleEvent(event tcell.Event) {
                                }
                                v.mouseReleased = true
                        }
-                       // We don't want to relocate because otherwise the view will be relocated
-                       // every time the user moves the cursor
-                       relocate = false
                case tcell.WheelUp:
-                       // Scroll up two lines
-                       v.ScrollUp(2)
-                       // We don't want to relocate if the user is scrolling
-                       relocate = false
+                       // Scroll up
+                       scrollSpeed := int(settings["scrollSpeed"].(float64))
+                       v.ScrollUp(scrollSpeed)
                case tcell.WheelDown:
-                       // Scroll down two lines
-                       v.ScrollDown(2)
-                       // We don't want to relocate if the user is scrolling
-                       relocate = false
+                       // Scroll down
+                       scrollSpeed := int(settings["scrollSpeed"].(float64))
+                       v.ScrollDown(scrollSpeed)
                }
        }
 
@@ -545,7 +544,22 @@ func (v *View) DisplayView() {
                        }
 
                        if ch == '\t' {
-                               screen.SetContent(x+tabchars, lineN, ' ', nil, lineStyle)
+                               lineIndentStyle := defStyle
+                               if style, ok := colorscheme["indent-char"]; ok {
+                                       lineIndentStyle = style
+                               }
+                               if v.Cursor.HasSelection() &&
+                                       (charNum >= v.Cursor.curSelection[0] && charNum < v.Cursor.curSelection[1] ||
+                                               charNum < v.Cursor.curSelection[0] && charNum >= v.Cursor.curSelection[1]) {
+
+                                       lineIndentStyle = tcell.StyleDefault.Reverse(true)
+
+                                       if style, ok := colorscheme["selection"]; ok {
+                                               lineIndentStyle = style
+                                       }
+                               }
+                               indentChar := []rune(settings["indentchar"].(string))
+                               screen.SetContent(x-v.leftCol+tabchars, lineN, indentChar[0], nil, lineIndentStyle)
                                tabSize := int(settings["tabsize"].(float64))
                                for i := 0; i < tabSize-1; i++ {
                                        tabchars++