map lines and sort lines use inputEditor

This commit is contained in:
2022-02-01 14:27:26 -07:00
parent 0cca471de4
commit c9358f1419
2 changed files with 7 additions and 4 deletions

View File

@@ -272,13 +272,15 @@
// Way to more forgivingly get long text inputs
(function :Promise<String> inputEditor [:String filename :String prompt]
(let [tempFile (joinPath extensionPath "temp" filename)
(let [previousEditor activeTextEditor
tempFile (joinPath extensionPath "temp" filename)
uri (if (FileSystem.exists tempFile)
(Uri.parse "file:$tempFile")
(Uri.parse "untitled:$tempFile"))]
(new Promise
->[resolve reject]
(awaitLet [doc (openTextDocument uri)
_ (doc.save)
editor (showTextDocument doc)]
(print "Enter ${prompt}, then save and close this editor.")
(let [&mut :Disposable closeEvent null]
@@ -287,7 +289,8 @@
->closedDoc
(when (= closedDoc.fileName doc.fileName)
(closeEvent.dispose)
(if editor.document.isDirty (reject "Input editor for $prompt was closed without saving.") (resolve (doc.getText)))))))))))
(awaitLet [_ (showTextDocument previousEditor.document)]
(if editor.document.isDirty (let [error "Input editor for $prompt was closed without saving."] (warningMessage error) (reject error)) (resolve (editor.document.getText))))))))))))
(#unless test
(var :Array<KTxt2Conversion> conversions [])

View File

@@ -16,7 +16,7 @@
(e.insert editor.selection.active mappedText))))))
(function mapLinesSync [&opt selectedText]
(awaitLet [mapFuncStr (inputBox)]
(awaitLet [mapFuncStr (inputEditor "mapLinesFunc.kiss" "a String->String function through which to map the selected lines")]
(let [:String->String mapFunc (evalString mapFuncStr)]
(_mapLinesSync selectedText mapFunc))))
@@ -31,7 +31,7 @@
(e.insert editor.selection.active (lines.join "\n")))))))
(function sortLinesSync [&opt selectedText]
(awaitLet [compareFuncStr (inputBox)]
(awaitLet [compareFuncStr (inputEditor "sortLinesFunc.kiss" "a (String,String) -> Int function with which to sort the selected lines")]
(_sortLinesSync selectedText (if (< 0 compareFuncStr.length) (evalString compareFuncStr) Reflect.compare))))