Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions data/fixtures/recorded/languages/markdown/changeCell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
languageId: markdown
command:
version: 7
spokenForm: change cell
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: notebookCell}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB: notebookCell just means the "cell" scope type. It doesn't actually mean a notebook cell (and in fact here it means a markdown table cell), but we added notebooks first and we don't want to rename it.

usePrePhraseSnapshot: false
initialState:
documentContents: |
```
code
```
selections:
- anchor: {line: 1, character: 0}
active: {line: 1, character: 0}
marks: {}
finalState:
documentContents: |+
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class LineScopeHandler extends BaseScopeHandler {
type: "paragraph",
} as const;
protected readonly isHierarchical = false;
public readonly includeAdjacentInEvery: boolean = true;
public readonly includeAdjacentInEvery = true;

constructor(_scopeType: ScopeType, _languageId: string) {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,46 @@ import {
import type { LanguageDefinitions } from "../../../languages/LanguageDefinitions";
import { ide } from "../../../singletons/ide.singleton";
import { NotebookCellTarget } from "../../targets";
import { BaseScopeHandler } from "./BaseScopeHandler";
import type { TargetScope } from "./scope.types";
import type {
ComplexScopeType,
ScopeHandler,
ScopeIteratorRequirements,
} from "./scopeHandler.types";

export class NotebookCellScopeHandler implements ScopeHandler {
export class NotebookCellScopeHandler extends BaseScopeHandler {
public readonly scopeType = { type: "notebookCell" } as const;
public readonly iterationScopeType = { type: "document" } as const;
public readonly includeAdjacentInEvery = false;
protected isHierarchical = false;
private readonly languageScopeHandler: ScopeHandler | undefined;

constructor(
private languageDefinitions: LanguageDefinitions,
languageDefinitions: LanguageDefinitions,
_scopeType: ScopeType,
private languageId: string,
) {}
) {
super();

this.languageScopeHandler = languageDefinitions
.get(this.languageId)
?.getScopeHandler(this.scopeType);
}

*generateScopes(
get iterationScopeType(): ScopeType | ComplexScopeType {
if (this.languageScopeHandler != null) {
return this.languageScopeHandler.iterationScopeType;
}
return { type: "document" };
}

*generateScopeCandidates(
editor: TextEditor,
position: Position,
direction: Direction,
hints: ScopeIteratorRequirements,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NTS: The actual type of the interface is requirements?: Partial<ScopeIteratorRequirements>. This should really be a tsc compile error but it wasn't. We therefore started to read properties on hints when some of those properties could be undefined which threw an exception

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We needed something like what the base class does:

  *generateScopes(
    editor: TextEditor,
    position: Position,
    direction: Direction,
    requirements: Partial<ScopeIteratorRequirements> = {},
  ): Iterable<TargetScope> {
    const hints: ScopeIteratorRequirements = {
      ...DEFAULT_REQUIREMENTS,
      ...requirements,
      distalPosition:
        requirements.distalPosition ??
        (direction === "forward"
          ? editor.document.range.end
          : editor.document.range.start),
    };

Rather than copying the logic it was easier to just rewrite this class to use the base class, which Andreas says should have been done originally, just didn't think of it

): Iterable<TargetScope> {
const scopeHandler = this.languageDefinitions
.get(this.languageId)
?.getScopeHandler(this.scopeType);

if (scopeHandler != null) {
yield* scopeHandler.generateScopeCandidates(
if (this.languageScopeHandler != null) {
yield* this.languageScopeHandler.generateScopes(
editor,
position,
direction,
Expand Down
Loading