Skip to content

Commit 64fcd09

Browse files
authored
add command to send selection extended to whole line (#2051)
* add command SendSelectionExtendedToWholeLine * register command
1 parent 5b73b23 commit 64fcd09

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

release/package.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@
9292
"command": "fsi.SendSelection",
9393
"title": "FSI: Send Selection"
9494
},
95+
{
96+
"command": "fsi.SendSelectionExtendedToWholeLine",
97+
"title": "FSI: Send Selection Extended To Whole Line"
98+
},
9599
{
96100
"command": "fsi.SendLastSelection",
97101
"title": "FSI: Send Last Selection"
@@ -1015,6 +1019,12 @@
10151019
"mac": "alt\u002BEnter",
10161020
"when": "editorFocus \u0026\u0026 !findWidgetVisible \u0026\u0026 editorLangId == \u0027fsharp\u0027"
10171021
},
1022+
{
1023+
"command": "fsi.SendSelectionExtendedToWholeLine",
1024+
"key": "alt\u002Bshift\u002BEnter",
1025+
"mac": "alt\u002Bshift\u002BEnter",
1026+
"when": "editorFocus \u0026\u0026 !findWidgetVisible \u0026\u0026 editorLangId == \u0027fsharp\u0027"
1027+
},
10181028
{
10191029
"command": "fsharp.generateDoc",
10201030
"key": "alt\u002Bshift\u002Bj",
@@ -1195,6 +1205,10 @@
11951205
"command": "fsi.SendSelection",
11961206
"when": "editorLangId == \u0027fsharp\u0027"
11971207
},
1208+
{
1209+
"command": "fsi.SendSelectionExtendedToWholeLine",
1210+
"when": "editorLangId == \u0027fsharp\u0027"
1211+
},
11981212
{
11991213
"command": "fsi.SendLastSelection",
12001214
"when": "editorLangId == \u0027fsharp\u0027"
@@ -1818,4 +1832,4 @@
18181832
"url": "https://github.com/ionide/ionide-vscode-fsharp.git"
18191833
},
18201834
"version": "7.24.0"
1821-
}
1835+
}

src/Components/Fsi.fs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,34 @@ module Fsi =
562562
do! send terminal text
563563
}
564564

565+
let private sendSelectionExtendedToWholeLine () =
566+
let editor = window.activeTextEditor.Value
567+
568+
promise {
569+
if editor.selection.isEmpty then
570+
do! sendLine ()
571+
else
572+
// Note: Handle terminal stuff only in this part of the if/else branch
573+
// because sendLine will already handle it for the other branch
574+
575+
let! terminal = getTerminal ()
576+
577+
sendCd terminal (Some editor)
578+
579+
let range =
580+
vscode.Range.Create(
581+
editor.selection.anchor.line,
582+
editor.selection.anchor.character,
583+
editor.selection.active.line,
584+
editor.selection.active.character
585+
)
586+
587+
let fullRange = vscode.Range.Create(range.start.line, 0, range.``end``.line + 1., 0)
588+
let text = editor.document.getText fullRange
589+
590+
do! send terminal text
591+
}
592+
565593
let private sendLastSelection () =
566594
promise {
567595
match lastSelectionSent with
@@ -681,6 +709,9 @@ module Fsi =
681709
commands.registerCommand ("fsi.SendSelection", sendSelection |> objfy2)
682710
|> context.Subscribe
683711

712+
commands.registerCommand ("fsi.SendSelectionExtendedToWholeLine", sendSelectionExtendedToWholeLine |> objfy2)
713+
|> context.Subscribe
714+
684715
commands.registerCommand ("fsi.SendLastSelection", sendLastSelection |> objfy2)
685716
|> context.Subscribe
686717

0 commit comments

Comments
 (0)