return true
}
+// MoveCursorUp is not an action
+func (h *BufPane) MoveCursorUp(n int) {
+ if !h.Buf.Settings["softwrap"].(bool) {
+ h.Cursor.UpN(n)
+ } else {
+ vloc := h.VLocFromLoc(h.Cursor.Loc)
+ sloc := h.Scroll(vloc.SLoc, -n)
+ if sloc == vloc.SLoc {
+ // we are at the beginning of buffer
+ h.Cursor.Loc = h.Buf.Start()
+ h.Cursor.LastVisualX = 0
+ } else {
+ vloc.SLoc = sloc
+ vloc.VisualX = h.Cursor.LastVisualX
+ h.Cursor.Loc = h.LocFromVLoc(vloc)
+ }
+ }
+}
+
+// MoveCursorDown is not an action
+func (h *BufPane) MoveCursorDown(n int) {
+ if !h.Buf.Settings["softwrap"].(bool) {
+ h.Cursor.DownN(n)
+ } else {
+ vloc := h.VLocFromLoc(h.Cursor.Loc)
+ sloc := h.Scroll(vloc.SLoc, n)
+ if sloc == vloc.SLoc {
+ // we are at the end of buffer
+ h.Cursor.Loc = h.Buf.End()
+ vloc = h.VLocFromLoc(h.Cursor.Loc)
+ h.Cursor.LastVisualX = vloc.VisualX
+ } else {
+ vloc.SLoc = sloc
+ vloc.VisualX = h.Cursor.LastVisualX
+ h.Cursor.Loc = h.LocFromVLoc(vloc)
+ }
+ }
+}
+
// CursorUp moves the cursor up
func (h *BufPane) CursorUp() bool {
h.Cursor.Deselect(true)
- h.Cursor.Up()
+ h.MoveCursorUp(1)
h.Relocate()
return true
}
// CursorDown moves the cursor down
func (h *BufPane) CursorDown() bool {
h.Cursor.Deselect(true)
- h.Cursor.Down()
+ h.MoveCursorDown(1)
h.Relocate()
return true
}
if !h.Cursor.HasSelection() {
h.Cursor.OrigSelection[0] = h.Cursor.Loc
}
- h.Cursor.Up()
+ h.MoveCursorUp(1)
h.Cursor.SelectTo(h.Cursor.Loc)
h.Relocate()
return true
if !h.Cursor.HasSelection() {
h.Cursor.OrigSelection[0] = h.Cursor.Loc
}
- h.Cursor.Down()
+ h.MoveCursorDown(1)
h.Cursor.SelectTo(h.Cursor.Loc)
h.Relocate()
return true
if !h.Cursor.HasSelection() {
h.Cursor.OrigSelection[0] = h.Cursor.Loc
}
- h.Cursor.UpN(h.BufHeight())
+ h.MoveCursorUp(h.BufHeight())
h.Cursor.SelectTo(h.Cursor.Loc)
h.Relocate()
return true
if !h.Cursor.HasSelection() {
h.Cursor.OrigSelection[0] = h.Cursor.Loc
}
- h.Cursor.DownN(h.BufHeight())
+ h.MoveCursorDown(h.BufHeight())
h.Cursor.SelectTo(h.Cursor.Loc)
h.Relocate()
return true
h.Cursor.ResetSelection()
h.Cursor.StoreVisualX()
}
- h.Cursor.UpN(h.BufHeight())
+ h.MoveCursorUp(h.BufHeight())
h.Relocate()
return true
}
h.Cursor.ResetSelection()
h.Cursor.StoreVisualX()
}
- h.Cursor.DownN(h.BufHeight())
+ h.MoveCursorDown(h.BufHeight())
h.Relocate()
return true
}
// the buffer module cannot directly call the display's API (it would mean
// a circular dependency between packages).
OptionCallback func(option string, nativeValue interface{})
+
+ // The display module registers its own GetVisualX function for getting
+ // the correct visual x location of a cursor when softwrap is used.
+ // This is hacky. Maybe it would be better to move all the visual x logic
+ // from buffer to display, but it would require rewriting a lot of code.
+ GetVisualX func(loc Loc) int
}
// NewBufferFromFileAtLoc opens a new buffer with a given cursor location
w.StartLine.Row = 0
}
w.Relocate()
+
+ for _, c := range w.Buf.GetCursors() {
+ c.LastVisualX = c.GetVisualX()
+ }
}
}
+ b.GetVisualX = func(loc buffer.Loc) int {
+ return w.VLocFromLoc(loc).VisualX
+ }
}
func (w *BufWindow) GetView() *View {
func (w *BufWindow) Resize(width, height int) {
w.Width, w.Height = width, height
+ w.updateDisplayInfo()
+
w.Relocate()
+
+ if w.Buf.Settings["softwrap"].(bool) {
+ for _, c := range w.Buf.GetCursors() {
+ c.LastVisualX = c.GetVisualX()
+ }
+ }
}
func (w *BufWindow) SetActive(b bool) {