MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / createIndentGuidesPlugin

Function createIndentGuidesPlugin

src/cm/indentGuides.ts:279–362  ·  view source on GitHub ↗

* ViewPlugin for indent guides

(
	config: Required<IndentGuidesConfig>,
)

Source from the content-addressed store, hash-verified

277 * ViewPlugin for indent guides
278 */
279function createIndentGuidesPlugin(
280 config: Required<IndentGuidesConfig>,
281): ViewPlugin<{
282 decorations: DecorationSet;
283 update(update: ViewUpdate): void;
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

Callers 1

indentGuidesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected