Skip to content

Commit

Permalink
add command to send selection extended to whole line (#2051)
Browse files Browse the repository at this point in the history
* add command SendSelectionExtendedToWholeLine

* register command
  • Loading branch information
yuuuxt authored Feb 15, 2025
1 parent 5b73b23 commit 64fcd09
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
16 changes: 15 additions & 1 deletion release/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -1818,4 +1832,4 @@
"url": "https://github.com/ionide/ionide-vscode-fsharp.git"
},
"version": "7.24.0"
}
}
31 changes: 31 additions & 0 deletions src/Components/Fsi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 64fcd09

Please sign in to comment.