-
Notifications
You must be signed in to change notification settings - Fork 47
Add HighlightedTextManager and pull highlighted text logic into it #368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1db5b26
Add HighlightedTextManager and pull highlighted text logic into it
timlenardo 1959fd7
Add HighlightedTextManager and pull highlighted text logic into it
timlenardo 610edd2
Apply suggestion from @greptile-apps[bot]
timlenardo e85110a
Review fixes
Niduank 0502615
address nits
timlenardo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
macos/Onit/StateManagers/HighlightedText/HighlightedTextConfig.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // | ||
| // HighlightedTextConfig.swift | ||
| // Onit | ||
| // | ||
| // Created by Kévin Naudin on 28/04/2025. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| struct HighlightedTextConfig { | ||
| static let textSelectionDebounceInterval: TimeInterval = 0.15 // 150ms | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should remove the vestigial |
||
| } | ||
File renamed without changes.
50 changes: 50 additions & 0 deletions
50
macos/Onit/StateManagers/HighlightedText/HighlightedTextManager+Delegates.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // | ||
| // HighlightedTextManager+Delegates.swift | ||
| // Onit | ||
| // | ||
| // Created by TimL on 28/04/2025. | ||
| // | ||
|
|
||
| import ApplicationServices | ||
|
|
||
| extension HighlightedTextManager: AccessibilityNotificationsDelegate { | ||
| // MARK: - AccessibilityNotificationsDelegate Implementation | ||
| func accessibilityManager(_ manager: AccessibilityNotificationsManager, didChangeSelection element: AXUIElement) { | ||
| handleSelectionChange(for: element) | ||
| } | ||
|
|
||
| func accessibilityManager(_ manager: AccessibilityNotificationsManager, didChangeFocusedUIElement element: AXUIElement) { | ||
| handleCaretPositionChange(for: element) | ||
| } | ||
|
|
||
| // Unused stubs | ||
| func accessibilityManager(_ manager: AccessibilityNotificationsManager, didActivateWindow window: TrackedWindow) {} | ||
| func accessibilityManager(_ manager: AccessibilityNotificationsManager, didActivateIgnoredWindow window: TrackedWindow?) {} | ||
| func accessibilityManager(_ manager: AccessibilityNotificationsManager, didMinimizeWindow window: TrackedWindow) {} | ||
| func accessibilityManager(_ manager: AccessibilityNotificationsManager, didDeminimizeWindow window: TrackedWindow) {} | ||
| func accessibilityManager(_ manager: AccessibilityNotificationsManager, didDestroyWindow window: TrackedWindow) {} | ||
| func accessibilityManager(_ manager: AccessibilityNotificationsManager, didMoveWindow window: TrackedWindow) {} | ||
| func accessibilityManager(_ manager: AccessibilityNotificationsManager, didResizeWindow window: TrackedWindow) {} | ||
| func accessibilityManager(_ manager: AccessibilityNotificationsManager, didChangeWindowTitle window: TrackedWindow) {} | ||
| } | ||
|
|
||
| extension HighlightedTextManager: AccessibilityObserversDelegate { | ||
|
|
||
| func accessibilityObserversManager(didActivateApplication appName: String?, processID: pid_t) { | ||
| setCurrentSource(appName) | ||
| } | ||
|
|
||
| func accessibilityObserversManager(didDeactivateApplication appName: String?, processID: pid_t) { | ||
| // Reset state when app deactivates | ||
| reset() | ||
| } | ||
|
|
||
| func accessibilityObserversManager(didActivateIgnoredApplication appName: String?, processID: pid_t) {} | ||
| func accessibilityObserversManager(didReceiveNotification notification: String, | ||
| element: AXUIElement, | ||
| elementPid: pid_t, | ||
| info: [String: Any]) {} | ||
| func accessibilityObserversManager(didDeactivateIgnoredApplication appName: String?, processID: pid_t) {} | ||
| func accessibilityObserversManager(didActivateOnit processID: pid_t) {} | ||
| func accessibilityObserversManager(didDeactivateOnit processID: pid_t) {} | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@timlenardo I replaced the
// wutby this call.Without this call, unhighlight is not working on Notes, iTerm2.
I know that it breaks the separation of layers.
The other way to handle it is to make
AXUIElementoptional inhandleSelectionChange, delegate etc ...I started doing that but stopped when I reached this code in
AccessibilityNotificationsManager:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the problem. My only other idea is:
I think this would be nicer, because a) we can completely dissociate HighlightedTextManger from AccessibilityNotificationManager b) we may avoid some race conditions by reading the selectedText() as soon as the notification comes through. Currently, it's up to the AXNotifDelegate to read the selectedText(), but if there's anything asynchronous in the callstack, the value may change. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like
didChangeSelectionis only used by theHighlightedTextManager(all other implementations are stubs), in which case, can't we just make it so thatAXUIElementcan benilfor :AccessibilityNotificationsManager.handleSelectionChange()AccessibilityNotificationsDelegate.accessibilityManager(_ manager..., didChangeSelection: ...)HighlightedTextManager.handleSelectionChange()And then, in
HighlightedTextManager.handleSelectionChange(), we can add aguardclause that setsselectedTexttonilwhenelementisnil:And then all we'd have to do in
AccessibilityNotificationsManager.handleAppActivation()is replacewith
And update the
guardclause innotifyDelegatefrom:to
And then update the stubs to take in an optional
AXUIElementfor thedidChangeSelectionnotification.I don't think this should break anything, as
HighlightedTextManageris the only one that's actually processing thekAXSelectedTextChangedNotification.Is this what you were referring to @Niduank ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lk340 - the issue is in
notifyDelegatesin AccessibilityNotificationsManager, where we check the processID before sending the notification. If we have a nil AXUIElement, we won't know which process it's from, so we will always send the notification. That would be okay for now, since only Notes and iTerm2 use the HighlightedTextPoller. But it would break if want to add any app using the HighlightedTextPoller to the ignoredApps list. In this case, we'd send the notification to all delegates, even if the app should be ignored.