Skip to content

Commit

Permalink
refactor: rename lock functions and update their parameters doc
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiSaba committed Nov 20, 2024
1 parent 781efe8 commit e80833d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export interface LockCodeOptions {
allowUndoRedo?: boolean
}

function lockCodeWithDecoration (
function lockCodeUsingDecoration (
editor: monaco.editor.ICodeEditor,
{
errorMessage,
Expand All @@ -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) {
Expand All @@ -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))
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e80833d

Please sign in to comment.