Use StoreVisualX() all over the code

Since we already have the StoreVisualX() helper, use it all over the
place instead of setting LastVisualX directly.

This will allow us to add more logic to StoreVisualX() add let this
extra logic apply everywhere automatically.
This commit is contained in:
Dmytro Maluka 2024-10-13 17:46:34 +02:00
parent d60413f03c
commit 85afb6eb87
4 changed files with 7 additions and 7 deletions

View File

@ -657,7 +657,7 @@ func (h *BufPane) InsertNewline() bool {
h.Buf.Remove(buffer.Loc{X: 0, Y: h.Cursor.Y - 1}, buffer.Loc{X: util.CharacterCount(line), Y: h.Cursor.Y - 1})
}
}
h.Cursor.LastVisualX = h.Cursor.GetVisualX()
h.Cursor.StoreVisualX()
h.Relocate()
return true
}
@ -687,7 +687,7 @@ func (h *BufPane) Backspace() bool {
h.Buf.Remove(loc.Move(-1, h.Buf), loc)
}
}
h.Cursor.LastVisualX = h.Cursor.GetVisualX()
h.Cursor.StoreVisualX()
h.Relocate()
return true
}

View File

@ -100,7 +100,7 @@ func (c *Cursor) GetCharPosInLine(b []byte, visualPos int) int {
// Start moves the cursor to the start of the line it is on
func (c *Cursor) Start() {
c.X = 0
c.LastVisualX = c.GetVisualX()
c.StoreVisualX()
}
// StartOfText moves the cursor to the first non-whitespace rune of
@ -131,7 +131,7 @@ func (c *Cursor) IsStartOfText() bool {
// End moves the cursor to the end of the line it is on
func (c *Cursor) End() {
c.X = util.CharacterCount(c.buf.LineBytes(c.Y))
c.LastVisualX = c.GetVisualX()
c.StoreVisualX()
}
// CopySelection copies the user's selection to either "primary"

View File

@ -104,7 +104,7 @@ func (eh *EventHandler) DoTextEvent(t *TextEvent, useUndo bool) {
c.OrigSelection[0] = move(c.OrigSelection[0])
c.OrigSelection[1] = move(c.OrigSelection[1])
c.Relocate()
c.LastVisualX = c.GetVisualX()
c.StoreVisualX()
}
if useUndo {

View File

@ -107,7 +107,7 @@ function commentLine(bp, lineN, indentLen)
bp.Cursor.Y = curpos.Y
end
bp.Cursor:Relocate()
bp.Cursor.LastVisualX = bp.Cursor:GetVisualX()
bp.Cursor:StoreVisualX()
end
function uncommentLine(bp, lineN, commentRegex)
@ -135,7 +135,7 @@ function uncommentLine(bp, lineN, commentRegex)
end
end
bp.Cursor:Relocate()
bp.Cursor.LastVisualX = bp.Cursor:GetVisualX()
bp.Cursor:StoreVisualX()
end
function toggleCommentLine(bp, lineN, commentRegex)