Skip to content
Merged
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
3 changes: 0 additions & 3 deletions src/processTargets/modifiers/getLegacyScopeStage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import ContainingSyntaxScopeStage, {
SimpleEveryScopeModifier,
} from "./scopeTypeStages/ContainingSyntaxScopeStage";
import NotebookCellStage from "./scopeTypeStages/NotebookCellStage";
import ParagraphStage from "./scopeTypeStages/ParagraphStage";
import {
CustomRegexModifier,
CustomRegexStage,
Expand Down Expand Up @@ -39,8 +38,6 @@ export default function getLegacyScopeStage(
switch (modifier.scopeType.type) {
case "notebookCell":
return new NotebookCellStage(modifier);
case "paragraph":
return new ParagraphStage(modifier);
case "nonWhitespaceSequence":
return new NonWhitespaceSequenceStage(modifier);
case "boundedNonWhitespaceSequence":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { Position, Range, TextDocument, TextEditor, TextLine } from "vscode";
import { Direction, ScopeType } from "../../../typings/targetDescriptor.types";
import { ParagraphTarget } from "../../targets";
import BaseScopeHandler from "./BaseScopeHandler";
import { fitRangeToLineContent } from "./LineScopeHandler";
import { TargetScope } from "./scope.types";

export default class TokenScopeHandler extends BaseScopeHandler {
public readonly scopeType: ScopeType = { type: "paragraph" };
public readonly iterationScopeType: ScopeType = { type: "document" };
protected readonly isHierarchical = false;

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

*generateScopeCandidates(
editor: TextEditor,
position: Position,
direction: Direction,
): Iterable<TargetScope> {
const { document } = editor;
const offset = direction === "forward" ? 1 : -1;
const stop = direction === "forward" ? document.lineCount : -1;
let startLine = getStartLine(document, position, direction);
let previousLine = editor.document.lineAt(position);

for (let i = position.line + offset; i !== stop; i += offset) {
const currentLine = editor.document.lineAt(i);

if (currentLine.isEmptyOrWhitespace) {
// End of paragraph
if (startLine != null) {
yield createScope(editor, startLine.range.union(previousLine.range));
startLine = undefined;
}
}
// Start of paragraph
else if (startLine == null) {
startLine = currentLine;
}

previousLine = currentLine;
}

// End of last paragraph
if (startLine != null) {
yield createScope(editor, startLine.range.union(previousLine.range));
}
}
}

/** Look in opposite direction for the start/edge of the paragraph */
function getStartLine(
document: TextDocument,
position: Position,
direction: Direction,
): TextLine | undefined {
const offset = direction === "forward" ? -1 : 1;
const stop = direction === "forward" ? -1 : document.lineCount;
let startLine = document.lineAt(position);

if (startLine.isEmptyOrWhitespace) {
return undefined;
}

for (let i = position.line + offset; i !== stop; i += offset) {
const line = document.lineAt(i);
if (line.isEmptyOrWhitespace) {
break;
}
startLine = line;
}

return startLine;
}

function createScope(editor: TextEditor, domain: Range): TargetScope {
return {
editor,
domain,
getTarget: (isReversed) =>
new ParagraphTarget({
editor,
isReversed,
contentRange: fitRangeToLineContent(editor, domain),
}),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
TokenScopeHandler,
WordScopeHandler,
OneOfScopeHandler,
ParagraphScopeHandler,
} from ".";
import type { ScopeType } from "../../../typings/targetDescriptor.types";
import type { ScopeHandler } from "./scopeHandler.types";
Expand Down Expand Up @@ -46,6 +47,8 @@ export default function getScopeHandler(
return new DocumentScopeHandler(scopeType, languageId);
case "oneOf":
return new OneOfScopeHandler(scopeType, languageId);
case "paragraph":
return new ParagraphScopeHandler(scopeType, languageId);
default:
return undefined;
}
Expand Down
2 changes: 2 additions & 0 deletions src/processTargets/modifiers/scopeHandlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ export * from "./DocumentScopeHandler";
export { default as DocumentScopeHandler } from "./DocumentScopeHandler";
export * from "./OneOfScopeHandler";
export { default as OneOfScopeHandler } from "./OneOfScopeHandler";
export * from "./ParagraphScopeHandler";
export { default as ParagraphScopeHandler } from "./ParagraphScopeHandler";
export * from "./getScopeHandler";
export { default as getScopeHandler } from "./getScopeHandler";
113 changes: 0 additions & 113 deletions src/processTargets/modifiers/scopeTypeStages/ParagraphStage.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
languageId: plaintext
command:
spokenForm: clear block
version: 3
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: paragraph}
usePrePhraseSnapshot: true
action: {name: clearAndSetSelection}
initialState:
documentContents: |

aaa
selections:
- anchor: {line: 1, character: 0}
active: {line: 1, character: 0}
marks: {}
finalState:
documentContents: |+


selections:
- anchor: {line: 1, character: 0}
active: {line: 1, character: 0}
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: paragraph}}]}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
languageId: plaintext
command:
spokenForm: clear block
version: 3
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: paragraph}
usePrePhraseSnapshot: true
action: {name: clearAndSetSelection}
initialState:
documentContents: |

aaa
selections:
- anchor: {line: 1, character: 2}
active: {line: 1, character: 2}
marks: {}
finalState:
documentContents: |+


selections:
- anchor: {line: 1, character: 0}
active: {line: 1, character: 0}
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: paragraph}}]}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
languageId: plaintext
command:
spokenForm: clear block
version: 3
targets:
- type: primitive
modifiers:
- type: containingScope
scopeType: {type: paragraph}
usePrePhraseSnapshot: true
action: {name: clearAndSetSelection}
initialState:
documentContents: |

aaa
selections:
- anchor: {line: 1, character: 3}
active: {line: 1, character: 3}
marks: {}
finalState:
documentContents: |+


selections:
- anchor: {line: 1, character: 0}
active: {line: 1, character: 0}
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: containingScope, scopeType: {type: paragraph}}]}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
languageId: plaintext
command:
spokenForm: clear next block
version: 3
targets:
- type: primitive
modifiers:
- type: relativeScope
scopeType: {type: paragraph}
offset: 1
length: 1
direction: forward
usePrePhraseSnapshot: true
action: {name: clearAndSetSelection}
initialState:
documentContents: |

aaa

bbb
selections:
- anchor: {line: 1, character: 0}
active: {line: 1, character: 0}
marks: {}
finalState:
documentContents: |+

aaa


selections:
- anchor: {line: 3, character: 0}
active: {line: 3, character: 0}
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: relativeScope, scopeType: {type: paragraph}, offset: 1, length: 1, direction: forward}]}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
languageId: plaintext
command:
spokenForm: clear next block
version: 3
targets:
- type: primitive
modifiers:
- type: relativeScope
scopeType: {type: paragraph}
offset: 1
length: 1
direction: forward
usePrePhraseSnapshot: true
action: {name: clearAndSetSelection}
initialState:
documentContents: |

aaa

bbb
selections:
- anchor: {line: 1, character: 1}
active: {line: 1, character: 1}
marks: {}
finalState:
documentContents: |+

aaa


selections:
- anchor: {line: 3, character: 0}
active: {line: 3, character: 0}
fullTargets: [{type: primitive, mark: {type: cursor}, modifiers: [{type: relativeScope, scopeType: {type: paragraph}, offset: 1, length: 1, direction: forward}]}]
Loading