The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.
Arc parity: Edit ▸ Find ▸ Use Selection to Find and Jump to Selection (⌘J)
Victor894f1f649faf
diff --git a/Sources/Cra/App/AppDelegate.swift b/Sources/Cra/App/AppDelegate.swiftindex fea53b9..a35e0fe 100644--- a/Sources/Cra/App/AppDelegate.swift+++ b/Sources/Cra/App/AppDelegate.swift@@ -1318,6 +1318,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {case "find": main.showFindBar()case "findNext": main.findNext(forward: true)case "findPrevious": main.findNext(forward: false)+ case "useSelectionForFind": main.useSelectionForFind()+ case "jumpToSelection": main.jumpToSelection()case "toggleSidebar": main.toggleSidebar()case "toggleToolbar": store.settings.showToolbar.toggle()case "toggleDeveloperMode": if let url = store.selectedTab?.tab?.url { store.settings.toggleDeveloperMode(url: url) }@@ -1527,7 +1529,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {edit.addItem(std("Select All", #selector(NSText.selectAll(_:)), "a"))edit.addItem(.separator())let find = NSMenu(title: "Find")- find.addItem(item("find")); find.addItem(item("findNext")); find.addItem(item("findPrevious"))+ for id in ["find", "findNext", "findPrevious", "useSelectionForFind", "jumpToSelection"] { find.addItem(item(id)) }edit.addItem(submenu: find, title: "Find")menubar.addItem(submenu: edit, title: "Edit")diff --git a/Sources/Cra/App/KeyBindings.swift b/Sources/Cra/App/KeyBindings.swiftindex ea90656..5a0b1c2 100644--- a/Sources/Cra/App/KeyBindings.swift+++ b/Sources/Cra/App/KeyBindings.swift@@ -155,6 +155,9 @@ final class KeyBindingRegistry {KeyAction(id: "find", name: "Find…", section: .edit, shortcuts: [Shortcut("f", cmd)], triggers: ["find", "search page"]),KeyAction(id: "findNext", name: "Find Next", section: .edit, shortcuts: [Shortcut("g", cmd)], inCommandBar: false),KeyAction(id: "findPrevious", name: "Find Previous", section: .edit, shortcuts: [Shortcut("g", cmdShift)], inCommandBar: false),+ // Arc: Edit ▸ Find ▸ Use Selection to Find (no key: ⌘E opens extensions) and Jump to Selection ⌘J.+ KeyAction(id: "useSelectionForFind", name: "Use Selection to Find", section: .edit, shortcuts: [], inCommandBar: false),+ KeyAction(id: "jumpToSelection", name: "Jump to Selection", section: .edit, shortcuts: [Shortcut("j", cmd)], inCommandBar: false),// ViewKeyAction(id: "toggleSidebar", name: "Hide Sidebar", section: .view, shortcuts: [Shortcut("s", cmd)], triggers: ["sidebar", "hide sidebar", "show sidebar"]),KeyAction(id: "toggleToolbar", name: "Hide Toolbar", section: .view, shortcuts: [Shortcut("d", cmdShift)], triggers: ["toolbar"]),diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swiftindex c935e1a..de96579 100644--- a/Sources/Cra/UI/Windows/MainWindowController.swift+++ b/Sources/Cra/UI/Windows/MainWindowController.swift@@ -3128,6 +3128,31 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserMcurrentBrowser?.setFocused(true)}+ /// Arc's (and Chrome's) Edit ▸ Find ▸ Use Selection to Find: the page's selection becomes the+ /// search, on the find pasteboard too as macOS apps share it, and the bar finds it.+ func useSelectionForFind() {+ guard let b = currentBrowser else { return }+ b.sendDevToolsMethod("Runtime.evaluate", params: #"{"expression":"getSelection().toString()","returnByValue":true}"#) { [weak self] result, _ in+ MainActor.assumeIsolated {+ let o = result.flatMap { try? JSONSerialization.jsonObject(with: Data($0.utf8)) as? [String: Any] }+ let text = ((o?["result"] as? [String: Any])?["value"] as? String ?? "").trimmingCharacters(in: .whitespacesAndNewlines)+ guard let self, !text.isEmpty else { return }+ let pb = NSPasteboard(name: .find)+ pb.clearContents()+ pb.setString(text, forType: .string)+ self.overlay.findQuery = text+ self.showFindBar()+ self.find(text, forward: true)+ }+ }+ }++ /// Arc's (and Chrome's) Edit ▸ Find ▸ Jump to Selection (⌘J): the page scrolls its selection into view.+ func jumpToSelection() {+ currentBrowser?.executeJavaScript("(()=>{const s=getSelection();if(!s.rangeCount)return;const n=s.getRangeAt(0).startContainer;"+ + "(n.nodeType===1?n:n.parentElement)?.scrollIntoView({block:'center'});})()")+ }+func findNext(forward: Bool) {if !overlay.findVisible { showFindBar(); return }find(overlay.findQuery, forward: forward)diff --git a/Tests/Scenarios/find-selection.scenario b/Tests/Scenarios/find-selection.scenarionew file mode 100644index 0000000..e067295--- /dev/null+++ b/Tests/Scenarios/find-selection.scenario@@ -0,0 +1,13 @@+# Arc's Edit ▸ Find ▸ Jump to Selection (⌘J) and Use Selection to Find (Arc 1.172.1, also Chrome's):+# a selection far down the page comes into view, and becomes the find bar's search.+budget rss=700 stalls50=10+cra://open?url=${PAGE}?n=jump+expect-log loaded 127\.0\.0\.1 \(HTTP 200\)+cra://debug?cdp=Runtime.evaluate¶ms={"expression":"(()=>{const d=document.createElement('div');d.style.marginTop='4000px';d.textContent='far away words';document.body.append(d);scrollTo(0,0);const r=document.createRange();r.selectNodeContents(d);getSelection().removeAllRanges();getSelection().addRange(r);return 'sel-'+scrollY})()"}+expect-log Cra cdp Runtime.evaluate .*"value":"sel-0"+cra://action/jumpToSelection+wait 1+cra://debug?cdp=Runtime.evaluate¶ms={"expression":"'jumped-'+(scrollY>1000)"}+expect-log Cra cdp Runtime.evaluate .*"value":"jumped-true"+cra://action/useSelectionForFind+wait 1diff --git a/docs/arc-parity.md b/docs/arc-parity.mdindex a0cae6d..042fa8c 100644--- a/docs/arc-parity.md+++ b/docs/arc-parity.md@@ -27,7 +27,7 @@ or Arc-only service), per CONTRIBUTING.md.| Copy URL as Quote | Edit ▸ ⌃⇧⌘C, "Enable Shared Quotes when highlighting text" | done | Arc links to arc.net (cloud); Cra copies a text-fragment link. || AppleScript dictionary | Arc.sdef, View ▸ Developer ▸ Allow JavaScript from Apple Events | missing | Raycast and other launchers script Arc through it. || Cast | View ▸ Cast | done | Chrome's Cast bubble (IDC_ROUTE_MEDIA). |-| Find and Replace, Use Selection to Find, Jump to Selection | Edit ▸ Find | missing | |+| Find and Replace, Use Selection to Find, Jump to Selection | Edit ▸ Find | partial | Use Selection to Find and Jump to Selection (⌘J) done; Find and Replace is for Arc's Notes/Easels text, which Cra doesn't have. || Sound effects | Settings ▸ Advanced "Play Arc sound effects" | done | Settings ▸ Advanced ▸ Play Cra sound effects gates the capture shutter. || Theme data for websites | Settings ▸ Advanced "Allow websites to get your theme data" | done | `--arc-palette-*` and `--arc-background-*` as #RRGGBBAA, from the space's theme (ArcThemeData; fitted to Arc's stored palette, checked live). || Window dragging from the top of webpages | Settings ▸ Advanced | measured | With the toolbar hidden, Arc drags the window from the top 56 pt of the page (66 pt below the window's top); 58 pt in, the page gets the drag. Cra's strip reaches 4 pt into the page. Needs clicks in that band held until the pointer moves, across Chromium's page windows. |@@ -122,6 +122,7 @@ in this sweep (Essential Shortcuts window, Library pages).- Settings ▸ Advanced ▸ "Allow websites to get your theme data": Arc's `--arc-palette-*` variables,measured live in Arc (names, #RRGGBBAA format, no trace in the page's markup) and fitted to thesemantic palette Arc stores per space.+- Edit ▸ Find ▸ Use Selection to Find and Jump to Selection (⌘J).## Left for later, and why@@ -130,5 +131,5 @@ in this sweep (Essential Shortcuts window, Library pages).a localhost server).- Easels and Notes: whole document types with their own editors; same approach once Boosts is in.- AppleScript dictionary (a new way for other apps to drive Cra; worth a decision on what it may do,- as for cra:// URLs), Find and Replace, cookie banner blocking, window dragging from the top of pages (measured, above), Previews and+ as for cra:// URLs), cookie banner blocking, window dragging from the top of pages (measured, above), Previews andJoin Meeting: not started.