---
title: "characterIndexForInsertion(at:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nstextview/characterindexforinsertion(at:)"
---

# characterIndexForInsertion(at:)

Returns a character index appropriate for placing a zero-length selection for an insertion point associated with the mouse at the given point.

## Declaration

```swift
func characterIndexForInsertion(at point: NSPoint) -> Int
```

## Parameters

- `point`: The point for which to return an index, in view coordinates.

## Return Value

Return Value The character index for the insertion point.

## Discussion

Discussion This method should be used for insertion points associated with mouse clicks, drag events, and so forth. For other purposes, it is better to use NSLayoutManager methods. The NSTextInput method characterIndexForPoint: is not suitable for this role; it is intended only for uses related to text input methods.

## See Also

### Managing the selection

- [selectedRanges](appkit/nstextview/selectedranges.md)
- [setSelectedRange(_:)](appkit/nstextview/setselectedrange(_:).md)
- [setSelectedRange(_:affinity:stillSelecting:)](appkit/nstextview/setselectedrange(_:affinity:stillselecting:).md)
- [setSelectedRanges(_:affinity:stillSelecting:)](appkit/nstextview/setselectedranges(_:affinity:stillselecting:).md)
- [selectionAffinity](appkit/nstextview/selectionaffinity.md)
- [selectionGranularity](appkit/nstextview/selectiongranularity.md)
- [insertionPointColor](appkit/nstextview/insertionpointcolor.md)
- [updateInsertionPointStateAndRestartTimer(_:)](appkit/nstextview/updateinsertionpointstateandrestarttimer(_:).md)
- [selectedTextAttributes](appkit/nstextview/selectedtextattributes.md)
- [markedTextAttributes](appkit/nstextview/markedtextattributes.md)
- [linkTextAttributes](appkit/nstextview/linktextattributes.md)
- [updateCandidates()](appkit/nstextview/updatecandidates().md)
