mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-09 13:07:37 +08:00
Add support for inserting blank line with Alt+Enter (#2652)
Co-authored-by: Jonatan Kłosko <jonatanklosko@gmail.com>
This commit is contained in:
parent
1f92e8ca52
commit
d5dee2a1ba
3 changed files with 30 additions and 5 deletions
|
@ -50,8 +50,10 @@ import { wait } from "../../lib/utils";
|
||||||
import Emitter from "../../lib/emitter";
|
import Emitter from "../../lib/emitter";
|
||||||
import CollabClient from "./live_editor/collab_client";
|
import CollabClient from "./live_editor/collab_client";
|
||||||
import { languages } from "./live_editor/codemirror/languages";
|
import { languages } from "./live_editor/codemirror/languages";
|
||||||
import { exitMulticursor } from "./live_editor/codemirror/commands";
|
import {
|
||||||
import { highlight } from "./live_editor/highlight";
|
exitMulticursor,
|
||||||
|
insertBlankLineAndCloseHints,
|
||||||
|
} from "./live_editor/codemirror/commands";
|
||||||
import { ancestorNode, closestNode } from "./live_editor/codemirror/tree_utils";
|
import { ancestorNode, closestNode } from "./live_editor/codemirror/tree_utils";
|
||||||
import { selectingClass } from "./live_editor/codemirror/selecting_class";
|
import { selectingClass } from "./live_editor/codemirror/selecting_class";
|
||||||
|
|
||||||
|
@ -289,7 +291,10 @@ export default class LiveEditor {
|
||||||
this.language &&
|
this.language &&
|
||||||
LanguageDescription.matchLanguageName(languages, this.language, false);
|
LanguageDescription.matchLanguageName(languages, this.language, false);
|
||||||
|
|
||||||
const customKeymap = [{ key: "Escape", run: exitMulticursor }];
|
const customKeymap = [
|
||||||
|
{ key: "Escape", run: exitMulticursor },
|
||||||
|
{ key: "Alt-Enter", run: insertBlankLineAndCloseHints },
|
||||||
|
];
|
||||||
|
|
||||||
this.view = new EditorView({
|
this.view = new EditorView({
|
||||||
parent: this.container,
|
parent: this.container,
|
||||||
|
@ -314,8 +319,8 @@ export default class LiveEditor {
|
||||||
history(),
|
history(),
|
||||||
EditorState.readOnly.of(this.readOnly),
|
EditorState.readOnly.of(this.readOnly),
|
||||||
readOnlyHint(),
|
readOnlyHint(),
|
||||||
keymap.of(vscodeKeymap),
|
|
||||||
keymap.of(customKeymap),
|
keymap.of(customKeymap),
|
||||||
|
keymap.of(vscodeKeymap),
|
||||||
EditorState.tabSize.of(2),
|
EditorState.tabSize.of(2),
|
||||||
EditorState.lineSeparator.of("\n"),
|
EditorState.lineSeparator.of("\n"),
|
||||||
lineWrappingEnabled ? EditorView.lineWrapping : [],
|
lineWrappingEnabled ? EditorView.lineWrapping : [],
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
import { closeCompletion } from "@codemirror/autocomplete";
|
||||||
|
import { insertBlankLine } from "@codemirror/commands";
|
||||||
|
import { closeSignature } from "./signature";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This command, when multi-cursor is active, collapses the selection
|
* This command, when multi-cursor is active, collapses the selection
|
||||||
* to the main cursor only.
|
* to the main cursor only.
|
||||||
|
@ -12,3 +16,16 @@ export function exitMulticursor(view) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls `insertBlankLine` and closes active intellisense hints.
|
||||||
|
*/
|
||||||
|
export function insertBlankLineAndCloseHints(view) {
|
||||||
|
if (insertBlankLine(view)) {
|
||||||
|
closeCompletion(view);
|
||||||
|
closeSignature(view);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -335,7 +335,10 @@ function startSignature(view) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeSignature(view) {
|
/**
|
||||||
|
* Closes the currently active completion.
|
||||||
|
*/
|
||||||
|
export function closeSignature(view) {
|
||||||
const signatureState = view.state.field(signatureField, false);
|
const signatureState = view.state.field(signatureField, false);
|
||||||
if (!signatureState || !signatureState.hint) return false;
|
if (!signatureState || !signatureState.hint) return false;
|
||||||
view.dispatch({ effects: [closeSignatureEffect.of(null)] });
|
view.dispatch({ effects: [closeSignatureEffect.of(null)] });
|
||||||
|
|
Loading…
Add table
Reference in a new issue