     return result
   }
 
-  public func markedRange() -> NSRange {
+  func markedRange() -> NSRange {
     guard let marked = self.markedText else {
       self.log.debug("No marked text, returning not found")
       return .notFound

    self.keyDownDone = true
  }

  public override func doCommand(by aSelector: Selector) {
    if self.responds(to: aSelector) {
      self.log.debug("calling \(aSelector)")
      self.perform(aSelector, with: self)

    return result
  }

  func hasMarkedText() -> Bool { self.markedText != nil }

  func attributedSubstring(
    forProposedRange aRange: NSRange,
    actualRange _: NSRangePointer?
  ) -> NSAttributedString? {
    self.log.debug("\(aRange)")
    if aRange.location == NSNotFound { return nil }

    guard
      let position = self.ugrid.firstPosition(fromFlatCharIndex: aRange.location),
      let inclusiveEndPosition = self.ugrid.lastPosition(
        fromFlatCharIndex: aRange.location + aRange.length - 1
      )
    else { return nil }

    self.log.debug("\(position) ... \(inclusiveEndPosition)")
    let string = self.ugrid.cells[position.row...inclusiveEndPosition.row]
      .map { row in
        row.filter { cell in
          aRange.location <= cell.flatCharIndex && cell.flatCharIndex <= aRange.inclusiveEndIndex
        }
      }
      .flatMap { $0 }
      .map(\.string)
      .joined()

    let delta = aRange.length - string.utf16.count
    if delta != 0 { self.log.debug("delta = \(delta)!") }

    self.log.debug("returning '\(string)'")
    return NSAttributedString(string: string)
  }

  func validAttributesForMarkedText() -> [NSAttributedString.Key] { [] }

  func firstRect(forCharacterRange aRange: NSRange, actualRange _: NSRangePointer?) -> NSRect {
    guard let position = self.ugrid.firstPosition(fromFlatCharIndex: aRange.location) else {
      return CGRect.zero
    }

    self.log.debug("\(aRange)-> \(position.row):\(position.column)")

    let resultInSelf = self.rect(forRow: position.row, column: position.column)
    let result = self.window?.convertToScreen(self.convert(resultInSelf, to: nil))

    return result!
  }

  func characterIndex(for aPoint: NSPoint) -> Int {
    let position = self.position(at: aPoint)
    let result = self.ugrid.flatCharIndex(forPosition: position)

