<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSRulerMarker/trackMouse(with:adding:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSRulerMarker(im)trackMouse:adding:"
  },
  "title" : "trackMouse(with:adding:)"
}
-->

# trackMouse(with:adding:)

Handles user manipulation of the receiver in its ruler view.

```
func trackMouse(with mouseDownEvent: NSEvent, adding isAdding: Bool) -> Bool
```

## Parameters

`mouseDownEvent`

The event that represents the user manipulation being attempted on the ruler marker.

`isAdding`

<doc://com.apple.documentation/documentation/Swift/true> to indicate that the receiver is a new marker being added to its ruler view, <doc://com.apple.documentation/documentation/Swift/false> otherwise.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the user manipulation was allowed, <doc://com.apple.documentation/documentation/Swift/false> if it was not allowed.

## Discussion

[`NSRulerView`](/documentation/AppKit/NSRulerView) objects invoke this method automatically to add a new marker or to move or remove an existing marker. You should never need to invoke it directly.

If the receiver is a new marker being added to its ruler view (`flag` is <doc://com.apple.documentation/documentation/Swift/true>), the receiver queries the ruler view’s client before adding itself to the ruler view. If the client responds to [`rulerView(_:shouldAdd:)`](/documentation/AppKit/NSView/rulerView(_:shouldAdd:)) and that method returns <doc://com.apple.documentation/documentation/Swift/false>, this method immediately returns <doc://com.apple.documentation/documentation/Swift/false>, and the new marker isn’t added.

If the receiver is not a new marker being added to its ruler view (`flag` is <doc://com.apple.documentation/documentation/Swift/false>), this method attempts to move or remove an existing marker, once again based on responses from the ruler view’s client view. If the receiver is neither movable nor removable, this method immediately returns <doc://com.apple.documentation/documentation/Swift/false>. Further, if the ruler view’s client responds to [`rulerView(_:shouldMove:)`](/documentation/AppKit/NSView/rulerView(_:shouldMove:)) and returns <doc://com.apple.documentation/documentation/Swift/false>, this method returns <doc://com.apple.documentation/documentation/Swift/false>, indicating the receiver can’t be moved.

If the receiver is being added or moved, this method queries the client view using [`rulerView(_:willAdd:atLocation:)`](/documentation/AppKit/NSView/rulerView(_:willAdd:atLocation:)) or [`rulerView(_:willMove:toLocation:)`](/documentation/AppKit/NSView/rulerView(_:willMove:toLocation:)), respectively. If the client responds to the method, the return value is used as the receiver’s location. These methods are invoked repeatedly as the receiver is dragged within the ruler view.

If the receiver is an existing marker being removed (dragged off the ruler), this method queries the client view using [`rulerView(_:shouldRemove:)`](/documentation/AppKit/NSView/rulerView(_:shouldRemove:)). If the client responds to this method and returns <doc://com.apple.documentation/documentation/Swift/false>, the marker is pinned to the ruler view’s baseline (following the cursor on the baseline if it’s movable).

When the user releases the mouse button, this method informs the client view of the marker’s new status using [`rulerView(_:didAdd:)`](/documentation/AppKit/NSView/rulerView(_:didAdd:)), [`rulerView(_:didMove:)`](/documentation/AppKit/NSView/rulerView(_:didMove:)), or [`rulerView(_:didRemove:)`](/documentation/AppKit/NSView/rulerView(_:didRemove:)) as appropriate. The client view can use this notification to set the marker’s represented object, modify its state and redisplay (for example, adjusting text layout around a new tab stop), or take whatever other action it might need.

If `flag` is <doc://com.apple.documentation/documentation/Swift/true> and the user dragged the new marker away from the ruler, the marker isn’t added, no message is sent, and this method returns <doc://com.apple.documentation/documentation/Swift/false>.

See [Ruler and Paragraph Style Programming Topics](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Rulers/Rulers.html#//apple_ref/doc/uid/10000089i) for more information on these client methods.

## See Also

[`isMovable`](/documentation/AppKit/NSRulerMarker/isMovable)

A Boolean that indicates whether the user can move the receiver in its ruler view.

[`isRemovable`](/documentation/AppKit/NSRulerMarker/isRemovable)

A Boolean that indicates whether the user can remove the receiver from its ruler view.



---

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)