Command to import KTxt2 input file
This commit is contained in:
@@ -209,13 +209,15 @@
|
||||
|
||||
(loadFrom "kiss-vscode" "src/commands/KissTools.kiss")
|
||||
(loadFrom "kiss-vscode" "src/commands/ExtensionTools.kiss")
|
||||
(loadFrom "kiss-vscode" "src/commands/KTxt2Tools.kiss")
|
||||
|
||||
// Provided from Main.kiss via (set):
|
||||
(var &mut :Command tryLoadConfig)
|
||||
|
||||
(function :Void registerBuiltins [&opt leaderKeys]
|
||||
(unless leaderKeys (set leaderKeys ""))
|
||||
(let [prefix "Kiss-VSCode:$(if leaderKeys " [${leaderKeys}]" "")"]
|
||||
(let [prefix "Kiss-VSCode:$(if leaderKeys " [${leaderKeys}]" "")"
|
||||
ktxt2Prefix "KTxt2:$(if leaderKeys " [${leaderKeys}]" "")"]
|
||||
// In Main.kiss:
|
||||
(registerCommand "${prefix} [r]eload Config.kiss" tryLoadConfig)
|
||||
// In this file:
|
||||
@@ -228,7 +230,9 @@
|
||||
(registerCommand "${prefix} open corresponding .kiss/.hx [f]ile" showCorrespondingFile)
|
||||
// ExtensionTools.kiss:
|
||||
(registerCommand "${prefix} [u]pdate Kiss-VSCode" updateKissVscode)
|
||||
(registerCommand "${prefix} [t]est and [u]pdate Kiss-VSCode" testAndUpdateKissVscode)))
|
||||
(registerCommand "${prefix} [t]est and [u]pdate Kiss-VSCode" testAndUpdateKissVscode)
|
||||
// KTxt2.kiss:
|
||||
(registerCommand "${ktxt2Prefix} [i]mport input file" importKTxt2InputFile)))
|
||||
|
||||
// TODO standardize this with KissInterp
|
||||
(function :Void prepareInterp []
|
||||
|
1
projects/kiss-vscode/package-lock.json
generated
1
projects/kiss-vscode/package-lock.json
generated
@@ -5,7 +5,6 @@
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "kiss-vscode",
|
||||
"version": "0.0.18",
|
||||
"dependencies": {
|
||||
"monaco-editor": "^0.29.1"
|
||||
|
@@ -27,6 +27,8 @@
|
||||
(awaitLet [chosenItem (_quickPick (for =>key value stringMap (quickPickItem key (Std.string value))))]
|
||||
(when chosenItem (dictGet stringMap chosenItem.label))))
|
||||
|
||||
(defAlias &call openDialog Vscode.window.showOpenDialog)
|
||||
|
||||
// commands
|
||||
(defAlias &call executeCommand Vscode.commands.executeCommand)
|
||||
(function repeatCommand [command times]
|
||||
|
20
projects/kiss-vscode/src/commands/KTxt2Tools.kiss
Normal file
20
projects/kiss-vscode/src/commands/KTxt2Tools.kiss
Normal file
@@ -0,0 +1,20 @@
|
||||
// Command to import a file to a new KTxt2 file:
|
||||
(function :Void importKTxt2InputFile [&opt _]
|
||||
(awaitLet [uris (openDialog (object openLabel "Import" title "File to import as KTxt2 input" canSelectMany false))
|
||||
outputType (inputBox (object prompt "Output file extension"))
|
||||
splitBy (quickPickMap [=>"↵ (new line)" "\n" =>"¶ (new paragraph)" "\n\n" =>"Other (specify via text box)" ""])]
|
||||
(withValueOrInputBox splitBy
|
||||
(let [file .fsPath (first uris)
|
||||
outputType (if (outputType.startsWith ".") (outputType.substr 1) outputType)
|
||||
ktxt2Filename "${file}.${outputType}.ktxt2"
|
||||
&mut newContents ""
|
||||
:kiss.List<String> inputBlocks (.split (File.getContent file) splitBy)]
|
||||
(doFor block (inputBlocks.slice 0 -1)
|
||||
(+= newContents (_blockOf block splitBy)))
|
||||
(+= newContents (_blockOf (last inputBlocks) ""))
|
||||
(File.saveContent ktxt2Filename newContents)
|
||||
(executeCommand "workbench.action.quickOpen" ktxt2Filename)))))
|
||||
|
||||
(function _blockOf [inputText :String splitBy]
|
||||
(let [blockText (KTxt2.insertSpecialChars "${inputText}${splitBy}")]
|
||||
"${KTxt2.blockStartEnd}${blockText}${KTxt2.unlockedStart}${KTxt2.blockStartEnd}"))
|
@@ -119,4 +119,14 @@
|
||||
(when (= 1 (count conversions))
|
||||
(let [onlyConversion (first (collect (conversions.iterator)))]
|
||||
(set element.output (onlyConversion.convert element.source))))))))
|
||||
(toString elements))))
|
||||
(toString elements))))
|
||||
|
||||
(function :String insertSpecialChars [:String text]
|
||||
(let [text (text.replace "\r" "")]
|
||||
(cond
|
||||
((text.endsWith "\n\n")
|
||||
(+ (substr text 0 -2) "¶"))
|
||||
((text.endsWith "\n")
|
||||
(+ (substr text 0 -1) "↵"))
|
||||
(true
|
||||
text))))
|
@@ -9,16 +9,6 @@
|
||||
|
||||
(defNew [&prop :ExtensionContext context])
|
||||
|
||||
(method :String insertSpecialChars [:String text]
|
||||
(let [text (text.replace "\r" "")]
|
||||
(cond
|
||||
((text.endsWith "\n\n")
|
||||
(+ (substr text 0 -2) "¶"))
|
||||
((text.endsWith "\n")
|
||||
(+ (substr text 0 -1) "↵"))
|
||||
(true
|
||||
text))))
|
||||
|
||||
(method :Promise<Void> resolveCustomTextEditor [:TextDocument document :WebviewPanel webviewPanel :CancellationToken _token]
|
||||
// When a blank file with the ktxt2 extension is opened for the first time, give it an empty
|
||||
// block so the user can actually add to it:
|
||||
@@ -52,7 +42,7 @@
|
||||
(infoMessage message))
|
||||
((objectWith [type "replace"] text start end)
|
||||
(makeEdit
|
||||
->edit (edit.replace document.uri (rangeFromStartEnd start end) (insertSpecialChars text))))
|
||||
->edit (edit.replace document.uri (rangeFromStartEnd start end) (KTxt2.insertSpecialChars text))))
|
||||
((objectWith [type "insertBefore"] text position)
|
||||
(makeEdit
|
||||
->edit (edit.insert document.uri (streamPosToOffsetDocumentPos position -KTxt2.blockStartEnd.length) text)))
|
||||
|
Reference in New Issue
Block a user