Skip to content

Commit 64a729e

Browse files
falcuccialex35mil
andauthored
feat: new keyboard shortcuts and handle select projects using tab (#8)
* feat: implement new keyboard shortcuts and handling methods in switcher window - add a swift gitignore file - update development team identifier in xcode project file - add a new togglefixedwindow keyboard shortcut - add a new case for `fixed` sort target in editorstore class - update command in editorstore class - add new togglefixedwindow handling method in switcherwindow class - add new navigateprojects method in switcherlistview struct * refactor: tab key logic and optimize binary files - refactor switcher list view logic for tab key press - update the calculation of `selectedindex` for tab key press * refactor: switcherview functionality - remove the `navigateprojects` function from `switcherlistview` in `switcherview.swift` - fix indentation in the `switcherlistview` struct in `switcherview.swift` * refactor: standardize keyboard shortcut terminology and functionality - change the keyboard shortcut name from `togglefixedwindow` to `togglepinnedwindow` in `app.swift` - update the `editorstore.swift` file to replace `fixed` with `pinned` in the `sorttarget` enum and related functions - modify the text and keyboard shortcut in the `settingsview.swift` file from `neohub hotkey` to `neovide hotkey` and change the shortcut from `togglefixedwindow` to `togglepinnedwindow` - refactor the `switcherwindow` class in `switcherview.swift` to use `togglepinnedwindow` instead of `togglefixedwindow` for keyboard shortcuts * chore: update development team in xcode project configuration - update `development_team` from `x8cnw77992` to `q62v4yp545` in `neohub.xcodeproj/project.pbxproj` multiple times * refactor: variable names across files - update a variable name from `fixed` to `pinned` in the `editorstore.swift` file * refactor: improved application behavior - removed redundant code related to editor activation - changed the behavior of hiding applications in specific scenarios * refactor: optimize editor handling in application - refactor `editorstore.swift` to always return the last used editor as pinned - remove unnecessary code in the `editorstore.swift` - refactor `switcherview.swift` to check if editors are not empty instead of counting them - remove redundant activation code in `switcherview.swift` - update a binary file `default.profraw` * refactor: improve handling of key press events in switcherview - change handling of key press event for `togglepinnedwindow` in `switcherview.swift` - binary files `default.profraw` were modified * refactor: key event handling in various files - update `development_team` setting from `q62v4yp545` to `x8cnw77992` in `neohub.xcodeproj` - change the key event from `onkeyup` to `onkeydown` in `switcherwindow` class in `switcherview.swift` * chore: update project settings and optimize binary files - update the `development_team` setting to q62v4yp545 in the project file - binary files `a/default.profraw` and `b/default.profraw` differ * style: standardize code formatting across project files - update the indentation of the closing brace * minor changes * - remove unnecessary whitespace in switcherview.swift * - add `dispatchqueue.main.async` to activate neovide first before activating nsapp - remove unnecessary code line in editorstore.swift - update default.profraw binary file * feat: file structure and add directory creation method - add a `createdirectoryifnotexists` method to the cli class - call `createdirectoryifnotexists` in the `perform` method - move the `createdirectoryifnotexists` implementation to the bottom of the cli.swift file. * refactor: toggle switcher window condition in switcherview - add a condition to toggle the switcher window if not already toggled in the switcherview.swift file - binary files differ in the default.profraw file * chore: update keyboard shortcuts and improve binary file handling - update the default keyboard shortcut for `togglepinnedwindow` - binary files `default.profraw` are different * refactor: address review comments --------- Co-authored-by: Alex Fedoseev <[email protected]>
1 parent b53307c commit 64a729e

File tree

6 files changed

+150
-3
lines changed

6 files changed

+150
-3
lines changed

.gitignore

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/swift
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=swift
3+
4+
### Swift ###
5+
# Xcode
6+
#
7+
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
8+
9+
## User settings
10+
xcuserdata/
11+
12+
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
13+
*.xcscmblueprint
14+
*.xccheckout
15+
16+
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
17+
build/
18+
DerivedData/
19+
*.moved-aside
20+
*.pbxuser
21+
!default.pbxuser
22+
*.mode1v3
23+
!default.mode1v3
24+
*.mode2v3
25+
!default.mode2v3
26+
*.perspectivev3
27+
!default.perspectivev3
28+
29+
## Obj-C/Swift specific
30+
*.hmap
31+
32+
## App packaging
33+
*.ipa
34+
*.dSYM.zip
35+
*.dSYM
36+
37+
## Playgrounds
38+
timeline.xctimeline
39+
playground.xcworkspace
40+
41+
# Swift Package Manager
42+
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
43+
# Packages/
44+
# Package.pins
45+
# Package.resolved
46+
*.xcodeproj
47+
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
48+
# hence it is not needed unless you have added a package configuration file to your project
49+
# .swiftpm
50+
51+
.build/
52+
53+
# CocoaPods
54+
# We recommend against adding the Pods directory to your .gitignore. However
55+
# you should judge for yourself, the pros and cons are mentioned at:
56+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
57+
# Pods/
58+
# Add this line if you want to avoid checking in source code from the Xcode workspace
59+
# *.xcworkspace
60+
61+
# Carthage
62+
# Add this line if you want to avoid checking in source code from Carthage dependencies.
63+
# Carthage/Checkouts
64+
65+
Carthage/Build/
66+
67+
# Accio dependency management
68+
Dependencies/
69+
.accio/
70+
71+
# fastlane
72+
# It is recommended to not store the screenshots in the git repo.
73+
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
74+
# For more information about the recommended setup visit:
75+
# https://docs.fastlane.tools/best-practices/source-control/#source-control
76+
77+
fastlane/report.xml
78+
fastlane/Preview.html
79+
fastlane/screenshots/**/*.png
80+
fastlane/test_output
81+
82+
# Code Injection
83+
# After new code Injection tools there's a generated folder /iOSInjectionProject
84+
# https://github.com/johnno1962/injectionforxcode
85+
86+
iOSInjectionProject/
87+
88+
# End of https://www.toptal.com/developers/gitignore/api/swift

NeoHub/App.swift

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ extension KeyboardShortcuts.Name {
1313
default: .init(.n, modifiers: [.command, .control])
1414
)
1515

16+
static let toggleLastActiveEditor = Self(
17+
"toggleLastActiveEditor",
18+
default: .init(.z, modifiers: [.command, .control])
19+
)
20+
1621
static let restartEditor = Self("restartEditor")
1722
}
1823

NeoHub/CLI.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ private struct Bin {
99
private struct Lib {
1010
static let source = Bundle.main.bundlePath + "/Contents/Frameworks/NeoHubLib.framework"
1111
static let destination = "/usr/local/lib/NeoHubLib.framework"
12+
13+
static var parent: String {
14+
return URL(fileURLWithPath: destination).deletingLastPathComponent().path
15+
}
1216
}
1317

1418
enum CLIOperation {
@@ -57,6 +61,7 @@ final class CLI: ObservableObject {
5761

5862
static func getStatus() -> CLIStatus {
5963
let fs = FileManager.default
64+
6065
let installed = fs.fileExists(atPath: Bin.destination) && fs.fileExists(atPath: Lib.destination)
6166

6267
if !installed {
@@ -83,7 +88,7 @@ final class CLI: ObservableObject {
8388
let script =
8489
switch operation {
8590
case .install:
86-
"do shell script \"cp -Rf \(Lib.source) \(Lib.destination) && cp -f \(Bin.source) \(Bin.destination)\" with administrator privileges"
91+
"do shell script \"mkdir -p \(Lib.parent) && cp -Rf \(Lib.source) \(Lib.destination) && cp -f \(Bin.source) \(Bin.destination)\" with administrator privileges"
8792
case .uninstall:
8893
"do shell script \"rm \(Bin.destination) && rm -rf \(Lib.destination)\" with administrator privileges"
8994
}

NeoHub/EditorStore.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ final class EditorStore: ObservableObject {
2424
public enum SortTarget {
2525
case menubar
2626
case switcher
27+
case lastActiveEditor
2728
}
2829

2930
public func getEditors() -> [Editor] {
@@ -36,6 +37,12 @@ final class EditorStore: ObservableObject {
3637
switch sortTarget {
3738
case .menubar:
3839
return editors.sorted { $0.name > $1.name }
40+
case .lastActiveEditor:
41+
if let lastActiveEditor = editors.max(by: { $0.lastAcceessTime < $1.lastAcceessTime }) {
42+
return [lastActiveEditor]
43+
} else {
44+
return []
45+
}
3946
case .switcher:
4047
var sorted = editors.sorted { $0.lastAcceessTime > $1.lastAcceessTime }
4148

@@ -330,7 +337,6 @@ final class Editor: Identifiable {
330337
NSApp.activate(ignoringOtherApps: true)
331338

332339
let activated = app.activate()
333-
334340
if !activated {
335341
let error = ReportableError("Failed to activate Neovide instance")
336342
log.error("\(error)")

NeoHub/views/SettingsView.swift

+8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ struct SettingsView: View {
3838
.padding(.horizontal)
3939
.padding(.vertical, 10)
4040

41+
HStack {
42+
Text("Toggle Last Active Editor")
43+
Spacer()
44+
KeyboardShortcuts.Recorder("", name: .toggleLastActiveEditor)
45+
}
46+
.padding(.horizontal)
47+
.padding(.vertical, 10)
48+
4149
Divider().padding(.horizontal)
4250

4351
HStack {

NeoHub/views/SwitcherView.swift

+36-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import KeyboardShortcuts
33

44
struct Key {
55
static let ESC: UInt16 = 53
6+
static let TAB: UInt16 = 48
67
static let ENTER: UInt16 = 36
78
static let ARROW_UP: UInt16 = 126
89
static let ARROW_DOWN: UInt16 = 125
@@ -106,11 +107,42 @@ final class SwitcherWindow: ObservableObject {
106107

107108
window.center()
108109

109-
KeyboardShortcuts.onKeyUp(for: .toggleSwitcher) { [self] in
110+
KeyboardShortcuts.onKeyDown(for: .toggleLastActiveEditor) { [self] in
111+
self.handleLastActiveEditorToggle()
112+
}
113+
114+
KeyboardShortcuts.onKeyDown(for: .toggleSwitcher) { [self] in
110115
self.handleSwitcherToggle()
111116
}
112117
}
113118

119+
private func handleLastActiveEditorToggle() {
120+
let editors = editorStore.getEditors(sortedFor: .lastActiveEditor)
121+
122+
if !editors.isEmpty {
123+
let editor = editors.first!
124+
let application = NSRunningApplication(processIdentifier: editor.processIdentifier)
125+
switch NSWorkspace.shared.frontmostApplication {
126+
case .some(let app):
127+
if app.processIdentifier == editor.processIdentifier {
128+
application?.hide()
129+
} else {
130+
activationManager.setActivationTarget(
131+
currentApp: app,
132+
switcherWindow: self.selfRef,
133+
editors: editors
134+
)
135+
application?.activate()
136+
}
137+
case .none:
138+
let application = NSRunningApplication(processIdentifier: editor.processIdentifier)
139+
application?.hide()
140+
}
141+
} else {
142+
self.toggle()
143+
}
144+
}
145+
114146
private func handleSwitcherToggle() {
115147
let editors = editorStore.getEditors()
116148

@@ -386,6 +418,9 @@ struct SwitcherListView: View {
386418
selectedIndex += 1
387419
}
388420
return nil
421+
case Key.TAB:
422+
selectedIndex = (selectedIndex + 1) % self.filterEditors().count
423+
return nil
389424
case Key.ENTER:
390425
let editors = self.filterEditors()
391426
if editors.indices.contains(selectedIndex) {

0 commit comments

Comments
 (0)