diff --git a/README.md b/README.md index d810ab1..9e803f3 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ It also includes some tools allowing to add some missing features to monaco-edit - `collapseCodeSections` allows to create and collapse a code section between 2 tokens - `registerTextDecorationProvider` allows to compute decorations on all existing editors - `hideCodeWithoutDecoration` allows to hide code parts that have a specific decoration -- `lockCodeFromDecoration` allows to make read-only code parts within a specific decoration +- `lockCodeWithDecoration` allows to make read-only code parts within a specific decoration - `lockCodeWithoutDecoration` allows to make read-only code parts outside of a specific decoration - `updateEditorKeybindingsMode` allows to apply vim or emacs keybindings - `extractRangesFromTokens` allows to extract a code section between 2 tokens diff --git a/src/tools.ts b/src/tools.ts index 1ea5d3e..1eec14a 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -97,7 +97,7 @@ export interface LockCodeOptions { allowUndoRedo?: boolean } -function lockCodeWithDecoration ( +function lockCodeUsingDecoration ( editor: monaco.editor.ICodeEditor, { errorMessage, @@ -107,10 +107,10 @@ function lockCodeWithDecoration ( allowUndoRedo = true }: LockCodeOptions, /** - * If true, the code within the ranges will be locked. - * All the code outside of the ranges will be lock otherwise. + * If true, the code within the decoration will be locked. + * All the code outside of the decoration will be locked otherwise. */ - fromRanges: boolean + withDecoration: boolean ): monaco.IDisposable { const disposableStore = new DisposableStore() function displayLockedCodeError (position: monaco.Position) { @@ -130,7 +130,7 @@ function lockCodeWithDecoration ( if (ranges.length === 0) { return true } - return fromRanges + return withDecoration ? ranges.every((uneditableRange) => !uneditableRange.containsRange(range)) : ranges.some((editableRange) => editableRange.containsRange(range)) } @@ -268,18 +268,18 @@ function lockCodeWithDecoration ( return disposableStore } -export function lockCodeFromDecoration ( +export function lockCodeWithDecoration ( editor: monaco.editor.ICodeEditor, lockOptions: LockCodeOptions ): monaco.IDisposable { - return lockCodeWithDecoration(editor, lockOptions, true) + return lockCodeUsingDecoration(editor, lockOptions, true) } export function lockCodeWithoutDecoration ( editor: monaco.editor.ICodeEditor, lockOptions: LockCodeOptions ): monaco.IDisposable { - return lockCodeWithDecoration(editor, lockOptions, false) + return lockCodeUsingDecoration(editor, lockOptions, false) } let hideCodeWithoutDecorationCounter = 0