| 284 | }> { |
| 285 | return ViewPlugin.fromClass( |
| 286 | class { |
| 287 | decorations: DecorationSet; |
| 288 | lineCache: IndentLineCache = new Map(); |
| 289 | styleCache: GuideStyleCache = new Map(); |
| 290 | lastCharWidth = 0; |
| 291 | lastTabSize = 4; |
| 292 | lastIndentUnit = 4; |
| 293 | |
| 294 | constructor(view: EditorView) { |
| 295 | const { state } = view; |
| 296 | this.lastCharWidth = view.defaultCharacterWidth; |
| 297 | this.lastTabSize = getTabSize(state); |
| 298 | this.lastIndentUnit = getIndentUnitColumns(state); |
| 299 | |
| 300 | this.decorations = buildDecorations( |
| 301 | view, |
| 302 | config, |
| 303 | this.lineCache, |
| 304 | this.styleCache, |
| 305 | ); |
| 306 | } |
| 307 | |
| 308 | update(update: ViewUpdate): void { |
| 309 | const { view, state } = update; |
| 310 | let needsRebuild = false; |
| 311 | |
| 312 | if (update.docChanged) { |
| 313 | this.decorations = this.decorations.map(update.changes); |
| 314 | this.lineCache.clear(); |
| 315 | needsRebuild = true; |
| 316 | } |
| 317 | |
| 318 | if (update.viewportChanged) { |
| 319 | needsRebuild = true; |
| 320 | } |
| 321 | |
| 322 | const currentTabSize = getTabSize(state); |
| 323 | const currentIndentUnit = getIndentUnitColumns(state); |
| 324 | const currentCharWidth = view.defaultCharacterWidth; |
| 325 | |
| 326 | if ( |
| 327 | currentTabSize !== this.lastTabSize || |
| 328 | currentIndentUnit !== this.lastIndentUnit |
| 329 | ) { |
| 330 | this.lastTabSize = currentTabSize; |
| 331 | this.lastIndentUnit = currentIndentUnit; |
| 332 | this.lineCache.clear(); |
| 333 | this.styleCache.clear(); |
| 334 | needsRebuild = true; |
| 335 | } |
| 336 | |
| 337 | if (currentCharWidth !== this.lastCharWidth) { |
| 338 | this.lastCharWidth = currentCharWidth; |
| 339 | this.styleCache.clear(); |
| 340 | needsRebuild = true; |
| 341 | } |
| 342 | |
| 343 | if (needsRebuild) { |
nothing calls this directly
no outgoing calls
no test coverage detected