From 64fcd09173e8bda0d434df7ca24469d9316181c2 Mon Sep 17 00:00:00 2001 From: yuuuxt Date: Sat, 15 Feb 2025 11:51:39 +0800 Subject: [PATCH] add command to send selection extended to whole line (#2051) * add command SendSelectionExtendedToWholeLine * register command --- release/package.json | 16 +++++++++++++++- src/Components/Fsi.fs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/release/package.json b/release/package.json index 02d7cbdf..64df5500 100644 --- a/release/package.json +++ b/release/package.json @@ -92,6 +92,10 @@ "command": "fsi.SendSelection", "title": "FSI: Send Selection" }, + { + "command": "fsi.SendSelectionExtendedToWholeLine", + "title": "FSI: Send Selection Extended To Whole Line" + }, { "command": "fsi.SendLastSelection", "title": "FSI: Send Last Selection" @@ -1015,6 +1019,12 @@ "mac": "alt\u002BEnter", "when": "editorFocus \u0026\u0026 !findWidgetVisible \u0026\u0026 editorLangId == \u0027fsharp\u0027" }, + { + "command": "fsi.SendSelectionExtendedToWholeLine", + "key": "alt\u002Bshift\u002BEnter", + "mac": "alt\u002Bshift\u002BEnter", + "when": "editorFocus \u0026\u0026 !findWidgetVisible \u0026\u0026 editorLangId == \u0027fsharp\u0027" + }, { "command": "fsharp.generateDoc", "key": "alt\u002Bshift\u002Bj", @@ -1195,6 +1205,10 @@ "command": "fsi.SendSelection", "when": "editorLangId == \u0027fsharp\u0027" }, + { + "command": "fsi.SendSelectionExtendedToWholeLine", + "when": "editorLangId == \u0027fsharp\u0027" + }, { "command": "fsi.SendLastSelection", "when": "editorLangId == \u0027fsharp\u0027" @@ -1818,4 +1832,4 @@ "url": "https://github.com/ionide/ionide-vscode-fsharp.git" }, "version": "7.24.0" -} \ No newline at end of file +} diff --git a/src/Components/Fsi.fs b/src/Components/Fsi.fs index e963f7b6..0cda51bc 100644 --- a/src/Components/Fsi.fs +++ b/src/Components/Fsi.fs @@ -562,6 +562,34 @@ module Fsi = do! send terminal text } + let private sendSelectionExtendedToWholeLine () = + let editor = window.activeTextEditor.Value + + promise { + if editor.selection.isEmpty then + do! sendLine () + else + // Note: Handle terminal stuff only in this part of the if/else branch + // because sendLine will already handle it for the other branch + + let! terminal = getTerminal () + + sendCd terminal (Some editor) + + let range = + vscode.Range.Create( + editor.selection.anchor.line, + editor.selection.anchor.character, + editor.selection.active.line, + editor.selection.active.character + ) + + let fullRange = vscode.Range.Create(range.start.line, 0, range.``end``.line + 1., 0) + let text = editor.document.getText fullRange + + do! send terminal text + } + let private sendLastSelection () = promise { match lastSelectionSent with @@ -681,6 +709,9 @@ module Fsi = commands.registerCommand ("fsi.SendSelection", sendSelection |> objfy2) |> context.Subscribe + commands.registerCommand ("fsi.SendSelectionExtendedToWholeLine", sendSelectionExtendedToWholeLine |> objfy2) + |> context.Subscribe + commands.registerCommand ("fsi.SendLastSelection", sendLastSelection |> objfy2) |> context.Subscribe