CodeEditApp/CodeEditSourceEditor

Compile Error: cannot convert value of type 'NSTextRange' to expected argument type 'NSRange' (aka '_NSRange')

Closed this issue · 3 comments

Description

I tried to use CodeEditTextView in a project:

//
//  ContentView.swift
//  SwiftUITest
//
//  Created by Debdut Karmakar on 5/16/23.
//

import SwiftUI
import CodeEditTextView

struct ContentView: View {

    @State var text = "let x = 1.0"
    var theme = EditorTheme(
        text: NSColor(hex: "#D9D9D9"),
        insertionPoint: NSColor(hex: "#D9D9D9"),
        invisibles: NSColor(hex: "#424D5B"),
        background: NSColor(hex: "#1F1F24"),
        lineHighlight: NSColor(hex: "#23252B"),
        selection: NSColor(hex: "#515B70"),
        keywords: NSColor(hex: "#FF7AB3"),
        commands: NSColor(hex: "#67B7A4"),
        types: NSColor(hex: "#5DD8FF"),
        attributes: NSColor(hex: "#D0A8FF"),
        variables: NSColor(hex: "#41A1C0"),
        values: NSColor(hex: "#A167E6"),
        numbers: NSColor(hex: "#D0BF69"),
        strings: NSColor(hex: "#FC6A5D"),
        characters: NSColor(hex: "#D0BF69"),
        comments: NSColor(hex: "#73A74E")
    )
    var font = NSFont.monospacedSystemFont(ofSize: 11, weight: .regular)
    var tabWidth = 4
    var lineHeight = 1.2
    var editorOverscroll = 0.3
    var wrapLines = true
    @State var cursorPosition = (1, 1)

    var body: some View {
        CodeEditTextView($text, language: .swift, theme: theme, font: NSFont.monospacedSystemFont(ofSize: 11, weight: .regular), tabWidth: tabWidth, lineHeight: lineHeight, wrapLines: wrapLines, cursorPosition: $cursorPosition)
    }
}

It doesn't compile and gives the following error:

CodeEditTextView/Sources/CodeEditTextView/Extensions/STTextView+/STTextView+TextInterface.swift:23:39 Cannot convert value of type 'NSTextRange' to expected argument type 'NSRange' (aka '_NSRange')

To Reproduce

  1. Create a SwiftUI macOS project
  2. Add this view:
import SwiftUI
import CodeEditTextView

struct ContentView: View {

    @State var text = "let x = 1.0"
    var theme = EditorTheme(
        text: NSColor(hex: "#D9D9D9"),
        insertionPoint: NSColor(hex: "#D9D9D9"),
        invisibles: NSColor(hex: "#424D5B"),
        background: NSColor(hex: "#1F1F24"),
        lineHighlight: NSColor(hex: "#23252B"),
        selection: NSColor(hex: "#515B70"),
        keywords: NSColor(hex: "#FF7AB3"),
        commands: NSColor(hex: "#67B7A4"),
        types: NSColor(hex: "#5DD8FF"),
        attributes: NSColor(hex: "#D0A8FF"),
        variables: NSColor(hex: "#41A1C0"),
        values: NSColor(hex: "#A167E6"),
        numbers: NSColor(hex: "#D0BF69"),
        strings: NSColor(hex: "#FC6A5D"),
        characters: NSColor(hex: "#D0BF69"),
        comments: NSColor(hex: "#73A74E")
    )
    var font = NSFont.monospacedSystemFont(ofSize: 11, weight: .regular)
    var tabWidth = 4
    var lineHeight = 1.2
    var editorOverscroll = 0.3
    var wrapLines = true
    @State var cursorPosition = (1, 1)

    var body: some View {
        CodeEditTextView($text, language: .swift, theme: theme, font: NSFont.monospacedSystemFont(ofSize: 11, weight: .regular), tabWidth: tabWidth, lineHeight: lineHeight, wrapLines: wrapLines, cursorPosition: $cursorPosition)
    }
}
  1. Add CodeEditTextView package to the project
  2. Build

Expected Behavior

Should compile and show the desired TextView.

Version Information

CodeEditTextView: [e.g. 0.6.2]
macOS: [e.g. 13.0]
Xcode: [e.g. 14.1]

Additional Context

No response

Screenshots

No response

Can you include some more information about what version of CodeEditTextView, MacOS version being compiled for, and Xcode version? Also if you can check what version of STTextView is being resolved I can do more to diagnose what's going wrong.

luah5 commented

@thecoolwinter this bug is a known STTextView bug, see the discussion: krzyzanowskim/STTextView#18 it's fixed in the latest release of STTextView tho

I'm going to close this as stale/needs more info. Feel free to re-open if this is still an issue.