Skip to content

Commit

Permalink
fix(input/#3783): Part 1 - Add 'editorLangId' context key (#3794)
Browse files Browse the repository at this point in the history
* Add entry about 'editorLangId'
* Add editor lang id context key
* Add some missing key bindings for language features to docs
* Add CHANGES entry
  • Loading branch information
bryphe authored Aug 22, 2021
1 parent faf06c1 commit 07b08c9
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES_CURRENT.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### Features

- #3795 - Search: Add `search.useIgnoreFiles` configuration setting (fixes #3792)
- #3794 - Input: Add `editorLangId` context key (related #3783)

### Bug Fixes

Expand Down
11 changes: 11 additions & 0 deletions docs/docs/configuration/key-bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ The `activeViewlet` context key corresponds to the id of the open sidebar pane:
- `workbench.view.scm` - SCM
- `workbench.view.search` - Search

The `editorLangId` context key corresponds to the language identifier of the active editor (the same value shown in the statusbar), and can be combined with other context keys, like:
`'when': 'editorFocus && editorLangId == typescript'`

Onivim-specific contexts:

| Context Name | True When |
Expand Down Expand Up @@ -185,6 +188,14 @@ Onivim-specific contexts:
| Control+V / Command+V | Paste from clipboard | `editor.action.clipboardPasteAction` |
| Control+S / Command+S | Save file | `workbench.action.files.save`

### Language Features

| Default Key Binding | Description | Command |
| --- | --- | --- |
| F2 | Rename | `editor.action.rename` |
| F12 or `gd` | Go-to Definition | `editor.action.revealDefinition` |
| Shift+F12 | Go-to References | `editor.action.goToReferences` |

### List / Menu commands

> NOTE: Some of the list select commands may not be fully hooked up yet, such that they may not respect vertical/horizontal opening.
Expand Down
14 changes: 14 additions & 0 deletions src/Feature/Editor/Editor.re
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@ type t = {
showDeprecated: bool,
};

module ContextKeys = {
open WhenExpr.ContextKeys.Schema;

let editorLangId =
string("editorLangId", ({buffer, _}) => {
EditorBuffer.fileType(buffer) |> Oni_Core.Buffer.FileType.toString
});
};

let contextKeys = editor => {
WhenExpr.ContextKeys.(
ContextKeys.[editorLangId] |> Schema.fromList |> fromSchema(editor)
);
};
let setBoundingBox = (bbox, editor) => {
let (left, top, _, _) = Revery.Math.BoundingBox2d.getBounds(bbox);
{...editor, pixelY: top, pixelX: left};
Expand Down
2 changes: 2 additions & 0 deletions src/Feature/Editor/Editor.rei
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ let create:
t;
let copy: t => t;

let contextKeys: t => WhenExpr.ContextKeys.t;

type inlineElement;

let setCodeLens:
Expand Down
6 changes: 6 additions & 0 deletions src/Model/ContextKeys.re
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ let all = (state: State.t) => {
|> Schema.map(({sideBar, _}: State.t) => sideBar)
|> fromSchema(state);

let editorContextKeys =
state.layout
|> Feature_Layout.activeEditor
|> Feature_Editor.Editor.contextKeys;

// TODO: These sidebar-specific UI pieces should be encapsulated
// by Feature_SideBar.contextKeys.
let scmContextKeys =
Expand Down Expand Up @@ -190,6 +195,7 @@ let all = (state: State.t) => {
explorerContextKeys,
sideBarContext,
scmContextKeys,
editorContextKeys,
extensionContextKeys,
searchContextKeys,
paneContextKeys,
Expand Down

0 comments on commit 07b08c9

Please sign in to comment.