mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-09-20 10:05:57 +08:00
Add a keyboard shortcut for triggering on-hover docs (#508)
* Add a keyboard shortcut for triggering on-hover docs * Update changelog
This commit is contained in:
parent
f91c71bf3a
commit
f9e67d27c0
|
@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
|
||||
- Introduced file system abstraction and an S3 support ([#492](https://github.com/livebook-dev/livebook/pull/492))
|
||||
- Added support for configuring file systems using env variables ([#498](https://github.com/livebook-dev/livebook/pull/498))
|
||||
- Added a keyboard shortcut for triggering on-hover docs ([#508](https://github.com/livebook-dev/livebook/pull/508))
|
||||
|
||||
### Fixed
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import monaco from "./live_editor/monaco";
|
||||
import monaco, { addKeybinding } from "./live_editor/monaco";
|
||||
import EditorClient from "./live_editor/editor_client";
|
||||
import MonacoEditorAdapter from "./live_editor/monaco_editor_adapter";
|
||||
import HookServerAdapter from "./live_editor/hook_server_adapter";
|
||||
|
@ -193,6 +193,18 @@ class LiveEditor {
|
|||
const contentHeight = this.editor.getContentHeight();
|
||||
this.container.style.height = `${contentHeight}px`;
|
||||
});
|
||||
|
||||
// Replace built-in keybindings
|
||||
// Note that generally we want to stick to defaults, so that we match
|
||||
// VS Code, but some keybindings are overly awkward, in which case we
|
||||
// add our own
|
||||
|
||||
// By default this is a sequence of: Ctrl + K Ctrl + I
|
||||
addKeybinding(
|
||||
this.editor,
|
||||
"editor.action.showHover",
|
||||
monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_I
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import * as monaco from "monaco-editor/esm/vs/editor/editor.api";
|
||||
import { CommandsRegistry } from "monaco-editor/esm/vs/platform/commands/common/commands";
|
||||
import ElixirOnTypeFormattingEditProvider from "./elixir/on_type_formatting_edit_provider";
|
||||
import theme from "./theme";
|
||||
|
||||
|
@ -80,3 +81,23 @@ export function highlight(code, language) {
|
|||
return result.replace(/<br\/>$/, "");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates keybinding for the given editor command.
|
||||
*
|
||||
* This uses an internal API, since there is no clean support
|
||||
* for customizing keybindings.
|
||||
* See https://github.com/microsoft/monaco-editor/issues/102#issuecomment-822981429
|
||||
*/
|
||||
export function addKeybinding(editor, id, newKeybinding) {
|
||||
const { handler, when } = CommandsRegistry.getCommand(id) ?? {};
|
||||
|
||||
if (handler) {
|
||||
editor._standaloneKeybindingService.addDynamicKeybinding(
|
||||
id,
|
||||
newKeybinding,
|
||||
handler,
|
||||
when
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,13 @@ defmodule LivebookWeb.SessionLive.ShortcutsComponent do
|
|||
desc: "Show completion list, use twice for details",
|
||||
basic: true
|
||||
},
|
||||
%{
|
||||
seq: ["ctrl", "i"],
|
||||
seq_mac: ["⌘", "i"],
|
||||
press_all: true,
|
||||
desc: "Show identifier documentation",
|
||||
basic: true
|
||||
},
|
||||
%{
|
||||
seq: ["ctrl", "shift", "i"],
|
||||
seq_mac: ["⇧", "⌥", "f"],
|
||||
|
|
Loading…
Reference in a new issue