From 72f6208ab20f1691ddaf4ee7de539bbf4b6dec82 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Mon, 15 May 2017 22:25:49 +0200 Subject: [PATCH 01/10] Bump version: snapshot/194 --- MacNeovim/Info.plist | 4 ++-- OutlineViewTest/Info.plist | 4 ++-- SwiftNeoVim/Info.plist | 4 ++-- SwiftNeoVimTests/Info.plist | 4 ++-- VimR-Workspace-Demo/Info.plist | 4 ++-- VimR.xcodeproj/project.pbxproj | 8 ++++---- VimR/Info.plist | 4 ++-- VimRTests/Info.plist | 4 ++-- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/MacNeovim/Info.plist b/MacNeovim/Info.plist index 05508321..669e3af1 100644 --- a/MacNeovim/Info.plist +++ b/MacNeovim/Info.plist @@ -17,9 +17,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - SNAPSHOT-193 + SNAPSHOT-194 CFBundleVersion - 193 + 194 LSApplicationCategoryType public.app-category.productivity LSMinimumSystemVersion diff --git a/OutlineViewTest/Info.plist b/OutlineViewTest/Info.plist index e60b1496..77b86832 100644 --- a/OutlineViewTest/Info.plist +++ b/OutlineViewTest/Info.plist @@ -17,9 +17,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - SNAPSHOT-193 + SNAPSHOT-194 CFBundleVersion - 193 + 194 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright diff --git a/SwiftNeoVim/Info.plist b/SwiftNeoVim/Info.plist index 4927c453..b55c893f 100644 --- a/SwiftNeoVim/Info.plist +++ b/SwiftNeoVim/Info.plist @@ -15,11 +15,11 @@ CFBundlePackageType FMWK CFBundleShortVersionString - SNAPSHOT-193 + SNAPSHOT-194 CFBundleSignature ???? CFBundleVersion - 193 + 194 NSHumanReadableCopyright Copyright © 2016 Tae Won Ha. All rights reserved. NSPrincipalClass diff --git a/SwiftNeoVimTests/Info.plist b/SwiftNeoVimTests/Info.plist index 65d3bbf8..31ddbb27 100644 --- a/SwiftNeoVimTests/Info.plist +++ b/SwiftNeoVimTests/Info.plist @@ -15,10 +15,10 @@ CFBundlePackageType BNDL CFBundleShortVersionString - SNAPSHOT-193 + SNAPSHOT-194 CFBundleSignature ???? CFBundleVersion - 193 + 194 diff --git a/VimR-Workspace-Demo/Info.plist b/VimR-Workspace-Demo/Info.plist index d5fcba19..b359400b 100644 --- a/VimR-Workspace-Demo/Info.plist +++ b/VimR-Workspace-Demo/Info.plist @@ -17,11 +17,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - SNAPSHOT-193 + SNAPSHOT-194 CFBundleSignature ???? CFBundleVersion - 193 + 194 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright diff --git a/VimR.xcodeproj/project.pbxproj b/VimR.xcodeproj/project.pbxproj index 1f628459..62497a6b 100644 --- a/VimR.xcodeproj/project.pbxproj +++ b/VimR.xcodeproj/project.pbxproj @@ -1693,7 +1693,7 @@ COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 193; + DYLIB_CURRENT_VERSION = 194; DYLIB_INSTALL_NAME_BASE = "@rpath"; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -1718,7 +1718,7 @@ COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 193; + DYLIB_CURRENT_VERSION = 194; DYLIB_INSTALL_NAME_BASE = "@rpath"; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -1953,7 +1953,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 193; + CURRENT_PROJECT_VERSION = 194; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -2003,7 +2003,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 193; + CURRENT_PROJECT_VERSION = 194; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; diff --git a/VimR/Info.plist b/VimR/Info.plist index 38396b75..7466b86f 100644 --- a/VimR/Info.plist +++ b/VimR/Info.plist @@ -32,7 +32,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - SNAPSHOT-193 + SNAPSHOT-194 CFBundleSignature ???? CFBundleURLTypes @@ -49,7 +49,7 @@ CFBundleVersion - 193 + 194 LSApplicationCategoryType public.app-category.productivity LSMinimumSystemVersion diff --git a/VimRTests/Info.plist b/VimRTests/Info.plist index 65d3bbf8..31ddbb27 100644 --- a/VimRTests/Info.plist +++ b/VimRTests/Info.plist @@ -15,10 +15,10 @@ CFBundlePackageType BNDL CFBundleShortVersionString - SNAPSHOT-193 + SNAPSHOT-194 CFBundleSignature ???? CFBundleVersion - 193 + 194 From f09999e521ac0f24b3e93330e8e37ba295a41533 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Mon, 15 May 2017 22:29:38 +0200 Subject: [PATCH 02/10] Bump appcast to SNAPSHOT-194 --- appcast_snapshot.xml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/appcast_snapshot.xml b/appcast_snapshot.xml index ce32a030..a62ff5ef 100644 --- a/appcast_snapshot.xml +++ b/appcast_snapshot.xml @@ -7,22 +7,22 @@ Most recent changes with links to updates for VimR. en - SNAPSHOT-193 + SNAPSHOT-194 -
  • GH-430: Bugfix: The cursor disappears when using arrow keys in the command mode.
  • +
  • GH-450: Mild file browser refactoring
  • ]]>
    - https://github.com/qvacua/vimr/releases/tag/snapshot/193 + https://github.com/qvacua/vimr/releases/tag/snapshot/194 - 2017-05-12T23:20:22.770207 + 2017-05-15T22:29:37.978411 10.10.0 -
    From a27001ab7f575bd206c11d07d4c5b7077c82725b Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Mon, 15 May 2017 23:17:19 +0200 Subject: [PATCH 03/10] Make a function fileprivate --- VimR/MainWindow.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/VimR/MainWindow.swift b/VimR/MainWindow.swift index e5d28441..095a0b77 100644 --- a/VimR/MainWindow.swift +++ b/VimR/MainWindow.swift @@ -241,10 +241,6 @@ class MainWindow: NSObject, self.windowController.showWindow(self) } - func closeAllNeoVimWindowsWithoutSaving() { - self.neoVimView.closeAllWindowsWithoutSaving() - } - fileprivate let emit: (UuidAction) -> Void fileprivate let disposeBag = DisposeBag() @@ -284,6 +280,10 @@ class MainWindow: NSObject, fileprivate var isClosing = false + fileprivate func closeAllNeoVimWindowsWithoutSaving() { + self.neoVimView.closeAllWindowsWithoutSaving() + } + fileprivate func updateNeoVimAppearance() { self.neoVimView.font = self.defaultFont self.neoVimView.linespacing = self.linespacing From bbce00c6ef9ab6e790c6d81124911409add35811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ku=CC=88hl?= Date: Wed, 17 May 2017 14:16:01 +0200 Subject: [PATCH 04/10] Support shift modifier on special keys The NeoVimView.vimModifierFlags method only checks for the control, option, and command modifiers, which leads to the shift modifier getting lost. This change mitigates that by checking for the shift modifier and translating it to the `S-` key prefix. This change has the possible side effect of requiring additional `S-` prefixes, depending on the keyboard layout. For example, take a US keyboard with a -/_ key and press that key with control and shift depressed. Before this change, VimR would transmit ``, while after this change it transmits ``. --- SwiftNeoVim/NeoVimView.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SwiftNeoVim/NeoVimView.swift b/SwiftNeoVim/NeoVimView.swift index af969f6a..7bb44487 100644 --- a/SwiftNeoVim/NeoVimView.swift +++ b/SwiftNeoVim/NeoVimView.swift @@ -1036,6 +1036,7 @@ extension NeoVimView: NSTextInputClient { let control = modifierFlags.contains(.control) let option = modifierFlags.contains(.option) let command = modifierFlags.contains(.command) + let shift = modifierFlags.contains(.shift) if control { result += "C-" @@ -1049,6 +1050,10 @@ extension NeoVimView: NSTextInputClient { result += "D-" } + if shift { + result += "S-" + } + if result.characters.count > 0 { return result } From c8a8c3b93d3ea7c591f5dfe5a180d6f00bd63fbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ku=CC=88hl?= Date: Wed, 17 May 2017 14:31:37 +0200 Subject: [PATCH 05/10] Add (Shift-)Tab as a special key MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pressing Shift+Tab generates an NSEvent with characters `"\u{19}"` (and the shift modifier), which the backend doesn’t recognise as the Tab key. (Instead it gets mapped as , which makes sense given how ASCII control characters are interpreted.) This change fixes that by adding a corresponding entry to the KeyUtils.specialKeys dict. Of course sending still works because it is transmitted as ``. --- SwiftNeoVim/KeyUtils.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/SwiftNeoVim/KeyUtils.swift b/SwiftNeoVim/KeyUtils.swift index 0d948fcb..cf890b8b 100644 --- a/SwiftNeoVim/KeyUtils.swift +++ b/SwiftNeoVim/KeyUtils.swift @@ -56,6 +56,7 @@ class KeyUtils { NSF33FunctionKey: "F33", NSF34FunctionKey: "F34", NSF35FunctionKey: "F35", + 0x19: "Tab", ] static func isSpecial(key: String) -> Bool { From c25034da7dfa7ce4c1e321913f63629eb1b695a7 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Tue, 16 May 2017 22:54:49 +0200 Subject: [PATCH 06/10] Only update when not reloading --- VimR/FileOutlineView.swift | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/VimR/FileOutlineView.swift b/VimR/FileOutlineView.swift index acbdaa52..a6641b0f 100644 --- a/VimR/FileOutlineView.swift +++ b/VimR/FileOutlineView.swift @@ -39,9 +39,8 @@ class FileOutlineView: NSOutlineView, self.doubleAction = #selector(FileOutlineView.doubleClickAction) source - .filter { state in - return state.lastFileSystemUpdate.mark != self.lastFileSystemUpdateMark - } + .filter { !self.reloadData(for: $0) } + .filter { $0.lastFileSystemUpdate.mark != self.lastFileSystemUpdateMark } .throttle(2 * FileMonitor.fileSystemEventsLatency + 1, latest: true, scheduler: SerialDispatchQueueScheduler(qos: .background)) @@ -59,25 +58,14 @@ class FileOutlineView: NSOutlineView, self.beFirstResponder() } - var reloadData = false - - if self.isShowHidden != state.fileBrowserShowHidden { - self.isShowHidden = state.fileBrowserShowHidden - reloadData = true - } - - if state.cwd != self.cwd { - self.lastFileSystemUpdateMark = state.lastFileSystemUpdate.mark - self.root = FileBrowserItem(state.cwd) - - reloadData = true - } - - if reloadData { - self.lastFileSystemUpdateMark = state.lastFileSystemUpdate.mark - self.reloadData() + guard self.reloadData(for: state) else { return } + + self.isShowHidden = state.fileBrowserShowHidden + self.lastFileSystemUpdateMark = state.lastFileSystemUpdate.mark + self.root = FileBrowserItem(state.cwd) + self.reloadData() }) .disposed(by: self.disposeBag) } @@ -128,6 +116,18 @@ class FileOutlineView: NSOutlineView, fatalError("init(coder:) has not been implemented") } + fileprivate func reloadData(for state: StateType) -> Bool { + if self.isShowHidden != state.fileBrowserShowHidden { + return true + } + + if state.cwd != self.cwd { + return true + } + + return false + } + fileprivate func update(_ url: URL) { guard let fileBrowserItem = self.fileBrowserItem(with: url) else { return From bc2fcd76eaf10931d1e4ccfeaee83532bc62804f Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Wed, 17 May 2017 19:38:15 +0200 Subject: [PATCH 07/10] Bump version: snapshot/195 --- MacNeovim/Info.plist | 4 ++-- OutlineViewTest/Info.plist | 4 ++-- SwiftNeoVim/Info.plist | 4 ++-- SwiftNeoVimTests/Info.plist | 4 ++-- VimR-Workspace-Demo/Info.plist | 4 ++-- VimR.xcodeproj/project.pbxproj | 8 ++++---- VimR/Info.plist | 4 ++-- VimRTests/Info.plist | 4 ++-- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/MacNeovim/Info.plist b/MacNeovim/Info.plist index 669e3af1..5b1897c0 100644 --- a/MacNeovim/Info.plist +++ b/MacNeovim/Info.plist @@ -17,9 +17,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - SNAPSHOT-194 + SNAPSHOT-195 CFBundleVersion - 194 + 195 LSApplicationCategoryType public.app-category.productivity LSMinimumSystemVersion diff --git a/OutlineViewTest/Info.plist b/OutlineViewTest/Info.plist index 77b86832..d0855670 100644 --- a/OutlineViewTest/Info.plist +++ b/OutlineViewTest/Info.plist @@ -17,9 +17,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - SNAPSHOT-194 + SNAPSHOT-195 CFBundleVersion - 194 + 195 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright diff --git a/SwiftNeoVim/Info.plist b/SwiftNeoVim/Info.plist index b55c893f..aab7003a 100644 --- a/SwiftNeoVim/Info.plist +++ b/SwiftNeoVim/Info.plist @@ -15,11 +15,11 @@ CFBundlePackageType FMWK CFBundleShortVersionString - SNAPSHOT-194 + SNAPSHOT-195 CFBundleSignature ???? CFBundleVersion - 194 + 195 NSHumanReadableCopyright Copyright © 2016 Tae Won Ha. All rights reserved. NSPrincipalClass diff --git a/SwiftNeoVimTests/Info.plist b/SwiftNeoVimTests/Info.plist index 31ddbb27..839c531f 100644 --- a/SwiftNeoVimTests/Info.plist +++ b/SwiftNeoVimTests/Info.plist @@ -15,10 +15,10 @@ CFBundlePackageType BNDL CFBundleShortVersionString - SNAPSHOT-194 + SNAPSHOT-195 CFBundleSignature ???? CFBundleVersion - 194 + 195 diff --git a/VimR-Workspace-Demo/Info.plist b/VimR-Workspace-Demo/Info.plist index b359400b..280e1777 100644 --- a/VimR-Workspace-Demo/Info.plist +++ b/VimR-Workspace-Demo/Info.plist @@ -17,11 +17,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - SNAPSHOT-194 + SNAPSHOT-195 CFBundleSignature ???? CFBundleVersion - 194 + 195 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright diff --git a/VimR.xcodeproj/project.pbxproj b/VimR.xcodeproj/project.pbxproj index 62497a6b..e9ffa78d 100644 --- a/VimR.xcodeproj/project.pbxproj +++ b/VimR.xcodeproj/project.pbxproj @@ -1693,7 +1693,7 @@ COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 194; + DYLIB_CURRENT_VERSION = 195; DYLIB_INSTALL_NAME_BASE = "@rpath"; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -1718,7 +1718,7 @@ COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 194; + DYLIB_CURRENT_VERSION = 195; DYLIB_INSTALL_NAME_BASE = "@rpath"; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -1953,7 +1953,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 194; + CURRENT_PROJECT_VERSION = 195; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -2003,7 +2003,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 194; + CURRENT_PROJECT_VERSION = 195; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; diff --git a/VimR/Info.plist b/VimR/Info.plist index 7466b86f..f6a98036 100644 --- a/VimR/Info.plist +++ b/VimR/Info.plist @@ -32,7 +32,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - SNAPSHOT-194 + SNAPSHOT-195 CFBundleSignature ???? CFBundleURLTypes @@ -49,7 +49,7 @@ CFBundleVersion - 194 + 195 LSApplicationCategoryType public.app-category.productivity LSMinimumSystemVersion diff --git a/VimRTests/Info.plist b/VimRTests/Info.plist index 31ddbb27..839c531f 100644 --- a/VimRTests/Info.plist +++ b/VimRTests/Info.plist @@ -15,10 +15,10 @@ CFBundlePackageType BNDL CFBundleShortVersionString - SNAPSHOT-194 + SNAPSHOT-195 CFBundleSignature ???? CFBundleVersion - 194 + 195 From cf919ba9c4cf9f1b54cf85d6cdd7505a94a045c6 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Wed, 17 May 2017 19:40:40 +0200 Subject: [PATCH 08/10] Bump appcast to SNAPSHOT-195 --- appcast_snapshot.xml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/appcast_snapshot.xml b/appcast_snapshot.xml index a62ff5ef..280168cf 100644 --- a/appcast_snapshot.xml +++ b/appcast_snapshot.xml @@ -7,22 +7,22 @@ Most recent changes with links to updates for VimR. en - SNAPSHOT-194 + SNAPSHOT-195 -
  • GH-450: Mild file browser refactoring
  • +
  • GH-403, GH-447: Shift-Tab works (thanks to @mkhl)
  • ]]>
    - https://github.com/qvacua/vimr/releases/tag/snapshot/194 + https://github.com/qvacua/vimr/releases/tag/snapshot/195 - 2017-05-15T22:29:37.978411 + 2017-05-17T19:40:40.275108 10.10.0 -
    From 5430834773796e00c6940942c7af6b0b68ec6aa2 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Wed, 17 May 2017 19:26:30 +0200 Subject: [PATCH 09/10] Update release notes --- resources/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/release-notes.md b/resources/release-notes.md index e8819263..7f7b1450 100644 --- a/resources/release-notes.md +++ b/resources/release-notes.md @@ -3,6 +3,7 @@ * GH-395: Bugfix: Massive file system changes in the working directory causes VimR to freeze. * GH-430: Bugfix: The cursor disappears when using arrow keys in the command mode. * GH-450: Mild file browser refactoring +* GH-403, GH-447: `Shift-Tab` works (thanks to @mkhl) # 0.15.0-191 From 53bed4540a0dc1b0df814d1c5ae6cb897a948747 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Wed, 17 May 2017 21:57:16 +0200 Subject: [PATCH 10/10] Make special keys file private --- SwiftNeoVim/KeyUtils.swift | 112 ++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 57 deletions(-) diff --git a/SwiftNeoVim/KeyUtils.swift b/SwiftNeoVim/KeyUtils.swift index cf890b8b..5b386982 100644 --- a/SwiftNeoVim/KeyUtils.swift +++ b/SwiftNeoVim/KeyUtils.swift @@ -7,77 +7,75 @@ import Cocoa class KeyUtils { - static let specialKeys = [ - NSUpArrowFunctionKey: "Up", - NSDownArrowFunctionKey: "Down", - NSLeftArrowFunctionKey: "Left", - NSRightArrowFunctionKey: "Right", - NSInsertFunctionKey: "Insert", - 0x7F: "BS", // "delete"-key - NSDeleteFunctionKey: "Del", // "Fn+delete"-key - NSHomeFunctionKey: "Home", - NSBeginFunctionKey: "Begin", - NSEndFunctionKey: "End", - NSPageUpFunctionKey: "PageUp", - NSPageDownFunctionKey: "PageDown", - NSHelpFunctionKey: "Help", - NSF1FunctionKey: "F1", - NSF2FunctionKey: "F2", - NSF3FunctionKey: "F3", - NSF4FunctionKey: "F4", - NSF5FunctionKey: "F5", - NSF6FunctionKey: "F6", - NSF7FunctionKey: "F7", - NSF8FunctionKey: "F8", - NSF9FunctionKey: "F9", - NSF10FunctionKey: "F10", - NSF11FunctionKey: "F11", - NSF12FunctionKey: "F12", - NSF13FunctionKey: "F13", - NSF14FunctionKey: "F14", - NSF15FunctionKey: "F15", - NSF16FunctionKey: "F16", - NSF17FunctionKey: "F17", - NSF18FunctionKey: "F18", - NSF19FunctionKey: "F19", - NSF20FunctionKey: "F20", - NSF21FunctionKey: "F21", - NSF22FunctionKey: "F22", - NSF23FunctionKey: "F23", - NSF24FunctionKey: "F24", - NSF25FunctionKey: "F25", - NSF26FunctionKey: "F26", - NSF27FunctionKey: "F27", - NSF28FunctionKey: "F28", - NSF29FunctionKey: "F29", - NSF30FunctionKey: "F30", - NSF31FunctionKey: "F31", - NSF32FunctionKey: "F32", - NSF33FunctionKey: "F33", - NSF34FunctionKey: "F34", - NSF35FunctionKey: "F35", - 0x19: "Tab", - ] - static func isSpecial(key: String) -> Bool { guard key.characters.count == 1 else { return false } if let firstChar = key.utf16.first { - return KeyUtils.specialKeys.keys.contains(Int(firstChar)) + return specialKeys.keys.contains(Int(firstChar)) } return false } static func namedKeyFrom(key: String) -> String { - if let firstChar = key.utf16.first { - if KeyUtils.specialKeys.keys.contains(Int(firstChar)) { - return KeyUtils.specialKeys[Int(firstChar)]! - } + if let firstChar = key.utf16.first, specialKeys.keys.contains(Int(firstChar)) { + return specialKeys[Int(firstChar)]! } return key } } + +fileprivate let specialKeys = [ + NSUpArrowFunctionKey: "Up", + NSDownArrowFunctionKey: "Down", + NSLeftArrowFunctionKey: "Left", + NSRightArrowFunctionKey: "Right", + NSInsertFunctionKey: "Insert", + 0x7F: "BS", // "delete"-key + NSDeleteFunctionKey: "Del", // "Fn+delete"-key + NSHomeFunctionKey: "Home", + NSBeginFunctionKey: "Begin", + NSEndFunctionKey: "End", + NSPageUpFunctionKey: "PageUp", + NSPageDownFunctionKey: "PageDown", + NSHelpFunctionKey: "Help", + NSF1FunctionKey: "F1", + NSF2FunctionKey: "F2", + NSF3FunctionKey: "F3", + NSF4FunctionKey: "F4", + NSF5FunctionKey: "F5", + NSF6FunctionKey: "F6", + NSF7FunctionKey: "F7", + NSF8FunctionKey: "F8", + NSF9FunctionKey: "F9", + NSF10FunctionKey: "F10", + NSF11FunctionKey: "F11", + NSF12FunctionKey: "F12", + NSF13FunctionKey: "F13", + NSF14FunctionKey: "F14", + NSF15FunctionKey: "F15", + NSF16FunctionKey: "F16", + NSF17FunctionKey: "F17", + NSF18FunctionKey: "F18", + NSF19FunctionKey: "F19", + NSF20FunctionKey: "F20", + NSF21FunctionKey: "F21", + NSF22FunctionKey: "F22", + NSF23FunctionKey: "F23", + NSF24FunctionKey: "F24", + NSF25FunctionKey: "F25", + NSF26FunctionKey: "F26", + NSF27FunctionKey: "F27", + NSF28FunctionKey: "F28", + NSF29FunctionKey: "F29", + NSF30FunctionKey: "F30", + NSF31FunctionKey: "F31", + NSF32FunctionKey: "F32", + NSF33FunctionKey: "F33", + NSF34FunctionKey: "F34", + NSF35FunctionKey: "F35", + 0x19: "Tab", +]