src/Tools/VSCode/extension/src/decorations.ts
changeset 65233 e37209c0a42a
parent 65201 2d01b30e6ac6
child 65913 f330f538dae6
equal deleted inserted replaced
65232:ca571c8c0788 65233:e37209c0a42a
     1 'use strict';
     1 'use strict';
     2 
     2 
       
     3 import * as timers from 'timers';
     3 import * as vscode from 'vscode'
     4 import * as vscode from 'vscode'
     4 import { Position, Range, MarkedString, DecorationOptions, DecorationRenderOptions,
     5 import { Position, Range, MarkedString, DecorationOptions, DecorationRenderOptions,
     5   TextDocument, TextEditor, TextEditorDecorationType, ExtensionContext, Uri } from 'vscode'
     6   TextDocument, TextEditor, TextEditorDecorationType, ExtensionContext, Uri } from 'vscode'
     6 import { get_color } from './extension'
     7 import { get_color } from './extension'
     7 import { Decoration } from './protocol'
     8 import { Decoration } from './protocol'
   177         editor.setDecorations(types.get(typ), content)
   178         editor.setDecorations(types.get(typ), content)
   178       }
   179       }
   179     }
   180     }
   180   }
   181   }
   181 }
   182 }
       
   183 
       
   184 
       
   185 /* decorations vs. document changes */
       
   186 
       
   187 const touched_documents = new Set<TextDocument>()
       
   188 
       
   189 function update_touched_documents()
       
   190 {
       
   191   const touched_editors: TextEditor[] = []
       
   192   for (const editor of vscode.window.visibleTextEditors) {
       
   193     if (touched_documents.has(editor.document)) {
       
   194       touched_editors.push(editor)
       
   195     }
       
   196   }
       
   197   touched_documents.clear
       
   198   touched_editors.forEach(update_editor)
       
   199 }
       
   200 
       
   201 let touched_timer: NodeJS.Timer
       
   202 
       
   203 export function touch_document(document: TextDocument)
       
   204 {
       
   205   if (touched_timer) timers.clearTimeout(touched_timer)
       
   206   touched_documents.add(document)
       
   207   touched_timer = timers.setTimeout(update_touched_documents, 1000)
       
   208 }