Coder Social home page Coder Social logo

suggestionstextfieldkit's Introduction

SuggestionsTextFieldKit

SuggestionsTextFieldKit is a library that enables the addition of suggestion functionality to NSTextField components within AppKit applications.

Features

  • Seamless Integration: Easily attach to any NSTextField to start offering suggestions.
  • Customizable: Tailor the suggestions window and data source to fit the needs of your app.
  • User Interaction: Handles user selections and confirmations with customizable handlers.
  • Keyboard Navigation: Supports moving up and down the suggestions list using keyboard commands.

Installation

Swift Package Manager

To integrate SuggestionsTextFieldKit into your Xcode project, use Swift Package Manager.

Usage

After importing SuggestionsTextFieldKit, you can easily add suggestions to an NSTextField by setting up a SuggestionsTextFieldDelegate and providing a data source for your suggestions.

import SuggestionsTextFieldKit
import AppKit

class YourViewController: NSViewController {
    @IBOutlet var textField: NSTextField!
    private var suggestionsDelegate: SuggestionsTextFieldDelegate?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupSuggestions()
    }

    private func setupSuggestions() {
        let suggestionsDelegate = SuggestionsTextFieldDelegate()
        suggestionsDelegate.suggestionsDataSource = self // Ensure your class conforms to `SuggestionsDataSource`
        suggestionsDelegate.selectionHandler = { suggestion in
            print("User selected suggestion: \(suggestion)")
        }
        suggestionsDelegate.confirmationHandler = { suggestion in
            print("User confirmed suggestion: \(suggestion)")
        }
        suggestionsDelegate.targetTextField = textField
        self.suggestionsDelegate = suggestionsDelegate
    }
}

extension YourViewController: SuggestionsDataSource {
    // Implement `SuggestionsDataSource` to provide suggestion data
    var suggestions: [Suggestion] = [] {
        didSet { NotificationCenter.default.post(name: SuggestionsChangedNotificationName, object: self) }
    }
    var inputString: String = "" {
        didSet { Task { await updateSuggestions() } }
    }
    // Implement updateSuggestions()
}

Contributing

Contributions to SuggestionsTextFieldKit are welcome! Whether you're fixing bugs, adding new features, or improving documentation, please feel free to submit a pull request or open an issue.

License

SuggestionsTextFieldKit is available under the LGPL V3 license. See the LICENSE file for more info.

suggestionstextfieldkit's People

Contributors

claucambra avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.