From 2616e04d5e19924eb5364e66aa9fdb728ade9081 Mon Sep 17 00:00:00 2001 From: Pokey Rule Date: Fri, 17 Dec 2021 17:03:14 +0000 Subject: [PATCH 1/3] Revert "Allow to fold single line (#394)" This reverts commit 8117983d6ed5b3242855264e6f89079ebad4ecb6. --- src/actions/Fold.ts | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/actions/Fold.ts b/src/actions/Fold.ts index fe8d783bae..622e78536c 100644 --- a/src/actions/Fold.ts +++ b/src/actions/Fold.ts @@ -1,4 +1,4 @@ -import { commands, window } from "vscode"; +import { commands } from "vscode"; import { Action, ActionPreferences, @@ -6,13 +6,10 @@ import { Graph, TypedSelection, } from "../typings/Types"; -import { focusEditor } from "../util/setSelectionsAndFocusEditor"; import { ensureSingleEditor } from "../util/targetUtils"; class FoldAction implements Action { - getTargetPreferences: () => ActionPreferences[] = () => [ - { insideOutsideType: "inside" }, - ]; + getTargetPreferences: () => ActionPreferences[] = () => [{ insideOutsideType: "outside" }]; constructor(private command: string) { this.run = this.run.bind(this); @@ -22,26 +19,16 @@ class FoldAction implements Action { TypedSelection[], TypedSelection[] ]): Promise { - const originalEditor = window.activeTextEditor; - const editor = ensureSingleEditor(targets); - - if (originalEditor !== editor) { - await focusEditor(editor); - } + ensureSingleEditor(targets); await commands.executeCommand(this.command, { levels: 1, direction: "down", - selectionLines: targets.map( - (target) => target.selection.selection.start.line - ), + selectionLines: targets + .filter((target) => !target.selection.selection.isSingleLine) + .map((target) => target.selection.selection.start.line), }); - // If necessary focus back original editor - if (originalEditor != null && originalEditor !== window.activeTextEditor) { - await focusEditor(originalEditor); - } - return { thatMark: targets.map((target) => target.selection), }; From b6abcd0aac5a752b6b3c211da934c36e85091f56 Mon Sep 17 00:00:00 2001 From: Pokey Rule Date: Fri, 17 Dec 2021 17:07:44 +0000 Subject: [PATCH 2/3] Keep good changes --- src/actions/Fold.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/actions/Fold.ts b/src/actions/Fold.ts index 622e78536c..fe8d783bae 100644 --- a/src/actions/Fold.ts +++ b/src/actions/Fold.ts @@ -1,4 +1,4 @@ -import { commands } from "vscode"; +import { commands, window } from "vscode"; import { Action, ActionPreferences, @@ -6,10 +6,13 @@ import { Graph, TypedSelection, } from "../typings/Types"; +import { focusEditor } from "../util/setSelectionsAndFocusEditor"; import { ensureSingleEditor } from "../util/targetUtils"; class FoldAction implements Action { - getTargetPreferences: () => ActionPreferences[] = () => [{ insideOutsideType: "outside" }]; + getTargetPreferences: () => ActionPreferences[] = () => [ + { insideOutsideType: "inside" }, + ]; constructor(private command: string) { this.run = this.run.bind(this); @@ -19,16 +22,26 @@ class FoldAction implements Action { TypedSelection[], TypedSelection[] ]): Promise { - ensureSingleEditor(targets); + const originalEditor = window.activeTextEditor; + const editor = ensureSingleEditor(targets); + + if (originalEditor !== editor) { + await focusEditor(editor); + } await commands.executeCommand(this.command, { levels: 1, direction: "down", - selectionLines: targets - .filter((target) => !target.selection.selection.isSingleLine) - .map((target) => target.selection.selection.start.line), + selectionLines: targets.map( + (target) => target.selection.selection.start.line + ), }); + // If necessary focus back original editor + if (originalEditor != null && originalEditor !== window.activeTextEditor) { + await focusEditor(originalEditor); + } + return { thatMark: targets.map((target) => target.selection), }; From 40a6803d2c7158ec4088d4b8ecd04a8eda601238 Mon Sep 17 00:00:00 2001 From: Pokey Rule Date: Fri, 17 Dec 2021 17:08:01 +0000 Subject: [PATCH 3/3] Keep good changes --- src/actions/Fold.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/actions/Fold.ts b/src/actions/Fold.ts index fe8d783bae..6631d0814c 100644 --- a/src/actions/Fold.ts +++ b/src/actions/Fold.ts @@ -32,9 +32,9 @@ class FoldAction implements Action { await commands.executeCommand(this.command, { levels: 1, direction: "down", - selectionLines: targets.map( - (target) => target.selection.selection.start.line - ), + selectionLines: targets + .filter((target) => !target.selection.selection.isSingleLine) + .map((target) => target.selection.selection.start.line), }); // If necessary focus back original editor