<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextView/insertCompletion(_:forPartialWordRange:movement:isFinal:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTextView(im)insertCompletion:forPartialWordRange:movement:isFinal:"
  },
  "title" : "insertCompletion(_:forPartialWordRange:movement:isFinal:)"
}
-->

# insertCompletion(_:forPartialWordRange:movement:isFinal:)

Inserts the selected completion into the text at the appropriate location.

```
func insertCompletion(_ word: String, forPartialWordRange charRange: NSRange, movement: Int, isFinal flag: Bool)
```

## Parameters

`word`

The text to insert, including the matched partial word and its potential completion.

`charRange`

The range of characters of the matched partial word to be completed.

`movement`

The direction of movement. For possible values see the [`NSText`](/documentation/AppKit/NSText) Constants section. This value allows subclasses to distinguish between canceling completion and selection by arrow keys, by return, by tab, or by other means such as clicking.

`flag`

<doc://com.apple.documentation/documentation/Swift/false> while the user navigates through the potential text completions, <doc://com.apple.documentation/documentation/Swift/true> when a completion is definitively selected or cancelled and the original value is reinserted.

## Discussion

This method has two effects, text substitution and changing of the selection:

- It replaces the text between `charRange.start` and the current insertion point with `word`.
- If `flag` is <doc://com.apple.documentation/documentation/Swift/false> it changes the selection to be the last *n* characters of `word` where *n* is equal to `[word length]` minus `charRange.length`, that is, the potential completion.
- If `flag` is <doc://com.apple.documentation/documentation/Swift/true> it makes the selection empty and puts the insertion point just after `word`.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)