hltrailingws: improve updateTrailingWs logic
Handle the case when the cursor itself hasn't really moved to another line, but its line number has changed due to insert or remove of some lines above. In this case, if the cursor is still at its new trailingws, we should not reset NewTrailingWsY to -1 but update it to the new line number. A scenario exemplifying this issue: Bind some key, e.g. Alt-r, to such a lua function: function insertNewlineAbove(bp) bp.Buf:Insert(buffer.Loc(0, bp.Cursor.Y), "\n") end Then in a file containing these lines: aaa bbb ccc insert a space at the end of bbb line, and then press Alt-r. bbb and ccc are moved one line down, but also the trailing space after bbb becomes highlighted, which isn't what we expect. This commit fixes that.
This commit is contained in:
parent
b824e767d6
commit
f108c90643
1 changed files with 6 additions and 0 deletions
|
@ -391,5 +391,11 @@ func (eh *EventHandler) updateTrailingWs(t *TextEvent) {
|
|||
} else if !removedAfterWs {
|
||||
c.NewTrailingWsY = -1
|
||||
}
|
||||
} else if c.NewTrailingWsY != -1 && start.Y != end.Y && c.Loc.GreaterThan(start) &&
|
||||
((t.EventType == TextEventInsert && c.Y == c.NewTrailingWsY+(end.Y-start.Y)) ||
|
||||
(t.EventType == TextEventRemove && c.Y == c.NewTrailingWsY-(end.Y-start.Y))) {
|
||||
// The cursor still has its new trailingws
|
||||
// but its line number was shifted by insert or remove of lines above
|
||||
c.NewTrailingWsY = c.Y
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue