Skip to content

Added modifier line number #165

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

Merged
merged 5 commits into from
Aug 1, 2021
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
12 changes: 11 additions & 1 deletion src/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ export interface SubpieceModifier {
export interface MatchingPairSymbolModifier {
type: "matchingPairSymbol";
}
export interface LineNumberModifierPosition {
lineNumber: number;
isRelative: boolean;
}
export interface LineNumberModifier {
type: "lineNumber";
anchor: LineNumberModifierPosition;
active: LineNumberModifierPosition;
}
export interface IdentityModifier {
type: "identity";
}
Expand All @@ -109,11 +118,12 @@ export interface TailModifier {
}

export type Modifier =
| IdentityModifier
| SurroundingPairModifier
| ContainingScopeModifier
| SubpieceModifier
| MatchingPairSymbolModifier
| IdentityModifier
| LineNumberModifier
| HeadModifier
| TailModifier;

Expand Down
28 changes: 28 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,38 @@ export async function activate(context: vscode.ExtensionContext) {

addDecorationsDebounced();

function checkForEditsOutsideViewport(event: vscode.TextDocumentChangeEvent) {
const editor = vscode.window.activeTextEditor;
if (editor == null || editor.document !== event.document) {
return;
}
const { start, end } = editor.visibleRanges[0];
const ranges = [];
for (const edit of event.contentChanges) {
if (
edit.range.end.isBeforeOrEqual(start) ||
edit.range.start.isAfterOrEqual(end)
) {
ranges.push(edit.range);
}
}
if (ranges.length > 0) {
ranges.sort((a, b) => a.start.line - b.start.line);
const linesText = ranges
.map((range) => `${range.start.line + 1}-${range.end.line + 1}`)
.join(", ");
vscode.window.showWarningMessage(
`Modification outside of viewport at lines: ${linesText}`
);
}
}

function handleEdit(edit: vscode.TextDocumentChangeEvent) {
graph.navigationMap.updateTokenRanges(edit);

addDecorationsDebounced();

checkForEditsOutsideViewport(edit);
}

const recomputeDecorationStyles = async () => {
Expand Down
22 changes: 22 additions & 0 deletions src/processTargets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Target,
TypedSelection,
Modifier,
LineNumberModifierPosition,
} from "./Types";
import { performInsideOutsideAdjustment } from "./performInsideOutsideAdjustment";
import { SUBWORD_MATCHER } from "./constants";
Expand Down Expand Up @@ -370,6 +371,27 @@ function transformSelection(
];
}

case "lineNumber": {
const getLine = (linePosition: LineNumberModifierPosition) =>
linePosition.isRelative
? selection.editor.selection.active.line + linePosition.lineNumber
: linePosition.lineNumber;
return [
{
selection: update(selection, {
selection: () =>
new Selection(
getLine(modifier.anchor),
0,
getLine(modifier.active),
0
),
}),
context: {},
},
];
}

case "matchingPairSymbol":
case "surroundingPair":
throw new Error("Not implemented");
Expand Down