Skip to content

Commit

Permalink
bindings keys for sublime on pc working, but needs more testing (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
kghenderson committed Oct 3, 2022
1 parent e449c66 commit 83f4887
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 73 deletions.
82 changes: 45 additions & 37 deletions pkg/keyzen/cuetools/tangle_sublimetext_tool.cue
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,52 @@ command: tangle_sublimetext: {
StrokesName: args.strokesName
PlatformName: args.platformName
let editorCmds = keyzen.KeyZen.Editors["\(EditorName)"].EditorCommandNameMap
let cmdNames = keyzen.KeyZen.Commands.CommandNames

// debugEditorCmds: editorCmds
// debugCommandNames: keyzen.KeyZen.Commands.CommandNames
// debugStrokes: keyzen.KeyZen.Strokes["\(strokesName)"]
// debugStrokeCmdsMap: keyzen.KeyZen.Strokes["\(strokesName)"].StrokesMap
// debugBindings: keyzen.KeyZen.Strokes["\(strokesName)"].StrokesMap.Bindings[platformName]
// not every editor implements every command
CommandBindingsCount: len(CommandBindings)
if CommandBindingsCount == 0 {{CommandBindingsMax: 0}}
if CommandBindingsCount > 0 {{CommandBindingsMax: CommandBindingsCount - 1}}
CommandBindings: [
for cmdIdx, cmdKey in keyzen.KeyZen.Commands.CommandNames {
let strokeDefs = keyzen.KeyZen.Strokes["\(StrokesName)"].StrokesMap["\(cmdKey)"]
for cmdIdx, cmdName in cmdNames
if keyzen.KeyZen.Strokes["\(StrokesName)"].StrokesMap["\(cmdName)"] != _|_ &&
editorCmds["\(cmdName)"] != _|_ {
let strokeDefs = keyzen.KeyZen.Strokes["\(StrokesName)"].StrokesMap["\(cmdName)"]
let editorCmd = editorCmds["\(cmdName)"]
let editorCmdArgs = editorCmd.args
let editorCmdTextCommand = "\"command\": \"" + editorCmd.command + "\""

CmdName: "\(cmdName)"

EditorCmdText: string
if editorCmdArgs == _|_ {EditorCmdText: editorCmdTextCommand}
if editorCmdArgs != _|_ {EditorCmdText: editorCmdTextCommand + ", \"args\": " + editorCmd.argsText}

BindingsCount: len(Bindings)
if BindingsCount == 0 {{BindingsMax: 0}}
if BindingsCount > 0 {{BindingsMax: BindingsCount - 1}}
Bindings: [
for _, strokeDef in strokeDefs {
let bindingMap = strokeDef.Bindings["\(PlatformName)"]
let bindingIds = [ for k, v in bindingMap {name: k, idx: v}]
let bindingIdsSorted = list.Sort(bindingIds, {x: {}, y: {}, less: x.idx < y.idx})
let bindingKeys = [ for _, kv in bindingIdsSorted {kv.name}]
let bindingText = strings.Join(bindingKeys, "+")
"DefText": "\(strokeDef.DefText)"
"BindText": bindingText
},
]

// not every editor implements every command
let edCmd = editorCmds["\(cmdKey)"]
if edCmd != _|_ && strokeDefs != _|_ {
CmdName: "\(cmdKey)"

let edCmdText = "\"command\": \"" + edCmd.command + "\""

let edCmdArgs = edCmd.args

// debugEditorCmdArgs: edCmdArgs
EditorCmdText: string
if edCmdArgs == _|_ {EditorCmdText: edCmdText}
if edCmdArgs != _|_ {EditorCmdText: edCmdText + ", \"args\": " + edCmd.argsText}

Bindings: [
for _, strokeDef in strokeDefs {
let bindingMap = strokeDef.Bindings["\(PlatformName)"]
let bindingIds = [ for k, v in bindingMap {name: k, idx: v}]
let bindingIdsSorted = list.Sort(bindingIds, {x: {}, y: {}, less: x.idx < y.idx})
let bindingKeys = [ for _, kv in bindingIdsSorted {kv.name}]
let bindingText = strings.Join(bindingKeys, "+")
"\(strokeDef.DefText)": bindingText
},
]

}
},
]
}
}
// debugSourceCli: cli.Print & {text: yaml.Marshal(buildSource.source)}
// debugSourceCli: cli.Print & {text: yaml.Marshal(buildSource.source)}
debugSourceFile: file.Create & {filename: "_src.yaml", contents: yaml.Marshal(buildSource.source)}

genText: {
Expand All @@ -81,7 +86,7 @@ command: tangle_sublimetext: {
contents: genText.text
}

doneMsg: "done tangling: " + args.editorName + ", " + args.strokesName
doneMsg: "done tangling: " + args.strokesName + " for " + args.editorName + " on " + args.platformName
}

done: {
Expand All @@ -95,17 +100,20 @@ command: tangle_sublimetext: {

// language=gotemplate
sublimeKeymapTemplate: ###"""
// {{.StrokesName}} for {{.EditorName}} on {{.PlatformName}}
// {{.StrokesName}} for {{.EditorName}} on {{.PlatformName}}
{{- $cmdMax := .CommandBindingsMax }}
{{- range $cmdIdx, $cmd := .CommandBindings }}
{{- $cmdName := $cmd.CmdName }}
{{- $editorCmdText := $cmd.EditorCmdText }}
{{- range $strokeDefName, $strokeBinds := $cmd.Bindings }}
{{- $bindName := "<temp>"}}
{ "keys": ["{{$bindName}}"] }: {{$editorCmdText}} // {{$cmdName}}: {{$strokeDefName}}
{{$cmd}}
{{- end }}{{/* range CommandBindings */}}
{{- $bindsMax := $cmd.BindingsMax }}
{{- range $bindIdx, $bind := $cmd.Bindings }}
{{- $defText := $bind.DefText}}
{{- $bindText := $bind.BindText}}
{ "keys": ["{{$bindText}}"], {{$editorCmdText}} }
{{- if not (and (eq $cmdIdx $cmdMax) (eq $bindIdx $bindsMax))}}, {{end}} // {{$cmdName}}: "{{$defText}}"
{{- end }}{{/* range Bindings */}}
{{- end }}{{/* range CommandBindings */}}
"""###

//// language=gotemplate
Expand Down
32 changes: 16 additions & 16 deletions pkg/keyzen/editors/impl_sublime.cue
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,34 @@ let thisEditor = #Editor & {
EditorCommandNameMap: [cmdName=string]: #SublStuff

EditorCommandNameMap: {
"CursorMoveToCharBackward": {"command": "move_to", "args": {"by": "characters", "forward": false, "extend": false}}
"CursorMoveToCharBackwardSelect": {"command": "move_to", "args": {"by": "characters", "forward": false, "extend": true}}
"CursorMoveToCharForward": {"command": "move_to", "args": {"by": "characters", "forward": true, "extend": false}}
"CursorMoveToCharForwardSelect": {"command": "move_to", "args": {"by": "characters", "forward": true, "extend": true}}
"CursorMoveToLineBackward": {"command": "move_to", "args": {"by": "lines", "forward": false, "extend": false}}
"CursorMoveToLineBackwardSelect": {"command": "move_to", "args": {"by": "lines", "forward": false, "extend": true}}
"CursorMoveToCharBackward": {"command": "move", "args": {"by": "characters", "forward": false, "extend": false}}
"CursorMoveToCharBackwardSelect": {"command": "move", "args": {"by": "characters", "forward": false, "extend": true}}
"CursorMoveToCharForward": {"command": "move", "args": {"by": "characters", "forward": true, "extend": false}}
"CursorMoveToCharForwardSelect": {"command": "move", "args": {"by": "characters", "forward": true, "extend": true}}
"CursorMoveToLineBackward": {"command": "move", "args": {"by": "lines", "forward": false, "extend": false}}
"CursorMoveToLineBackwardSelect": {"command": "move", "args": {"by": "lines", "forward": false, "extend": true}}
"CursorMoveToLineBegin": {"command": "move_to", "args": {"to": "bol", "extend": false}}
"CursorMoveToLineBeginSelect": {"command": "move_to", "args": {"to": "bol", "extend": true}}
"CursorMoveToLineEnd": {"command": "move_to", "args": {"to": "eol", "extend": false}}
"CursorMoveToLineEndSelect": {"command": "move_to", "args": {"to": "eol", "extend": true}}
"CursorMoveToLineForward": {"command": "move_to", "args": {"by": "lines", "forward": true, "extend": false}}
"CursorMoveToLineForwardSelect": {"command": "move_to", "args": {"by": "lines", "forward": true, "extend": true}}
"CursorMoveToLineForward": {"command": "move", "args": {"by": "lines", "forward": true, "extend": false}}
"CursorMoveToLineForwardSelect": {"command": "move", "args": {"by": "lines", "forward": true, "extend": true}}
"CursorMoveToPageBackward": {"command": "move_to", "args": {"by": "pages", "forward": false, "extend": false}}
"CursorMoveToPageBackwardSelect": {"command": "move_to", "args": {"by": "pages", "forward": false, "extend": true}}
"CursorMoveToPageForward": {"command": "move_to", "args": {"by": "pages", "forward": false, "extend": false}}
"CursorMoveToPageForwardSelect": {"command": "move_to", "args": {"by": "pages", "forward": false, "extend": true}}
"CursorMoveToSubwordBackward": {"command": "move_to", "args": {"by": "subwords", "forward": false, "extend": false}}
"CursorMoveToSubwordBackwardSelect": {"command": "move_to", "args": {"by": "subwords", "forward": false, "extend": true}}
"CursorMoveToSubwordForward": {"command": "move_to", "args": {"by": "subwords", "forward": true, "extend": false}}
"CursorMoveToSubwordForwardSelect": {"command": "move_to", "args": {"by": "subwords", "forward": true, "extend": true}}
"CursorMoveToSubwordBackward": {"command": "move", "args": {"by": "subwords", "forward": false, "extend": false}}
"CursorMoveToSubwordBackwardSelect": {"command": "move", "args": {"by": "subwords", "forward": false, "extend": true}}
"CursorMoveToSubwordForward": {"command": "move", "args": {"by": "subwords", "forward": true, "extend": false}}
"CursorMoveToSubwordForwardSelect": {"command": "move", "args": {"by": "subwords", "forward": true, "extend": true}}
"CursorMoveToTextBegin": {"command": "move_to", "args": {"to": "bof", "extend": false}}
"CursorMoveToTextBeginSelect": {"command": "move_to", "args": {"to": "bof", "extend": true}}
"CursorMoveToTextEnd": {"command": "move_to", "args": {"to": "eof", "extend": false}}
"CursorMoveToTextEndSelect": {"command": "move_to", "args": {"to": "eof", "extend": true}}
"CursorMoveToWordBackward": {"command": "move_to", "args": {"by": "words", "forward": false, "extend": false}}
"CursorMoveToWordBackwardSelect": {"command": "move_to", "args": {"by": "words", "forward": false, "extend": true}}
"CursorMoveToWordForward": {"command": "move_to", "args": {"by": "words", "forward": true, "extend": false}}
"CursorMoveToWordForwardSelect": {"command": "move_to", "args": {"by": "words", "forward": true, "extend": true}}
"CursorMoveToWordBackward": {"command": "move", "args": {"by": "words", "forward": false, "extend": false}}
"CursorMoveToWordBackwardSelect": {"command": "move", "args": {"by": "words", "forward": false, "extend": true}}
"CursorMoveToWordForward": {"command": "move", "args": {"by": "words", "forward": true, "extend": false}}
"CursorMoveToWordForwardSelect": {"command": "move", "args": {"by": "words", "forward": true, "extend": true}}
"CursorMultiCloneAbove": {"command": "select_lines", "args": {"forward": false}}
"CursorMultiCloneBelow": {"command": "select_lines", "args": {"forward": true}}
"CursorMultiCloneOnLineEnds": {"command": "split_selection_into_lines"}
Expand Down
12 changes: 6 additions & 6 deletions pkg/keyzen/keys/impl_01_keys.cue
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ Keys: relativeKeys: {
PC: ["super", "ctrl", "alt"]
}
"primary": {
PC: ["ctrl"]
Mac: ["cmd"]
Mac2: ["cmd"]
PC: ["ctrl"]
}
"secondary": {
Mac: ["alt"]
Mac2: ["alt"]
PC: ["alt"]
Mac: ["ctrl"]
Mac2: ["ctrl"]
}
"pinky": {
PC: ["ctrl"]
Mac: ["ctrl"]
Mac2: ["cmd"]
PC: ["alt"]
}
"thumb": {
Mac: ["cmd"]
Mac2: ["alt"]
PC: ["alt"]
Mac: ["cmd"]
Mac2: ["ctrl"]
}
}

Expand Down
28 changes: 14 additions & 14 deletions pkg/keyzen/strokes/impl_zenstrokes1.cue
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ let thisStrokes = #Strokes & {
StrokeCmdDefsMap: {
"CursorMoveToCharBackward": [["left"], ["hyper+j"]]
"CursorMoveToCharBackwardSelect": [["shift+left"], ["hyper+shift+j"]]
"CursorMoveToCharForward": [["right"]]
"CursorMoveToCharForwardSelect": [["shift+right"]]
"CursorMoveToCharForward": [["right"], ["hyper+l"]]
"CursorMoveToCharForwardSelect": [["shift+right"], ["hyper+shift+l"]]
"CursorMoveToLineBackward": [["up"], ["hyper+i"]]
"CursorMoveToLineBackwardSelect": [["shift+up"], ["hyper+shift+i"]]
"CursorMoveToLineBegin": [["home"]] //, ["hyper+u"]
"CursorMoveToLineBeginSelect": [["shift+home"]] //, ["hyper+shift+u"]
"CursorMoveToLineEnd": [["end"]] //, ["hyper+o"]
"CursorMoveToLineEndSelect": [["shift+end"]] // , ["hyper+shift+o"]
"CursorMoveToLineForward": [["down"]]
"CursorMoveToLineForwardSelect": [["shift+down"]]
"CursorMoveToLineBegin": [["home"], ["hyper+h"], ["pinky+thumb+left"]] //, ["hyper+u"]
"CursorMoveToLineBeginSelect": [["shift+home"], ["hyper+shift+h"], ["pinky+thumb+shift+left"]] //, ["hyper+shift+u"]
"CursorMoveToLineEnd": [["end"], ["hyper+;"], ["pinky+thumb+right"]] //, ["hyper+o"]
"CursorMoveToLineEndSelect": [["shift+end"], ["hyper+shift+;"], ["pinky+thumb+shift+right"]] // , ["hyper+shift+o"]
"CursorMoveToLineForward": [["down"], ["hyper+k"]]
"CursorMoveToLineForwardSelect": [["shift+down"], ["hyper+shift+k"]]
"CursorMoveToPageBackward": [["pageup"], ["hyper+y"]]
"CursorMoveToPageBackwardSelect": [["shift+pageup"], ["hyper+shift+y"]]
"CursorMoveToPageForward": [["pagedown"], ["hyper+h"]]
Expand All @@ -26,10 +26,10 @@ let thisStrokes = #Strokes & {
"CursorMoveToSubwordBackwardSelect": [["thumb+shift+left"]]
"CursorMoveToSubwordForward": [["thumb+right"]]
"CursorMoveToSubwordForwardSelect": [["thumb+shift+right"]]
"CursorMoveToTextBegin": [["pinky+home"]]
"CursorMoveToTextBeginSelect": [["pinky+shift+home"]]
"CursorMoveToTextEnd": [["pinky+end"]]
"CursorMoveToTextEndSelect": [["pinky+shift+end"]]
"CursorMoveToTextBegin": [["pinky+home"], ["hyper+y"]]
"CursorMoveToTextBeginSelect": [["pinky+shift+home"], ["hyper+shift+y"]]
"CursorMoveToTextEnd": [["pinky+end"], ["hyper+n"]]
"CursorMoveToTextEndSelect": [["pinky+shift+end"], ["hyper+shift+n"]]
"CursorMoveToWordBackward": [["pinky+left"], ["hyper+u"]]
"CursorMoveToWordBackwardSelect": [["pinky+shift+left"], ["hyper+shift+u"]]
"CursorMoveToWordForward": [["pinky+right"], ["hyper+o"]]
Expand All @@ -40,12 +40,12 @@ let thisStrokes = #Strokes & {
// "CursorSelectAll": [[""]
// "CursorSelectionContract": [["pinky+shift+"]
// "CursorSelectionExpand": [["pinky+shift+"]
"EditNodeDelete": [["pinky+shift+."]]
"EditNodeDelete": [["pinky+shift+."], ["pinky+shift+x"]]
"EditNodeInsertAboveParent": [["pinky+shift+y"]]
"EditNodeInsertAboveSibling": [["pinky+shift+u"]]
"EditNodeInsertBelowChild": [["pinky+shift+n"]]
"EditNodeInsertBelowSibling": [["pinky+shift+m"]]
"EditNodeInsertDuplicate": [["pinky+shift+d"]]
"EditNodeInsertDuplicate": [["pinky+d"]]
"EditNodeJoin": [["pinky+shift+o"]]
"EditNodeMoveDown": [["pinky+shift+k"]]
"EditNodeMoveIn": [["pinky+shift+l"]]
Expand Down

0 comments on commit 83f4887

Please sign in to comment.