"strings"
"time"
- "github.com/gdamore/tcell"
+ "github.com/zyedidia/tcell"
)
// The View struct stores information about a view into a buffer.
// The eventhandler for undo/redo
eh *EventHandler
+ messages []GutterMessage
+
// The buffer
buf *Buffer
// The statusline
if strings.ToLower(quit) == "yes" || strings.ToLower(quit) == "y" {
return true
} else if strings.ToLower(quit) == "save" || strings.ToLower(quit) == "s" {
- Save(v)
+ v.Save()
return true
}
}
case tcell.Button1:
// Left click
origX, origY := v.cursor.x, v.cursor.y
- v.MoveToMouseClick(x, y)
- if v.mouseReleased {
+ if v.mouseReleased && !e.HasMotion() {
+ v.MoveToMouseClick(x, y)
if (time.Since(v.lastClickTime)/time.Millisecond < doubleClickThreshold) &&
(origX == v.cursor.x && origY == v.cursor.y) {
if v.doubleClick {
v.cursor.curSelection[0] = loc
v.cursor.curSelection[1] = loc
}
- } else {
+ v.mouseReleased = false
+ } else if !v.mouseReleased {
+ v.MoveToMouseClick(x, y)
if v.tripleClick {
v.cursor.AddLineToSelection()
} else if v.doubleClick {
v.cursor.curSelection[1] = v.cursor.Loc()
}
}
- v.mouseReleased = false
case tcell.ButtonNone:
// Mouse event with no click
if !v.mouseReleased {
if relocate {
v.Relocate()
}
- if settings.Syntax {
+ if settings["syntax"].(bool) {
v.matches = Match(v)
}
}
+// GutterMessage creates a message in this view's gutter
+func (v *View) GutterMessage(lineN int, msg string, kind int) {
+ gutterMsg := GutterMessage{
+ lineNum: lineN,
+ msg: msg,
+ kind: kind,
+ }
+ for _, gmsg := range v.messages {
+ if gmsg.lineNum == lineN {
+ return
+ }
+ }
+ v.messages = append(v.messages, gutterMsg)
+}
+
// DisplayView renders the view to the screen
func (v *View) DisplayView() {
// The character number of the character in the top left of the screen
// We are going to have to offset by that amount
maxLineLength := len(strconv.Itoa(len(v.buf.lines)))
// + 1 for the little space after the line number
- if settings.Ruler == true {
+ if settings["ruler"] == true {
v.lineNumOffset = maxLineLength + 1
} else {
v.lineNumOffset = 0
}
var highlightStyle tcell.Style
+ if len(v.messages) > 0 {
+ v.lineNumOffset += 2
+ }
+
for lineN := 0; lineN < v.height; lineN++ {
var x int
// If the buffer is smaller than the view height
}
line := v.buf.lines[lineN+v.topline]
+ if len(v.messages) > 0 {
+ msgOnLine := false
+ for _, msg := range v.messages {
+ if msg.lineNum == lineN+v.topline {
+ msgOnLine = true
+ gutterStyle := tcell.StyleDefault
+ switch msg.kind {
+ case GutterInfo:
+ if style, ok := colorscheme["gutter-info"]; ok {
+ gutterStyle = style
+ }
+ case GutterWarning:
+ if style, ok := colorscheme["gutter-warning"]; ok {
+ gutterStyle = style
+ }
+ case GutterError:
+ if style, ok := colorscheme["gutter-error"]; ok {
+ gutterStyle = style
+ }
+ }
+ screen.SetContent(x, lineN, '>', nil, gutterStyle)
+ x++
+ screen.SetContent(x, lineN, '>', nil, gutterStyle)
+ x++
+ if v.cursor.y == lineN {
+ messenger.Message(msg.msg)
+ messenger.gutterMessage = true
+ }
+ }
+ }
+ if !msgOnLine {
+ screen.SetContent(x, lineN, ' ', nil, tcell.StyleDefault)
+ x++
+ screen.SetContent(x, lineN, ' ', nil, tcell.StyleDefault)
+ x++
+ if v.cursor.y == lineN && messenger.gutterMessage {
+ messenger.Reset()
+ messenger.gutterMessage = false
+ }
+ }
+ }
+
// Write the line number
lineNumStyle := defStyle
if style, ok := colorscheme["line-number"]; ok {
}
// Write the spaces before the line number if necessary
var lineNum string
- if settings.Ruler == true {
+ if settings["ruler"] == true {
lineNum = strconv.Itoa(lineN + v.topline + 1)
for i := 0; i < maxLineLength-len(lineNum); i++ {
screen.SetContent(x, lineN, ' ', nil, lineNumStyle)
x++
}
- if settings.Ruler == true {
+ if settings["ruler"] == true {
// Write the extra space
screen.SetContent(x, lineN, ' ', nil, lineNumStyle)
x++
for colN, ch := range line {
var lineStyle tcell.Style
- if settings.Syntax {
+ if settings["syntax"].(bool) {
// Syntax highlighting is enabled
highlightStyle = v.matches[lineN][colN]
}
if ch == '\t' {
screen.SetContent(x+tabchars, lineN, ' ', nil, lineStyle)
- tabSize := settings.TabSize
+ tabSize := int(settings["tabsize"].(float64))
for i := 0; i < tabSize-1; i++ {
tabchars++
if x-v.leftCol+tabchars >= v.lineNumOffset {