Skip to content

Commit

Permalink
Refactor level 7 outline entries to use const enum for readability (#…
Browse files Browse the repository at this point in the history
…209897)

* refactor 7 -> const value for readability + inline on compile

* specifically use const enum instead of exported const
  • Loading branch information
Yoyokrazy authored Apr 8, 2024
1 parent e03ba6c commit f8d35f6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { disposableTimeout } from 'vs/base/common/async';
import { IOutlinePane } from 'vs/workbench/contrib/outline/browser/outline';
import { Codicon } from 'vs/base/common/codicons';
import { NOTEBOOK_IS_ACTIVE_EDITOR } from 'vs/workbench/contrib/notebook/common/notebookContextKeys';
import { NotebookOutlineConstants } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookOutlineEntryFactory';

class NotebookOutlineTemplate {

Expand Down Expand Up @@ -160,7 +161,7 @@ class NotebookOutlineRenderer implements ITreeRenderer<OutlineEntry, FuzzyScore,
const scopedContextKeyService = template.elementDisposables.add(this._contextKeyService.createScoped(template.container));
NotebookOutlineContext.CellKind.bindTo(scopedContextKeyService).set(isCodeCell ? CellKind.Code : CellKind.Markup);
NotebookOutlineContext.CellHasChildren.bindTo(scopedContextKeyService).set(length > 0);
NotebookOutlineContext.CellHasHeader.bindTo(scopedContextKeyService).set(node.element.level !== 7);
NotebookOutlineContext.CellHasHeader.bindTo(scopedContextKeyService).set(node.element.level !== NotebookOutlineConstants.NonHeaderOutlineLevel);
NotebookOutlineContext.OutlineElementTarget.bindTo(scopedContextKeyService).set(this._target);
this.setupFolding(isCodeCell, nbViewModel, scopedContextKeyService, template, nbCell);

Expand Down Expand Up @@ -428,14 +429,14 @@ export class NotebookCellOutline implements IOutline<OutlineEntry> {
if (entry.cell.cellKind === CellKind.Markup) {
if (!showMarkdownHeadersOnly) {
yield entry;
} else if (entry.level < 7) {
} else if (entry.level < NotebookOutlineConstants.NonHeaderOutlineLevel) {
yield entry;
}

} else if (showCodeCells && entry.cell.cellKind === CellKind.Code) {
if (showCodeCellSymbols) {
yield entry;
} else if (entry.level === 7) {
} else if (entry.level === NotebookOutlineConstants.NonHeaderOutlineLevel) {
yield entry;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import { IRange } from 'vs/editor/common/core/range';
import { SymbolKind } from 'vs/editor/common/languages';
import { OutlineTarget } from 'vs/workbench/services/outline/browser/outline';

export const enum NotebookOutlineConstants {
NonHeaderOutlineLevel = 7,
}

type entryDesc = {
name: string;
range: IRange;
Expand Down Expand Up @@ -77,7 +81,7 @@ export class NotebookOutlineEntryFactory {
if (cachedEntries) {
// push code cell that is a parent of cached symbols if we are targeting the outlinePane
if (target === OutlineTarget.OutlinePane) {
entries.push(new OutlineEntry(index++, 7, cell, preview, !!exeState, exeState ? exeState.isPaused : false));
entries.push(new OutlineEntry(index++, NotebookOutlineConstants.NonHeaderOutlineLevel, cell, preview, !!exeState, exeState ? exeState.isPaused : false));
}
cachedEntries.forEach((cached) => {
entries.push(new OutlineEntry(index++, cached.level, cell, cached.name, false, false, cached.range, cached.kind));
Expand All @@ -90,7 +94,7 @@ export class NotebookOutlineEntryFactory {
// empty or just whitespace
preview = localize('empty', "empty cell");
}
entries.push(new OutlineEntry(index++, 7, cell, preview, !!exeState, exeState ? exeState.isPaused : false));
entries.push(new OutlineEntry(index++, NotebookOutlineConstants.NonHeaderOutlineLevel, cell, preview, !!exeState, exeState ? exeState.isPaused : false));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { OutlineChangeEvent, OutlineConfigKeys, OutlineTarget } from 'vs/workben
import { OutlineEntry } from './OutlineEntry';
import { IOutlineModelService } from 'vs/editor/contrib/documentSymbols/browser/outlineModel';
import { CancellationToken } from 'vs/base/common/cancellation';
import { NotebookOutlineEntryFactory } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookOutlineEntryFactory';
import { NotebookOutlineConstants, NotebookOutlineEntryFactory } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookOutlineEntryFactory';

export class NotebookCellOutlineProvider {
private readonly _disposables = new DisposableStore();
Expand Down Expand Up @@ -273,9 +273,9 @@ export class NotebookCellOutlineProvider {
// if any are true, newActive should NOT be set to this._activeEntry and the event should NOT fire
if (
(newActive !== this._activeEntry) && !(
(showMarkdownHeadersOnly && newActive?.cell.cellKind === CellKind.Markup && newActive?.level === 7) || // show headers only + cell is mkdn + is level 7 (no header)
(!showCodeCells && newActive?.cell.cellKind === CellKind.Code) || // show code cells + cell is code
(!showCodeCellSymbols && newActive?.cell.cellKind === CellKind.Code && newActive?.level > 7) // show code symbols + cell is code + has level > 7 (nb symbol levels)
(showMarkdownHeadersOnly && newActive?.cell.cellKind === CellKind.Markup && newActive?.level === NotebookOutlineConstants.NonHeaderOutlineLevel) || // show headers only + cell is mkdn + is level 7 (no header)
(!showCodeCells && newActive?.cell.cellKind === CellKind.Code) || // show code cells + cell is code
(!showCodeCellSymbols && newActive?.cell.cellKind === CellKind.Code && newActive?.level > NotebookOutlineConstants.NonHeaderOutlineLevel) // show code symbols + cell is code + has level > 7 (nb symbol levels)
)
) {
this._activeEntry = newActive;
Expand Down

0 comments on commit f8d35f6

Please sign in to comment.