mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-25 14:52:19 +03:00
Improve cursor drawing
This commit is contained in:
parent
8f38a53698
commit
015b12332d
@ -174,6 +174,18 @@ class Grid: CustomStringConvertible {
|
||||
self.cells[position.row][position.column].marked = false
|
||||
}
|
||||
|
||||
func isNextCellEmpty(position: Position) -> Bool {
|
||||
if self.cells[position.row][min(position.column + 1, self.size.width - 1)].string.characters.count == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func nextCellPosition(position: Position) -> Position {
|
||||
return Position(row: position.row, column: min(position.column + 1, self.size.width - 1))
|
||||
}
|
||||
|
||||
private func clearRegion(region: Region) {
|
||||
// FIXME: sometimes clearRegion gets called without first resizing the Grid. Should we handle this?
|
||||
guard self.hasData else {
|
||||
|
@ -143,12 +143,9 @@ public class NeoVimView: NSView {
|
||||
// Swift.print("\(#function): \(cursorPosition)")
|
||||
|
||||
var cursorRect = self.cellRect(row: cursorPosition.row, column: cursorPosition.column)
|
||||
Swift.print("@@@@@@@@@@@@@@@@@ original \(cursorRect)")
|
||||
let nextColumn = min(cursorPosition.column + 1, self.grid.size.width)
|
||||
let nextString = self.grid.cells[cursorPosition.row][nextColumn].string
|
||||
if nextString.characters.count == 0 {
|
||||
cursorRect = cursorRect.union(self.cellRect(row: cursorPosition.row, column:nextColumn))
|
||||
Swift.print("@@@@@@@@@@@@@@@@@ new \(cursorRect)")
|
||||
if self.grid.isNextCellEmpty(cursorPosition) {
|
||||
let nextPosition = self.grid.nextCellPosition(cursorPosition)
|
||||
cursorRect = cursorRect.union(self.cellRect(row: nextPosition.row, column:nextPosition.column))
|
||||
}
|
||||
|
||||
ColorUtils.colorFromCodeIgnoringAlpha(background).set()
|
||||
|
@ -46,11 +46,9 @@ extension NeoVimView: NeoVimUiBridgeProtocol {
|
||||
public func cursorGotoRow(row: Int32, column: Int32) {
|
||||
DispatchUtils.gui {
|
||||
Swift.print("### goto: \(row):\(column)")
|
||||
self.setNeedsDisplayAt(position: self.grid.position)
|
||||
|
||||
let newPosition = Position(row: Int(row), column: Int(column))
|
||||
self.grid.goto(newPosition)
|
||||
self.setNeedsDisplayAt(position: newPosition)
|
||||
self.setCursorNeedsDisplay()
|
||||
self.grid.goto(Position(row: Int(row), column: Int(column)))
|
||||
self.setCursorNeedsDisplay()
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,7 +111,15 @@ extension NeoVimView: NeoVimUiBridgeProtocol {
|
||||
if string.characters.count == 0 {
|
||||
self.setNeedsDisplayAt(row: curPos.row, column: max(curPos.column - 1, 0))
|
||||
}
|
||||
self.setNeedsDisplayAt(position: self.grid.position) // cursor
|
||||
self.setCursorNeedsDisplay()
|
||||
}
|
||||
}
|
||||
|
||||
private func setCursorNeedsDisplay() {
|
||||
let position = self.grid.position
|
||||
self.setNeedsDisplayAt(position: position)
|
||||
if self.grid.isNextCellEmpty(position) {
|
||||
self.setNeedsDisplayAt(position: self.grid.nextCellPosition(position))
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,7 +133,7 @@ extension NeoVimView: NeoVimUiBridgeProtocol {
|
||||
if markedText.characters.count == 0 {
|
||||
self.setNeedsDisplayAt(row: curPos.row, column: max(curPos.column - 1, 0))
|
||||
}
|
||||
self.setNeedsDisplayAt(position: self.grid.position) // cursor
|
||||
self.setCursorNeedsDisplay()
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,7 +142,7 @@ extension NeoVimView: NeoVimUiBridgeProtocol {
|
||||
// Swift.print("\(#function): \(row):\(column)")
|
||||
self.grid.unmarkCell(Position(row: Int(row), column: Int(column)))
|
||||
self.setNeedsDisplayAt(row: Int(row), column: Int(column))
|
||||
self.setNeedsDisplayAt(position: self.grid.position) // cursor
|
||||
self.setCursorNeedsDisplay()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user