Skip to content

Commit d5493e4

Browse files
authored
Merge pull request #102 from CodinGame/fix-hide-code
Fix hide code
2 parents d1e65f3 + 5059bd6 commit d5493e4

File tree

3 files changed

+21
-32
lines changed

3 files changed

+21
-32
lines changed

rollup.config.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,23 @@ ${files.map((_, index) => ` whenReady${index}()`).join(',\n')}
103103
breakpoints,
104104
taskDefinitions,
105105
viewsWelcome,
106+
terminal,
107+
viewsContainers,
106108
...remainingContribute
107-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
108-
} = manifest.contributes as any
109+
} = manifest.contributes ?? {}
109110

110111
const {
112+
activationEvents,
113+
devDependencies,
114+
dependencies,
115+
scripts,
111116
browser,
112117
main,
113118
l10n,
114119
extensionDependencies, // for pure-d that requires hbenl.vscode-test-explorer
115120
...remainingManifest
116-
} = manifest
121+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
122+
} = manifest as any
117123

118124
return {
119125
...remainingManifest,

src/tools.ts

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,20 @@ export function lockCodeWithoutDecoration (
182182
return disposableStore
183183
}
184184

185+
let hideCodeWithoutDecorationCounter = 0
185186
export function hideCodeWithoutDecoration (editor: monaco.editor.ICodeEditor, decorationFilter: (decoration: monaco.editor.IModelDecoration) => boolean): monaco.IDisposable {
186-
let otherHiddenAreas: monaco.IRange[] = editor._getViewModel()?.getHiddenAreas() ?? []
187-
function getHiddenAreas () {
187+
const hideId = `hideCodeWithoutDecoration:${hideCodeWithoutDecorationCounter++}`
188+
189+
function updateHiddenAreas (): void {
188190
const model = editor.getModel()
189191
if (model == null) {
190-
return []
192+
return
191193
}
192194

193195
const decorations = model.getAllDecorations()
194196
.filter(decorationFilter)
195197
if (decorations.length === 0) {
196-
return otherHiddenAreas
198+
return
197199
}
198200

199201
const ranges = decorations
@@ -218,40 +220,22 @@ export function hideCodeWithoutDecoration (editor: monaco.editor.ICodeEditor, de
218220
}
219221
}, [])
220222

221-
let hiddenAreas: monaco.IRange[] = [...otherHiddenAreas]
223+
const hiddenAreas: monaco.IRange[] = []
222224
let position = new monaco.Position(1, 1)
223225
for (const range of ranges) {
224226
const startPosition = model.modifyPosition(range.getStartPosition(), -1)
225227
const endPosition = model.modifyPosition(range.getEndPosition(), 1)
226-
hiddenAreas = [
227-
...hiddenAreas,
228-
monaco.Range.fromPositions(position, startPosition)
229-
]
228+
hiddenAreas.push(monaco.Range.fromPositions(position, startPosition))
230229
position = endPosition
231230
}
232-
hiddenAreas = [
233-
...hiddenAreas,
234-
monaco.Range.fromPositions(position, model.getFullModelRange().getEndPosition())
235-
]
236-
237-
return hiddenAreas
238-
}
239-
240-
const originalSetHiddenAreas = editor.setHiddenAreas.bind(editor)
241-
function updateHiddenAreas () {
242-
originalSetHiddenAreas(getHiddenAreas())
243-
}
231+
hiddenAreas.push(monaco.Range.fromPositions(position, model.getFullModelRange().getEndPosition()))
244232

245-
// Hack to make it work with the folding service calling setHiddenAreas with its own areas
246-
editor.setHiddenAreas = (ranges) => {
247-
otherHiddenAreas = ranges
248-
updateHiddenAreas()
233+
editor.setHiddenAreas(hiddenAreas, hideId)
249234
}
250235

251236
const disposableStore = new DisposableStore()
252237

253238
disposableStore.add(editor.onDidChangeModel(() => {
254-
otherHiddenAreas = editor._getViewModel()?.getHiddenAreas() ?? []
255239
updateHiddenAreas()
256240
}))
257241
disposableStore.add(editor.onDidChangeModelDecorations(() => {
@@ -261,8 +245,7 @@ export function hideCodeWithoutDecoration (editor: monaco.editor.ICodeEditor, de
261245

262246
disposableStore.add({
263247
dispose () {
264-
editor.setHiddenAreas = originalSetHiddenAreas
265-
editor.setHiddenAreas(otherHiddenAreas)
248+
editor.setHiddenAreas([], hideId)
266249
}
267250
})
268251

src/types/monaco.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ declare module 'monaco-editor' {
55
interface ICodeEditor {
66
// This method is internal and is supposed to be used by the folding feature
77
// We still use it to hide parts of the code in the `hideCodeWithoutDecoration` function
8-
setHiddenAreas(ranges: IRange[]): void
8+
setHiddenAreas(ranges: IRange[], source?: unknown): void
99

1010
_getViewModel(): {
1111
getHiddenAreas(): IRange[]

0 commit comments

Comments
 (0)