diff --git a/SwiftNeoVim/Grid.swift b/SwiftNeoVim/Grid.swift index 45714c12..866a5a99 100644 --- a/SwiftNeoVim/Grid.swift +++ b/SwiftNeoVim/Grid.swift @@ -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 { diff --git a/SwiftNeoVim/NeoVimView.swift b/SwiftNeoVim/NeoVimView.swift index 30877a92..9ffa2c18 100644 --- a/SwiftNeoVim/NeoVimView.swift +++ b/SwiftNeoVim/NeoVimView.swift @@ -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() diff --git a/SwiftNeoVim/NeoVimViewUiBridge.swift b/SwiftNeoVim/NeoVimViewUiBridge.swift index f5d8f066..25b92031 100644 --- a/SwiftNeoVim/NeoVimViewUiBridge.swift +++ b/SwiftNeoVim/NeoVimViewUiBridge.swift @@ -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() } }