Skip to content

Migrated notebook cell modifier to scope handler #1571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Modifier,
SurroundingPairModifier,
} from "@cursorless/common";
import { StoredTargetMap } from "..";
import { LanguageDefinitions } from "../languages/LanguageDefinitions";
import { ModifierStageFactory } from "./ModifierStageFactory";
import { ModifierStage } from "./PipelineStages.types";
Expand Down Expand Up @@ -35,8 +36,6 @@ import ContainingSyntaxScopeStage, {
SimpleContainingScopeModifier,
SimpleEveryScopeModifier,
} from "./modifiers/scopeTypeStages/ContainingSyntaxScopeStage";
import NotebookCellStage from "./modifiers/scopeTypeStages/NotebookCellStage";
import { StoredTargetMap } from "..";

export class ModifierStageFactoryImpl implements ModifierStageFactory {
constructor(
Expand Down Expand Up @@ -123,8 +122,6 @@ export class ModifierStageFactoryImpl implements ModifierStageFactory {
modifier: ContainingScopeModifier | EveryScopeModifier,
): ModifierStage {
switch (modifier.scopeType.type) {
case "notebookCell":
return new NotebookCellStage(modifier);
case "boundedNonWhitespaceSequence":
return new BoundedNonWhitespaceSequenceStage(
this.languageDefinitions,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type {
Direction,
Position,
ScopeType,
TextEditor,
} from "@cursorless/common";
import { NotebookCellTarget } from "../../targets";
import { TargetScope } from "./scope.types";
import BaseScopeHandler from "./BaseScopeHandler";
import { ScopeIteratorRequirements } from "./scopeHandler.types";

export default class NotebookCellScopeHandler extends BaseScopeHandler {
public readonly scopeType = { type: "notebookCell" } as const;
protected isHierarchical = false;

constructor(_scopeType: ScopeType, _languageId: string) {
super();
}

get iterationScopeType(): ScopeType {
throw new Error(`Every ${this.scopeType.type} not yet implemented`);
}

protected *generateScopeCandidates(
editor: TextEditor,
_position: Position,
_direction: Direction,
_hints: ScopeIteratorRequirements,
): Iterable<TargetScope> {
const contentRange = editor.document.range;

yield {
editor,
domain: contentRange,
getTargets: (isReversed) => [
new NotebookCellTarget({
editor,
isReversed,
contentRange: contentRange,
}),
],
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IdentifierScopeHandler,
LineScopeHandler,
NonWhitespaceSequenceScopeHandler,
NotebookCellScopeHandler,
OneOfScopeHandler,
ParagraphScopeHandler,
ScopeHandlerFactory,
Expand Down Expand Up @@ -62,6 +63,8 @@ export class ScopeHandlerFactoryImpl implements ScopeHandlerFactory {
return new DocumentScopeHandler(scopeType, languageId);
case "oneOf":
return OneOfScopeHandler.create(this, scopeType, languageId);
case "notebookCell":
return new NotebookCellScopeHandler(scopeType, languageId);
case "nonWhitespaceSequence":
return new NonWhitespaceSequenceScopeHandler(
this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export * from "./OneOfScopeHandler";
export { default as OneOfScopeHandler } from "./OneOfScopeHandler";
export * from "./ParagraphScopeHandler";
export { default as ParagraphScopeHandler } from "./ParagraphScopeHandler";
export { default as NotebookCellScopeHandler } from "./NotebookCellScopeHandler";
export * from "./SentenceScopeHandler/SentenceScopeHandler";
export { default as SentenceScopeHandler } from "./SentenceScopeHandler/SentenceScopeHandler";
export * from "./RegexScopeHandler";
Expand Down

This file was deleted.