mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-15 22:12:20 +00:00
Ladybird/AppKit: Add a checkbox to enable case-sensitive find-in-page
This commit is contained in:
parent
778f323fc1
commit
3b56be61dc
Notes:
sideshowbarker
2024-07-18 03:20:18 +09:00
Author: https://github.com/trflynn89
Commit: 3b56be61dc
Pull-request: https://github.com/SerenityOS/serenity/pull/24501
3 changed files with 25 additions and 7 deletions
|
@ -60,7 +60,8 @@
|
||||||
|
|
||||||
- (void)setPreferredColorScheme:(Web::CSS::PreferredColorScheme)color_scheme;
|
- (void)setPreferredColorScheme:(Web::CSS::PreferredColorScheme)color_scheme;
|
||||||
|
|
||||||
- (void)findInPage:(NSString*)query;
|
- (void)findInPage:(NSString*)query
|
||||||
|
caseSensitivity:(CaseSensitivity)case_sensitivity;
|
||||||
- (void)findInPageNextMatch;
|
- (void)findInPageNextMatch;
|
||||||
- (void)findInPagePreviousMatch;
|
- (void)findInPagePreviousMatch;
|
||||||
|
|
||||||
|
|
|
@ -181,8 +181,9 @@ struct HideCursor {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)findInPage:(NSString*)query
|
- (void)findInPage:(NSString*)query
|
||||||
|
caseSensitivity:(CaseSensitivity)case_sensitivity
|
||||||
{
|
{
|
||||||
m_web_view_bridge->find_in_page(Ladybird::ns_string_to_string(query));
|
m_web_view_bridge->find_in_page(Ladybird::ns_string_to_string(query), case_sensitivity);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)findInPageNextMatch
|
- (void)findInPageNextMatch
|
||||||
|
|
|
@ -19,8 +19,12 @@ static constexpr CGFloat const SEARCH_FIELD_HEIGHT = 30;
|
||||||
static constexpr CGFloat const SEARCH_FIELD_WIDTH = 300;
|
static constexpr CGFloat const SEARCH_FIELD_WIDTH = 300;
|
||||||
|
|
||||||
@interface SearchPanel () <NSSearchFieldDelegate>
|
@interface SearchPanel () <NSSearchFieldDelegate>
|
||||||
|
{
|
||||||
|
CaseSensitivity m_case_sensitivity;
|
||||||
|
}
|
||||||
|
|
||||||
@property (nonatomic, strong) NSSearchField* search_field;
|
@property (nonatomic, strong) NSSearchField* search_field;
|
||||||
|
@property (nonatomic, strong) NSButton* search_match_case;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -45,6 +49,12 @@ static constexpr CGFloat const SEARCH_FIELD_WIDTH = 300;
|
||||||
[search_next setToolTip:@"Find Next Match"];
|
[search_next setToolTip:@"Find Next Match"];
|
||||||
[search_next setBordered:NO];
|
[search_next setBordered:NO];
|
||||||
|
|
||||||
|
self.search_match_case = [NSButton checkboxWithTitle:@"Match Case"
|
||||||
|
target:self
|
||||||
|
action:@selector(find:)];
|
||||||
|
[self.search_match_case setState:NSControlStateValueOff];
|
||||||
|
m_case_sensitivity = CaseSensitivity::CaseInsensitive;
|
||||||
|
|
||||||
auto* search_done = [NSButton buttonWithTitle:@"Done"
|
auto* search_done = [NSButton buttonWithTitle:@"Done"
|
||||||
target:self
|
target:self
|
||||||
action:@selector(cancelSearch:)];
|
action:@selector(cancelSearch:)];
|
||||||
|
@ -54,6 +64,7 @@ static constexpr CGFloat const SEARCH_FIELD_WIDTH = 300;
|
||||||
[self addView:self.search_field inGravity:NSStackViewGravityLeading];
|
[self addView:self.search_field inGravity:NSStackViewGravityLeading];
|
||||||
[self addView:search_previous inGravity:NSStackViewGravityLeading];
|
[self addView:search_previous inGravity:NSStackViewGravityLeading];
|
||||||
[self addView:search_next inGravity:NSStackViewGravityLeading];
|
[self addView:search_next inGravity:NSStackViewGravityLeading];
|
||||||
|
[self addView:self.search_match_case inGravity:NSStackViewGravityLeading];
|
||||||
[self addView:search_done inGravity:NSStackViewGravityTrailing];
|
[self addView:search_done inGravity:NSStackViewGravityTrailing];
|
||||||
|
|
||||||
[self setOrientation:NSUserInterfaceLayoutOrientationHorizontal];
|
[self setOrientation:NSUserInterfaceLayoutOrientationHorizontal];
|
||||||
|
@ -103,7 +114,7 @@ static constexpr CGFloat const SEARCH_FIELD_WIDTH = 300;
|
||||||
|
|
||||||
if (![self isHidden]) {
|
if (![self isHidden]) {
|
||||||
[self.search_field setStringValue:query];
|
[self.search_field setStringValue:query];
|
||||||
[[[self tab] web_view] findInPage:query];
|
[[[self tab] web_view] findInPage:query caseSensitivity:m_case_sensitivity];
|
||||||
|
|
||||||
[self.window makeFirstResponder:self.search_field];
|
[self.window makeFirstResponder:self.search_field];
|
||||||
}
|
}
|
||||||
|
@ -129,10 +140,15 @@ static constexpr CGFloat const SEARCH_FIELD_WIDTH = 300;
|
||||||
auto* query = [paste_board stringForType:NSPasteboardTypeString];
|
auto* query = [paste_board stringForType:NSPasteboardTypeString];
|
||||||
|
|
||||||
if (query) {
|
if (query) {
|
||||||
if (![[self.search_field stringValue] isEqual:query]) {
|
auto case_sensitivity = [self.search_match_case state] == NSControlStateValueOff
|
||||||
[self.search_field setStringValue:query];
|
? CaseSensitivity::CaseInsensitive
|
||||||
[[[self tab] web_view] findInPage:query];
|
: CaseSensitivity::CaseSensitive;
|
||||||
|
|
||||||
|
if (case_sensitivity != m_case_sensitivity || ![[self.search_field stringValue] isEqual:query]) {
|
||||||
|
[self.search_field setStringValue:query];
|
||||||
|
m_case_sensitivity = case_sensitivity;
|
||||||
|
|
||||||
|
[[[self tab] web_view] findInPage:query caseSensitivity:m_case_sensitivity];
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,7 +166,7 @@ static constexpr CGFloat const SEARCH_FIELD_WIDTH = 300;
|
||||||
- (void)controlTextDidChange:(NSNotification*)notification
|
- (void)controlTextDidChange:(NSNotification*)notification
|
||||||
{
|
{
|
||||||
auto* query = [self.search_field stringValue];
|
auto* query = [self.search_field stringValue];
|
||||||
[[[self tab] web_view] findInPage:query];
|
[[[self tab] web_view] findInPage:query caseSensitivity:m_case_sensitivity];
|
||||||
|
|
||||||
[self setPasteBoardContents:query];
|
[self setPasteBoardContents:query];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue