Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to continue indentation, upgrade @codemirror/commands #16252

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/codemirror-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"watch": "tsc -b --watch"
},
"dependencies": {
"@codemirror/commands": "^6.3.3",
"@codemirror/commands": "^6.5.0",
"@codemirror/lang-markdown": "^6.2.4",
"@codemirror/language": "^6.10.1",
"@codemirror/legacy-modes": "^6.3.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/codemirror/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"dependencies": {
"@codemirror/autocomplete": "^6.15.0",
"@codemirror/commands": "^6.3.3",
"@codemirror/commands": "^6.5.0",
"@codemirror/lang-cpp": "^6.0.2",
"@codemirror/lang-css": "^6.2.1",
"@codemirror/lang-html": "^6.4.8",
Expand Down
22 changes: 20 additions & 2 deletions packages/codemirror/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import {
indentMore,
insertBlankLine,
insertNewlineAndIndent,
insertNewlineKeepIndent,
insertTab,
simplifySelection
} from '@codemirror/commands';
import { EditorState, Transaction } from '@codemirror/state';
import { EditorState, Facet, Transaction } from '@codemirror/state';
import {
COMPLETER_ACTIVE_CLASS,
COMPLETER_ENABLED_CLASS
Expand All @@ -34,6 +35,19 @@ const TOOLTIP_OPENER_SELECTOR =
const ACTIVE_CELL_IN_EDIT_MODE_SELECTOR =
'.jp-mod-editMode .jp-Cell.jp-mod-active';

/**
* CodeMirror facets namespace
*/
export namespace CommandFacets {
/**
* Whether to always continue indentation when inserting a new line.
*/
export const continueIndentation = Facet.define<boolean, boolean>({
combine: values => values.some(v => v),
static: true
});
}

/**
* CodeMirror commands namespace
*/
Expand Down Expand Up @@ -79,7 +93,11 @@ export namespace StateCommands {
}

const arg = { state: target.state, dispatch: target.dispatch };
return insertNewlineAndIndent(arg);
if (target.state.facet(CommandFacets.continueIndentation)) {
return insertNewlineKeepIndent(arg);
} else {
return insertNewlineAndIndent(arg);
}
}

/**
Expand Down
17 changes: 16 additions & 1 deletion packages/codemirror/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { ITranslator, nullTranslator } from '@jupyterlab/translation';
import { JSONExt, ReadonlyJSONObject } from '@lumino/coreutils';
import { IObservableDisposable } from '@lumino/disposable';
import { ISignal, Signal } from '@lumino/signaling';
import { StateCommands } from './commands';
import { CommandFacets, StateCommands } from './commands';
import { customTheme, CustomTheme, rulers } from './extensions';
import {
IConfigurableExtension,
Expand Down Expand Up @@ -746,6 +746,21 @@ export namespace EditorExtensionRegistry {
factory: () =>
createConfigurableExtension<KeyBinding[]>(value => keymap.of(value))
}),
Object.freeze({
name: 'continueIndentation',
default: false,
factory: () =>
createConfigurableExtension((value: boolean) =>
CommandFacets.continueIndentation.of(value)
),
schema: {
type: 'boolean',
title: trans.__('Continue Indentation'),
description: trans.__(
'Whether to always continue indentation when inserting a new line. When disabled, the editor will follow language-specific heuristics if available.'
)
}
}),
Object.freeze({
name: 'lineNumbers',
default: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/fileeditor-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"watch": "tsc -b --watch"
},
"dependencies": {
"@codemirror/commands": "^6.3.3",
"@codemirror/commands": "^6.5.0",
"@codemirror/search": "^6.5.6",
"@jupyterlab/application": "^4.2.0-beta.3",
"@jupyterlab/apputils": "^4.3.0-beta.3",
Expand Down
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1355,15 +1355,15 @@ __metadata:
languageName: node
linkType: hard

"@codemirror/commands@npm:^6.3.3":
version: 6.3.3
resolution: "@codemirror/commands@npm:6.3.3"
"@codemirror/commands@npm:^6.5.0":
version: 6.5.0
resolution: "@codemirror/commands@npm:6.5.0"
dependencies:
"@codemirror/language": ^6.0.0
"@codemirror/state": ^6.4.0
"@codemirror/view": ^6.0.0
"@lezer/common": ^1.1.0
checksum: 7d23aecc973823969434b839aefa9a98bb47212d2ce0e6869ae903adbb5233aad22a760788fb7bb6eb45b00b01a4932fb93ad43bacdcbc0215e7500cf54b17bb
checksum: 27e49c5e0cb918b95d6a9f741bcc0e72cb76f963b0c829308edfb4491a37d8b12ae6fb96f9f1886b3189a22c82fec4434fbe65547dc3cd3e8dfb5222dfead2e7
languageName: node
linkType: hard

Expand Down Expand Up @@ -2518,7 +2518,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@jupyterlab/codemirror-extension@workspace:packages/codemirror-extension"
dependencies:
"@codemirror/commands": ^6.3.3
"@codemirror/commands": ^6.5.0
"@codemirror/lang-markdown": ^6.2.4
"@codemirror/language": ^6.10.1
"@codemirror/legacy-modes": ^6.3.3
Expand Down Expand Up @@ -2548,7 +2548,7 @@ __metadata:
resolution: "@jupyterlab/codemirror@workspace:packages/codemirror"
dependencies:
"@codemirror/autocomplete": ^6.15.0
"@codemirror/commands": ^6.3.3
"@codemirror/commands": ^6.5.0
"@codemirror/lang-cpp": ^6.0.2
"@codemirror/lang-css": ^6.2.1
"@codemirror/lang-html": ^6.4.8
Expand Down Expand Up @@ -3396,7 +3396,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@jupyterlab/fileeditor-extension@workspace:packages/fileeditor-extension"
dependencies:
"@codemirror/commands": ^6.3.3
"@codemirror/commands": ^6.5.0
"@codemirror/search": ^6.5.6
"@jupyterlab/application": ^4.2.0-beta.3
"@jupyterlab/apputils": ^4.3.0-beta.3
Expand Down