@@ -182,18 +182,20 @@ export function lockCodeWithoutDecoration (
182182 return disposableStore
183183}
184184
185+ let hideCodeWithoutDecorationCounter = 0
185186export 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
0 commit comments