1
1
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:
Tae Won Ha 2016-06-29 20:06:31 +02:00
parent 8f38a53698
commit 015b12332d
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
3 changed files with 29 additions and 14 deletions

View File

@ -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 {

View File

@ -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()

View File

@ -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()
}
}