Skip to content

Commit

Permalink
Merge branch 'raw' of github.com:blinksh/blink into raw
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Dec 23, 2019
2 parents 464fd1e + ca700a8 commit a0f7474
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 30 deletions.
28 changes: 27 additions & 1 deletion Blink/SmarterKeys/SmarterTermInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,9 @@ extension SmarterTermInput {
case #selector(UIResponder.paste(_:)):
return sender != nil
case #selector(UIResponder.copy(_:)),
#selector(TermView.pasteSelection(_:)):
#selector(TermView.pasteSelection(_:)),
#selector(Self.soSelection(_:)),
#selector(Self.googleSelection(_:)):
return sender != nil && device?.view?.hasSelection == true
case #selector(Self.copyLink(_:)),
#selector(Self.openLink(_:)):
Expand Down Expand Up @@ -602,6 +604,30 @@ extension SmarterTermInput {
@objc func pasteSelection(_ sender: Any) {
device?.view?.pasteSelection(sender)
}

@objc func googleSelection(_ sender: Any) {
guard
let deviceView = device?.view,
let query = deviceView.selectedText?.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed),
let url = URL(string: "https://google.com/search?q=\(query)")
else {
return
}

blink_openurl(url)
}

@objc func soSelection(_ sender: Any) {
guard
let deviceView = device?.view,
let query = deviceView.selectedText?.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed),
let url = URL(string: "https://stackoverflow.com/search?q=\(query)")
else {
return
}

blink_openurl(url)
}
}


Expand Down
2 changes: 2 additions & 0 deletions Blink/SpaceController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ extension SpaceController {
case .windowNew: _newWindowAction()
case .clipboardCopy: SmarterTermInput.shared.copy(self)
case .clipboardPaste: SmarterTermInput.shared.paste(self)
case .selectionGoogle: SmarterTermInput.shared.googleSelection(self)
case .selectionStackOverflow: SmarterTermInput.shared.soSelection(self)
case .zoomIn: currentTerm()?.termDevice.view?.increaseFontSize()
case .zoomOut: currentTerm()?.termDevice.view?.decreaseFontSize()
case .zoomReset: currentTerm()?.termDevice.view?.resetFontSize()
Expand Down
13 changes: 13 additions & 0 deletions Blink/TermView.m
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,11 @@ - (void)_handleSelectionChange:(NSDictionary *)data
[self _menuActionTitleFromNSURL:_detectedLink], urlName];
[items addObject:[[UIMenuItem alloc] initWithTitle:actionTitle
action:@selector(openLink:)]];
} else {
[items addObject:[[UIMenuItem alloc] initWithTitle:@"Google"
action:@selector(googleSelection:)]];
[items addObject:[[UIMenuItem alloc] initWithTitle:@"SO"
action:@selector(soSelection:)]];
}


Expand Down Expand Up @@ -546,6 +551,14 @@ - (void)openLink:(id)sender
- (void)yank:(id)sender
{
}

- (void)googleSelection:(id)sender {

}

- (void)soSelection:(id)sender {

}

- (void)pasteSelection:(id)sender
{
Expand Down
62 changes: 33 additions & 29 deletions KB/Native/Model/KeyBindingAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,39 +58,43 @@ enum Command: String, Codable, CaseIterable {
case zoomReset
case clipboardCopy
case clipboardPaste
case selectionGoogle
case selectionStackOverflow
case configShow

var title: String {
switch self {
case .windowNew: return "New Window"
case .windowClose: return "Close Window"
case .windowFocusOther: return "Focus on other Window"
case .tabNew: return "New tab"
case .tabClose: return "Close tab"
case .tabNext: return "Next tab"
case .tabNextCycling: return "Next tab (cycling)"
case .tabPrev: return "Previous tab"
case .tabPrevCycling: return "Previous tab (cycling)"
case .tab1: return "Switch to tab 1"
case .tab2: return "Switch to tab 2"
case .tab3: return "Switch to tab 3"
case .tab4: return "Switch to tab 4"
case .tab5: return "Switch to tab 5"
case .tab6: return "Switch to tab 6"
case .tab7: return "Switch to tab 7"
case .tab8: return "Switch to tab 8"
case .tab9: return "Switch to tab 9"
case .tab10: return "Switch to tab 10"
case .tab11: return "Switch to tab 11"
case .tab12: return "Switch to tab 12"
case .tabLast: return "Switch to last tab"
case .tabMoveToOtherWindow: return "Move tab to other Window"
case .zoomIn: return "Zoom In"
case .zoomOut: return "Zoom Out"
case .zoomReset: return "Zoom Reset"
case .clipboardCopy: return "Copy"
case .clipboardPaste: return "Paste"
case .configShow: return "Show Config"
case .windowNew: return "New Window"
case .windowClose: return "Close Window"
case .windowFocusOther: return "Focus on other Window"
case .tabNew: return "New tab"
case .tabClose: return "Close tab"
case .tabNext: return "Next tab"
case .tabNextCycling: return "Next tab (cycling)"
case .tabPrev: return "Previous tab"
case .tabPrevCycling: return "Previous tab (cycling)"
case .tab1: return "Switch to tab 1"
case .tab2: return "Switch to tab 2"
case .tab3: return "Switch to tab 3"
case .tab4: return "Switch to tab 4"
case .tab5: return "Switch to tab 5"
case .tab6: return "Switch to tab 6"
case .tab7: return "Switch to tab 7"
case .tab8: return "Switch to tab 8"
case .tab9: return "Switch to tab 9"
case .tab10: return "Switch to tab 10"
case .tab11: return "Switch to tab 11"
case .tab12: return "Switch to tab 12"
case .tabLast: return "Switch to last tab"
case .tabMoveToOtherWindow: return "Move tab to other Window"
case .zoomIn: return "Zoom In"
case .zoomOut: return "Zoom Out"
case .zoomReset: return "Zoom Reset"
case .clipboardCopy: return "Copy"
case .clipboardPaste: return "Paste"
case .selectionGoogle: return "Google Selection"
case .selectionStackOverflow: return "StackOverflow Selection"
case .configShow: return "Show Config"
}
}
}
Expand Down

0 comments on commit a0f7474

Please sign in to comment.