Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8971703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:01:25+00:00 2026-06-15T18:01:25+00:00

I am trying to implement a simple NSTextField with autocomplete that behaves more like

  • 0

I am trying to implement a simple NSTextField with autocomplete that behaves more like a JQuery UI autocomplete (http://jqueryui.com/autocomplete/) than the default behavior of NSSearchField. The difference between the two is that with JQuery UI the user has to manually select one of the suggestions before it becomes active in the textfield, whereas with the NS methods the first suggestion is automatically selected.

The reason is that the list of suggestions I will provide to the user are not going to match the text, but instead will be related. For example, if the user types “app”, instead of suggesting “apple”, I will suggest “fruit”. Unfortunately, with the default behavior, if the first item is automatically selected, then the textfield will change to “fruit” as soon as it is suggested, which is not the desired behavior (I want it to stay as “app” until the user selects “fruit” themselves.

Is it possible to prevent the first item from automatically being selected? The closest solution I have found is listed below. While it does prevent the text from being overwritten, I would prefer to not have any item selected at all, since the list is meant to be a list of valid entries, and by showing what the user has typed as the first item, it would incorrectly indicate that the input is always valid. So in other words, I am trying to use the autocomplete to both speed entry as well as restrict the input to valid entries.

Closest solution found so far:
How to prevent NSSearchField from overwriting entered strings using the first autocompletion list entry?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:01:26+00:00Added an answer on June 15, 2026 at 6:01 pm

    I figured this out. First in…

    control:textView:completions:forPartialWordRange:indexOfSelectedItem: 
    

    I added:

    *index = -1;
    

    This tells the autocomplete to not select anything (as described here: NSTextView Class Reference)

    index

    On input, an integer variable with the default value of 0. On output,
    you can set this value to an index in the returned array indicating
    which item should be selected initially. Set the value to -1 to
    indicate there should not be an initial selection.

    Then, the next problem I had was that if you enter more than one word in the search field, then the autocompletion only replaces the last word, whereas the desired behavior is to replace the entire search string. In order to resolve this, I subclassed NSTextView and added the following method:

    -(NSRange) rangeForUserCompletion {
        return NSMakeRange (0, 1);
    }
    

    This makes sure that the entire search string is replaced instead of just the last word.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement the simple-linkedinphp library (it's found at http://code.google.com/p/simple-linkedinphp/ ) It runs
I'm trying to implement a simple HTTP server in Android that handles POST requests,
Trying to implement a simple load more functionality with jquery. The idea is to
I am trying to implement a simple client that connects to a give address.
I am trying to implement a simple C++ function that adds a node to
I'm trying to implement simple Event Bus I started like this: public class RegistrationData
Trying to implement a simple notification system based on private pub ( something like
I'm trying to implement a simple layout, closely represented like this: _________________________ | |
I was trying to implement a simple function that can concatenate any number of
I'm trying to implement a simple watermark on a text box that disappears when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.