1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-25 14:52:19 +03:00

Forward almost every keystroke to neovim

- we probably still have to fine-tune this.
This commit is contained in:
Tae Won Ha 2016-07-11 23:24:40 +02:00
parent 97cc6e4ad5
commit 4699e3db35
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
8 changed files with 110 additions and 71 deletions

View File

@ -4,7 +4,6 @@
*/
#import <Foundation/Foundation.h>
#import "NeoVimUiBridgeProtocol.h"
#import "NeoVimMsgIds.h"

View File

@ -7,6 +7,7 @@
#import "Logging.h"
#import "server_globals.h"
#import "NeoVimServer.h"
#import "NeoVimUiBridgeProtocol.h"
// FileInfo and Boolean are #defined by Carbon and NeoVim: Since we don't need the Carbon versions of them, we rename
// them.

View File

@ -0,0 +1,85 @@
//
// Keys.swift
// nvox
//
// Created by Tae Won Ha on 11/07/16.
// Copyright © 2016 Tae Won Ha. All rights reserved.
//
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",
]
static func isSpecial(key 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 false
}
static func namedKeyFrom(key key: String) -> String {
if let firstChar = key.utf16.first {
if KeyUtils.specialKeys.keys.contains(Int(firstChar)) {
return KeyUtils.specialKeys[Int(firstChar)]!
}
}
return key
}
}

View File

@ -311,12 +311,12 @@ public class NeoVimView: NSView {
)
}
func vimNamedKeys(string: String) -> String {
func wrapNamedKeys(string: String) -> String {
return "<\(string)>"
}
func vimPlainString(string: String) -> String {
return string.stringByReplacingOccurrencesOfString("<", withString: self.vimNamedKeys("lt"))
return string.stringByReplacingOccurrencesOfString("<", withString: self.wrapNamedKeys("lt"))
}
required public init?(coder: NSCoder) {

View File

@ -16,6 +16,8 @@ extension NeoVimView: NSTextInputClient {
return
}
// NSLog("\(#function): \(event)")
let modifierFlags = event.modifierFlags
let capslock = modifierFlags.contains(.AlphaShiftKeyMask)
let shift = modifierFlags.contains(.ShiftKeyMask)
@ -24,10 +26,18 @@ extension NeoVimView: NSTextInputClient {
: event.charactersIgnoringModifiers!
let vimModifiers = self.vimModifierFlags(modifierFlags)
if vimModifiers.characters.count > 0 {
self.agent.vimInput(self.vimNamedKeys(vimModifiers + charsIgnoringModifiers))
if KeyUtils.isSpecial(key: charsIgnoringModifiers) {
if vimModifiers.characters.count > 0 {
self.agent.vimInput(self.wrapNamedKeys(vimModifiers + KeyUtils.namedKeyFrom(key: charsIgnoringModifiers)))
} else {
self.agent.vimInput(self.wrapNamedKeys(KeyUtils.namedKeyFrom(key: charsIgnoringModifiers)))
}
} else {
self.agent.vimInput(self.vimPlainString(chars))
if vimModifiers.characters.count > 0 {
self.agent.vimInput(self.wrapNamedKeys(vimModifiers + charsIgnoringModifiers))
} else {
self.agent.vimInput(self.vimPlainString(chars))
}
}
self.keyDownDone = true

View File

@ -1,58 +0,0 @@
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Cocoa
/// NeoVim's named keys can be found in keymap.c
extension NeoVimView {
public override func moveForward(sender: AnyObject?) {
self.agent.vimInput(self.vimNamedKeys("C-f"))
}
public override func moveBackward(sender: AnyObject?) {
self.agent.vimInput(self.vimNamedKeys("C-b"))
}
public override func moveRight(sender: AnyObject?) {
self.agent.vimInput(self.vimNamedKeys("Right"))
}
public override func moveLeft(sender: AnyObject?) {
self.agent.vimInput(self.vimNamedKeys("Left"))
}
public override func moveUp(sender: AnyObject?) {
self.agent.vimInput(self.vimNamedKeys("Up"))
}
public override func moveDown(sender: AnyObject?) {
self.agent.vimInput(self.vimNamedKeys("Down"))
}
public override func deleteForward(sender: AnyObject?) {
self.agent.vimInput(self.vimNamedKeys("DEL"))
}
public override func deleteBackward(sender: AnyObject?) {
self.agent.vimInput(self.vimNamedKeys("BS"))
}
public override func scrollPageUp(sender: AnyObject?) {
self.agent.vimInput(self.vimNamedKeys("PageUp"))
}
public override func scrollPageDown(sender: AnyObject?) {
self.agent.vimInput(self.vimNamedKeys("PageDown"))
}
public override func scrollToBeginningOfDocument(sender: AnyObject?) {
self.agent.vimInput(self.vimNamedKeys("Home"))
}
public override func scrollToEndOfDocument(sender: AnyObject?) {
self.agent.vimInput(self.vimNamedKeys("End"))
}
}

View File

@ -62,7 +62,7 @@
4BEE79151D16D2100012EDAA /* DispatchUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BEE79141D16D2100012EDAA /* DispatchUtils.swift */; };
4BEE79171D16D3800012EDAA /* CellAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BEE79161D16D3800012EDAA /* CellAttributes.swift */; };
4BEF363D1D1EC045002A9898 /* NeoVimViewEvents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BEF363C1D1EC045002A9898 /* NeoVimViewEvents.swift */; };
4BFF04841D21984100063EF3 /* NeoVimViewResponder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BFF04831D21984100063EF3 /* NeoVimViewResponder.swift */; };
4BF6E29C1D34153C0053FA76 /* KeyUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BF6E29B1D34153C0053FA76 /* KeyUtils.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -204,7 +204,7 @@
4BEE79141D16D2100012EDAA /* DispatchUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DispatchUtils.swift; sourceTree = "<group>"; };
4BEE79161D16D3800012EDAA /* CellAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CellAttributes.swift; sourceTree = "<group>"; };
4BEF363C1D1EC045002A9898 /* NeoVimViewEvents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NeoVimViewEvents.swift; sourceTree = "<group>"; };
4BFF04831D21984100063EF3 /* NeoVimViewResponder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NeoVimViewResponder.swift; sourceTree = "<group>"; };
4BF6E29B1D34153C0053FA76 /* KeyUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyUtils.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -292,6 +292,7 @@
4BCADE071D11ED12004DAD0F /* CocoaExtensions.swift */,
4B1BB3521D16C5E500CA4FEF /* InputTestView.swift */,
4BEE79141D16D2100012EDAA /* DispatchUtils.swift */,
4BF6E29B1D34153C0053FA76 /* KeyUtils.swift */,
);
path = SwiftNeoVim;
sourceTree = "<group>";
@ -409,7 +410,6 @@
4BEF363C1D1EC045002A9898 /* NeoVimViewEvents.swift */,
4BEE79111D16D0AC0012EDAA /* NeoVimViewUiBridge.swift */,
4B401B191D046E0600D99EDC /* NeoVimViewDelegate.swift */,
4BFF04831D21984100063EF3 /* NeoVimViewResponder.swift */,
4B570DC01D303CAF006EDC21 /* NeoVimAgent.h */,
4B570DC11D303CAF006EDC21 /* NeoVimAgent.m */,
);
@ -638,11 +638,11 @@
buildActionMask = 2147483647;
files = (
4BEE79171D16D3800012EDAA /* CellAttributes.swift in Sources */,
4BF6E29C1D34153C0053FA76 /* KeyUtils.swift in Sources */,
4B1BB3531D16C5E500CA4FEF /* InputTestView.swift in Sources */,
4BCADE081D11ED12004DAD0F /* CocoaExtensions.swift in Sources */,
4B2A2C0F1D0353E30074CE9A /* NeoVim.swift in Sources */,
4B401B1A1D046E0600D99EDC /* NeoVimViewDelegate.swift in Sources */,
4BFF04841D21984100063EF3 /* NeoVimViewResponder.swift in Sources */,
1929B728262BAA14FC93F6AC /* NeoVimView.swift in Sources */,
4BEF363D1D1EC045002A9898 /* NeoVimViewEvents.swift in Sources */,
4B570DC31D303CAF006EDC21 /* NeoVimAgent.m in Sources */,

View File

@ -21,9 +21,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
self.mainWindowManager.newMainWindow()
}
// func applicationDidFinishLaunching(aNotification: NSNotification) {
func applicationDidFinishLaunching(aNotification: NSNotification) {
// let testView = InputTestView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
// self.window.contentView?.addSubview(testView)
// self.window.makeFirstResponder(testView)
// }
self.mainWindowManager.newMainWindow()
}
}