NSTextView - supplying word completions for insertion point?

  • I have a text view in for which I'd like to offer a small number of
    completions for. I'm currently supplying these via the appropriate
    delegate method.

    What I would like to do in addition is offer up all of the possibly
    completions (there aren't that many) when the user tries to
    "complete" an insertion point.

    NSTextView appears to go backwards to the next word boundary (over
    whitespace) which is undesirable, but a simple override can correct
    that.

    However, if I return a 0 length range from -rangeForUserCompletion,
    the completions are never triggered. The documentation is explicit
    that I should "Returning (NSNotFound, 0) suppresses completion." How
    can I convince NSTextView that it should offer up a list of
    completions for an empty completion range?

    Thanks,
    Jim
  • On Aug 29, 2006, at 1:39 PM, Jim Correia wrote:

    > I have a text view in for which I'd like to offer a small number of
    > completions for. I'm currently supplying these via the appropriate
    > delegate method.
    >
    > What I would like to do in addition is offer up all of the possibly
    > completions (there aren't that many) when the user tries to
    > "complete" an insertion point.
    >
    > NSTextView appears to go backwards to the next word boundary (over
    > whitespace) which is undesirable, but a simple override can correct
    > that.
    >
    > However, if I return a 0 length range from -rangeForUserCompletion,
    > the completions are never triggered. The documentation is explicit
    > that I should "Returning (NSNotFound, 0) suppresses completion."
    > How can I convince NSTextView that it should offer up a list of
    > completions for an empty completion range?

    You can file a bug requesting a change in behavior, but with the
    current implementation I don't see anything short of lying about the
    range and then fixing it up again in
    insertCompletion:forPartialWordRange:movement:isFinal:.  At that
    point you might be better off just overriding the whole completion
    mechanism, and putting up your own completion window--you might even
    be able to find code for this sort of thing floating around.

    Douglas Davidson
previous month august 2006 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today