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

Removed additional highlight before scroll #337

Merged
merged 2 commits into from
Nov 29, 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
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@
"default": 100,
"description": "How long in milliseconds to show a pending edit decoration"
},
"cursorless.showAdditionalHighlightBeforeScroll": {
"type": "boolean",
"default": false,
"description": "Whether to show a highlight before scrolling in addition to after"
},
"cursorless.hatSizeAdjustment": {
"type": "number",
"default": 0,
Expand Down
53 changes: 23 additions & 30 deletions src/actions/Scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import {
Graph,
TypedSelection,
} from "../typings/Types";
import { displayDecorationsWhileRunningFunc } from "../util/editDisplayUtils";
import { groupBy } from "../util/itertools";
import { commands, window, workspace } from "vscode";
import { commands, window } from "vscode";
import { focusEditor } from "../util/setSelectionsAndFocusEditor";
import {
displayPendingEditDecorationsForSelection,
} from "../util/editDisplayUtils";

class Scroll implements Action {
getTargetPreferences: () => ActionPreferences[] = () => [{ insideOutsideType: "inside" }];
getTargetPreferences: () => ActionPreferences[] = () => [
{ insideOutsideType: "inside" },
];

constructor(private graph: Graph, private at: string) {
this.run = this.run.bind(this);
Expand All @@ -27,38 +31,27 @@ class Scroll implements Action {
return { lineNumber: getLineNumber(targets, this.at), editor };
});

const scrollCallback = async () => {
const originalEditor = window.activeTextEditor;

for (const lineWithEditor of lines) {
// For reveal line to the work we have to have the correct editor focused
if (lineWithEditor.editor !== window.activeTextEditor) {
await focusEditor(lineWithEditor.editor);
}
await commands.executeCommand("revealLine", {
lineNumber: lineWithEditor.lineNumber,
at: this.at,
});
}
const originalEditor = window.activeTextEditor;

// If necessary focus back original editor
if (
originalEditor != null &&
originalEditor !== window.activeTextEditor
) {
await focusEditor(originalEditor);
for (const lineWithEditor of lines) {
// For reveal line to the work we have to have the correct editor focused
if (lineWithEditor.editor !== window.activeTextEditor) {
await focusEditor(lineWithEditor.editor);
}
};
await commands.executeCommand("revealLine", {
lineNumber: lineWithEditor.lineNumber,
at: this.at,
});
}

const showAdditionalHighlightBeforeScroll = workspace
.getConfiguration("cursorless")
.get<boolean>("showAdditionalHighlightBeforeScroll")!;
// If necessary focus back original editor
if (originalEditor != null && originalEditor !== window.activeTextEditor) {
await focusEditor(originalEditor);
}

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

return {
Expand Down
44 changes: 0 additions & 44 deletions src/util/editDisplayUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,50 +98,6 @@ export default async function displayPendingEditDecorations(
});
}

/**
1. Shows decorations.
2. Wait for pending edit decoration time while subtracting the time it takes to actually run the callback
3. Removes decorations
*/
export async function displayDecorationsWhileRunningFunc(
selections: SelectionWithEditor[],
decorationType: TextEditorDecorationType,
callback: () => Promise<void>,
showAdditionalHighlightBeforeCallback: boolean
) {
if (!showAdditionalHighlightBeforeCallback) {
await callback();
}

await runForEachEditor(
selections,
(s) => s.editor,
async (editor, selections) => {
editor.setDecorations(
decorationType,
selections.map((s) => s.selection)
);
}
);

const pendingEditDecorationTime = getPendingEditDecorationTime();

if (showAdditionalHighlightBeforeCallback) {
await sleep(pendingEditDecorationTime);
await callback();
}

await sleep(pendingEditDecorationTime);

await runForEachEditor(
selections,
(s) => s.editor,
async (editor) => {
editor.setDecorations(decorationType, []);
}
);
}

function useLineDecorations(selection: TypedSelection) {
return (
isLineSelectionType(selection.selectionType) &&
Expand Down