]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/view.go
Fix: mouse clicking with softwrap
[micro.git] / cmd / micro / view.go
index f10cc8ffb0022f8b10bc5724fd14e6620ebeb18b..269acd43c0862991c1abe3438267e942c1e169bf 100644 (file)
@@ -1,7 +1,7 @@
 package main
 
 import (
-       "io/ioutil"
+       "os"
        "strconv"
        "strings"
        "time"
@@ -242,13 +242,14 @@ func (v *View) OpenBuffer(buf *Buffer) {
 func (v *View) Open(filename string) {
        home, _ := homedir.Dir()
        filename = strings.Replace(filename, "~", home, 1)
-       file, err := ioutil.ReadFile(filename)
+       file, err := os.Open(filename)
+       defer file.Close()
 
        var buf *Buffer
        if err != nil {
                messenger.Message(err.Error())
                // File does not exist -- create an empty buffer with that name
-               buf = NewBuffer([]byte{}, filename)
+               buf = NewBuffer(strings.NewReader(""), filename)
        } else {
                buf = NewBuffer(file, filename)
        }
@@ -417,9 +418,6 @@ func (v *View) MoveToMouseClick(x, y int) {
                v.ScrollDown(1)
                y = v.Height + v.Topline - 1
        }
-       if y >= v.Buf.NumLines {
-               y = v.Buf.NumLines - 1
-       }
        if y < 0 {
                y = 0
        }
@@ -630,7 +628,7 @@ func (v *View) openHelp(helpPage string) {
        if data, err := FindRuntimeFile(RTHelp, helpPage).Data(); err != nil {
                TermMessage("Unable to load help text", helpPage, "\n", err)
        } else {
-               helpBuffer := NewBuffer(data, helpPage+".md")
+               helpBuffer := NewBuffer(strings.NewReader(string(data)), helpPage+".md")
                helpBuffer.name = "Help"
 
                if v.Type == vtHelp {
@@ -888,6 +886,7 @@ func (v *View) DisplayView() {
                                                v.drawCell(screenX-v.leftCol, screenY, ' ', nil, lineStyle)
                                        }
                                }
+                               strWidth += remainder
                        } else if runewidth.RuneWidth(ch) > 1 {
                                if screenX-v.x-v.leftCol >= v.lineNumOffset {
                                        v.drawCell(screenX, screenY, ch, nil, lineStyle)
@@ -898,15 +897,16 @@ func (v *View) DisplayView() {
                                                v.drawCell(screenX-v.leftCol, screenY, '<', nil, lineStyle)
                                        }
                                }
+                               strWidth += StringWidth(string(ch), tabSize)
                        } else {
                                if screenX-v.x-v.leftCol >= v.lineNumOffset {
                                        v.drawCell(screenX-v.leftCol, screenY, ch, nil, lineStyle)
                                }
+                               strWidth += StringWidth(string(ch), tabSize)
                        }
                        charNum = charNum.Move(1, v.Buf)
                        screenX++
                        colN++
-                       strWidth += StringWidth(string(ch), tabSize)
                }
                // Here we are at a newline