Skip to content
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

Hide decorations for selections that are larger than the viewport #403

Merged
merged 7 commits into from
Jan 6, 2022
19 changes: 15 additions & 4 deletions src/actions/Scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import {
import { groupBy } from "../util/itertools";
import { commands, window } from "vscode";
import { focusEditor } from "../util/setSelectionsAndFocusEditor";
import {
displayPendingEditDecorationsForSelection,
} from "../util/editDisplayUtils";
import { displayPendingEditDecorationsForSelection } from "../util/editDisplayUtils";

class Scroll implements Action {
getTargetPreferences: () => ActionPreferences[] = () => [
Expand Down Expand Up @@ -49,8 +47,21 @@ class Scroll implements Action {
await focusEditor(originalEditor);
}

const decorationSelections = targets
.map((target) => target.selection)
.filter((selection) => {
const visibleRanges = selection.editor.visibleRanges;
const start = visibleRanges[0].start;
const end = visibleRanges[visibleRanges.length - 1].end;
// Don't show decorations for selections that are larger than the visible range
return (
selection.selection.start.isAfterOrEqual(start) ||
selection.selection.end.isBeforeOrEqual(end)
);
});

await displayPendingEditDecorationsForSelection(
targets.map((target) => target.selection),
decorationSelections,
this.graph.editStyles.referenced.line
);

Expand Down