Commit Graph

13163 Commits

Author SHA1 Message Date
Lukas
cbcd52846c macOS: fix search dragging animation when corner is not changed 2025-11-26 21:00:14 +01:00
Mitchell Hashimoto
48d11b1ce4 fix(macos): use strings' utf-8 lengths for libghostty calls (#9715)
Swift conveniently converts strings to UTF-8 encoded cstrings when
passing them to external functions, however our libghostty functions
also take a length and we were using String.count for that, which
returns the number of _characters_ not the byte length, which caused
searches with multi-byte characters to get truncated.

I went ahead and changed _all_ invocations that pass a string length to
use the utf-8 byte length even if the string is comptime-known and all
ASCII, just so that it's proper and if someone copies one of the calls
in the future for user-inputted data they don't reproduce this bug.

ref:
https://developer.apple.com/documentation/swift/string/count
https://developer.apple.com/documentation/swift/stringprotocol/lengthofbytes(using:)
2025-11-26 11:16:36 -08:00
Qwerasd
4b01163c79 fix(macos): use strings' utf-8 lengths for libghostty calls
Swift conveniently converts strings to UTF-8 encoded cstrings when
passing them to external functions, however our libghostty functions
also take a length and we were using String.count for that, which
returns the number of _characters_ not the byte length, which caused
searches with multi-byte characters to get truncated.

I went ahead and changed _all_ invocations that pass a string length to
use the utf-8 byte length even if the string is comptime-known and all
ASCII, just so that it's proper and if someone copies one of the calls
in the future for user-inputted data they don't reproduce this bug.

ref:
https://developer.apple.com/documentation/swift/string/count
https://developer.apple.com/documentation/swift/stringprotocol/lengthofbytes(using:)
2025-11-26 12:00:58 -07:00
Mitchell Hashimoto
d213091452 renderer: manual selection should take priority over search matches (#9714)
Previously it was impossible to select a search match. Well, it was
selecting but it wasn't showing that it was selected.
2025-11-26 10:30:42 -08:00
Mitchell Hashimoto
9206b3dc9b renderer: manual selection should take priority over search matches
Previously it was impossible to select a search match. Well, it was
selecting but it wasn't showing that it was selected.
2025-11-26 10:28:28 -08:00
Mitchell Hashimoto
3305455902 macOS: move search result counter inside text field (#9713)
Move the search result counter inside the search text field using an
overlay, preventing layout shift when results appear.

**Before:** The counter appeared as a separate element in the HStack,
causing the text field to shift when results loaded.

**After:** The counter is overlaid inside the text field on the right
side with reserved padding, eliminating layout shift.

---

**AI Disclosure: The was entirely authored with Claude Code,
specifically with Claude Opus 4.5.**
2025-11-26 10:07:15 -08:00
Mitchell Hashimoto
d85fc62774 search: reset selected match when the needle changes 2025-11-26 10:04:28 -08:00
avarayr
f5b923573d macOS: move search result counter inside text field
Move the search result counter (e.g. "1/30") inside the search text
field using an overlay, preventing layout shift when results appear.

This PR was authored with Claude Code.
2025-11-26 13:04:05 -05:00
Mitchell Hashimoto
71a2dad929 macOS Search GUI (#9709)
#189 for macOS

This adds a search GUI for macOS, including macOS-standard menu bar
items, and keybindings that match other native macOS applications such
as Terminal app, Safari, and others. This introduces a new keybinding
action `start_search` to start a blank search for GUIs.

This PR also resolves a number of minor issues found in the search
subsystem and renderer related to search from prior PRs. This should
result in overall improved search stability. **Please note there are
still known issues (bottom of this PR).**

> [!WARNING]
>
> **A note on stability:** I know a lot of people are eager to have this
feature, and I'm excited
> for this feature to soon be available in tip releases. But note that
new features like this are
> always filled with performance issues, bugs, crashes, etc. That's the
point of tip releases:
> to find and address these before wider availability. We will do our
best to respond rapidly to
> major issues found in tip, but don't expect perfect functionality
immediately!

## Demo


https://github.com/user-attachments/assets/3b81752e-d7e5-4875-9864-92497333b23e

> [!NOTE]
>
> You can drag the search window to any of the four corners if its
getting in the way of reading the terminal.

## Known Issues

TODO prior to this PR merging:

- [x] Single-byte search terms cause a crash since our sliding window
can't handle it. This PR temporarily requires search terms with length
2+ before starting a search to avoid it. 😄
- [x] The way `ScreenSearch` prunes history is fundamental unsafe. With
a rapidly growing screen that could reach history limits and an active
search at the same time, Ghostty is almost guaranteed to crash
currently. The workaround is to not search actively scrolling screens
(new data) for now.
2025-11-26 09:09:55 -08:00
Mitchell Hashimoto
5b4394d211 macos: end_search for ending search 2025-11-26 08:57:24 -08:00
Mitchell Hashimoto
c51170da9c add end_search binding 2025-11-26 08:50:06 -08:00
Mitchell Hashimoto
f7b14a0142 macos: debounce search requests with length less than 3 2025-11-26 08:50:06 -08:00
Mitchell Hashimoto
339abf97f7 macos: can allow single char searches now 2025-11-26 08:50:06 -08:00
Mitchell Hashimoto
f91080a165 terminal: fix single-character search crashes 2025-11-26 08:50:06 -08:00
Mitchell Hashimoto
f252db1f1c terminal: handle pruning history for when active area removes it 2025-11-26 08:50:06 -08:00
Mitchell Hashimoto
330ce07d48 terminal: fix moving selection on history changing 2025-11-26 08:50:06 -08:00
Mitchell Hashimoto
ad755b0e3d core: always send start_search for refocus 2025-11-26 08:50:05 -08:00
Mitchell Hashimoto
1bb2d4f1c2 macos: only end search if we previously had one 2025-11-26 08:50:05 -08:00
Mitchell Hashimoto
48acc90983 terminal: search should reload active area if dirty 2025-11-26 08:50:05 -08:00
Mitchell Hashimoto
93656fca5a macos: show progerss correctly for search 2025-11-26 08:50:05 -08:00
Mitchell Hashimoto
0e974f85ed macos: fix iOS build 2025-11-26 08:50:05 -08:00
Mitchell Hashimoto
7320b234b4 core: surface sends search total/progress to apprt 2025-11-26 08:50:05 -08:00
Mitchell Hashimoto
c20af77f98 macos: handle search progress/total apprt actions 2025-11-26 08:50:05 -08:00
Mitchell Hashimoto
2ee2d000f5 apprt actions for search progress 2025-11-26 08:50:05 -08:00
Mitchell Hashimoto
d4a2f3db71 macos: search overlay shows search progress 2025-11-26 08:50:05 -08:00
Mitchell Hashimoto
7835ad0ea4 macos: more menu items 2025-11-26 08:50:05 -08:00
Mitchell Hashimoto
240d5e0fc5 config: default search keybindings for macos 2025-11-26 08:50:05 -08:00
Mitchell Hashimoto
3f7cfca4b4 macos: add find menu item 2025-11-26 08:50:05 -08:00
Mitchell Hashimoto
949a8ea53f macos: dummy search state for iOS 2025-11-26 08:50:05 -08:00
Mitchell Hashimoto
5b2d66e261 apprt/gtk: disable search apprt actions 2025-11-26 08:50:04 -08:00
Mitchell Hashimoto
cfbc219f5c macos: enter and shift+enter move the results 2025-11-26 08:50:04 -08:00
Mitchell Hashimoto
efc05523e0 macos: enter goes to next result 2025-11-26 08:50:04 -08:00
Mitchell Hashimoto
72708b8253 search: do not restart search if needle doesn't change 2025-11-26 08:50:04 -08:00
Mitchell Hashimoto
3ce19a02ba macos: hook up the next/prev search buttons 2025-11-26 08:50:04 -08:00
Mitchell Hashimoto
15f00a9cd1 renderer: setup proper dirty state on search selection changing 2025-11-26 08:50:04 -08:00
Mitchell Hashimoto
ad8a6e0642 search thread needs to take an allocated needle 2025-11-26 08:50:04 -08:00
Mitchell Hashimoto
5ee000f58f macos: search input starts the search up 2025-11-26 08:50:04 -08:00
Mitchell Hashimoto
081d73d850 macos: changes to SearchState trigger calls to internals 2025-11-26 08:50:04 -08:00
Mitchell Hashimoto
56d4a7f58e macos: start_search refocuses the search input 2025-11-26 08:50:04 -08:00
Mitchell Hashimoto
c61d28a3a4 macos: esc returns focus back to surface 2025-11-26 08:50:04 -08:00
Mitchell Hashimoto
b7e70ce534 apprt: end_search 2025-11-26 08:50:04 -08:00
Mitchell Hashimoto
b084889782 config: cmd+f on macos start_search default 2025-11-26 08:50:04 -08:00
Mitchell Hashimoto
bc44b187d6 macos: hook up start_search apprt action to open search 2025-11-26 08:50:04 -08:00
Mitchell Hashimoto
aeaa8d4ead add start_search binding and apprt action 2025-11-26 08:50:03 -08:00
Mitchell Hashimoto
b87d57f029 macos: search overlay 2025-11-26 08:50:03 -08:00
Mitchell Hashimoto
20758fb80e Misc search fixes (#9711)
- ScreenSearch has to restart on resize. We don't have any good way to
handle reflow since our search results are unpinned. We can look into
this later but this fixes correctness.
- PageList now tracks serial number by node that monotonically increases
on any alloc or reuse. Our screen search uses this to prune invalid
history results.
2025-11-26 08:49:54 -08:00
Mitchell Hashimoto
9b7753a36f terminal: ScreenSearch prunes by min serial 2025-11-26 08:46:26 -08:00
Mitchell Hashimoto
30f189d774 terminal: PageList has page_serial_min 2025-11-26 08:41:26 -08:00
Mitchell Hashimoto
e549af76fe terminal: flattened highlights contain serial numbers for nodes 2025-11-26 08:36:29 -08:00
Mitchell Hashimoto
1786022ac3 terminal: ScreenSearch restarts on resize 2025-11-26 08:31:09 -08:00