From a263fc5535239877225a5969efa16fa8da1fe651 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Mon, 29 Nov 2021 14:17:38 +0100 Subject: [PATCH] Removed additional highlight before scroll (#337) Co-authored-by: Pokey Rule --- package.json | 5 ---- src/actions/Scroll.ts | 53 ++++++++++++++++-------------------- src/util/editDisplayUtils.ts | 44 ------------------------------ 3 files changed, 23 insertions(+), 79 deletions(-) diff --git a/package.json b/package.json index dff5e2bc46..b259713c2d 100644 --- a/package.json +++ b/package.json @@ -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, diff --git a/src/actions/Scroll.ts b/src/actions/Scroll.ts index 3684276587..9d5dce4222 100644 --- a/src/actions/Scroll.ts +++ b/src/actions/Scroll.ts @@ -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); @@ -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("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 { diff --git a/src/util/editDisplayUtils.ts b/src/util/editDisplayUtils.ts index 249e4e7ba4..4dc3f888a4 100644 --- a/src/util/editDisplayUtils.ts +++ b/src/util/editDisplayUtils.ts @@ -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, - 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) &&