mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-07-17 06:31:10 +00:00
libghostty: add selection contains API
Expose a C API for checking whether a GhosttyPoint is inside a GhosttySelection. The new terminal helper validates the selection snapshot against the active screen, resolves the point to a grid pin, and delegates to the internal Selection.contains implementation so C consumers get the same linear and rectangular selection semantics as Ghostty. Wire the symbol through the C API exports and public headers, and add a focused test covering linear containment and rectangular selection behavior.
This commit is contained in:
@@ -136,6 +136,7 @@ extern "C" {
|
||||
#include <ghostty/vt/modes.h>
|
||||
#include <ghostty/vt/mouse.h>
|
||||
#include <ghostty/vt/paste.h>
|
||||
#include <ghostty/vt/point.h>
|
||||
#include <ghostty/vt/screen.h>
|
||||
#include <ghostty/vt/selection.h>
|
||||
#include <ghostty/vt/size_report.h>
|
||||
|
||||
@@ -1207,6 +1207,34 @@ GHOSTTY_API GhosttyResult ghostty_terminal_selection_ordered(
|
||||
GhosttySelectionOrder desired,
|
||||
GhosttySelection* out_selection);
|
||||
|
||||
/**
|
||||
* Test whether a terminal point is inside a selection snapshot.
|
||||
*
|
||||
* This uses the same selection semantics as the terminal, including
|
||||
* rectangular/block selections and linear selections spanning multiple rows.
|
||||
*
|
||||
* The selection's start and end grid refs must both be valid untracked
|
||||
* snapshots for the given terminal's currently active screen. In practice,
|
||||
* they must come from that terminal and screen, and no mutating terminal call
|
||||
* may have occurred since the refs were produced or reconstructed from
|
||||
* tracked refs. Passing refs from another terminal, another screen, or stale
|
||||
* refs violates this precondition.
|
||||
*
|
||||
* @param terminal The terminal handle (NULL returns GHOSTTY_INVALID_VALUE)
|
||||
* @param selection Selection snapshot to inspect
|
||||
* @param point Point to test for containment
|
||||
* @param[out] out_contains On success, receives whether point is inside selection
|
||||
* @return GHOSTTY_SUCCESS on success, GHOSTTY_INVALID_VALUE if the terminal,
|
||||
* selection, selection references, point, or output pointer are invalid
|
||||
*
|
||||
* @ingroup terminal
|
||||
*/
|
||||
GHOSTTY_API GhosttyResult ghostty_terminal_selection_contains(
|
||||
GhosttyTerminal terminal,
|
||||
const GhosttySelection* selection,
|
||||
GhosttyPoint point,
|
||||
bool* out_contains);
|
||||
|
||||
/**
|
||||
* Resolve a point in the terminal grid to a grid reference.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user