force output blocks to end with a specific terminator

This commit is contained in:
2021-12-18 14:42:14 -07:00
parent 1594c8de4e
commit 972a66f1bd
3 changed files with 17 additions and 2 deletions

View File

@@ -10,6 +10,10 @@
(var outputStarts [unlockedStart lockedStart])
(var emptyBlock "${blockStartEnd}${unlockedStart}${blockStartEnd}")
(function :String outputBlockTerminator [:Stream fileStream]
(whenLet [(Some terminator) (fileStream.takeUntilOneOf [blockStartEnd] true)]
terminator))
(function :Array<KTxt2Element> splitFileElements [:Stream fileStream]
(let [elements []]
(loop

View File

@@ -26,6 +26,7 @@ typedef EditorState = {
startCursorPos:Int,
endCursorPos:Int,
lastSearch:String,
outputTerminator:String
};
typedef Disposable = {

View File

@@ -19,7 +19,8 @@
activeEditorIdx -1
startCursorPos -1
endCursorPos -1
lastSearch "")))
lastSearch ""
outputTerminator "")))
(function :Void setState [:EditorState state]
(_vscode.setState state))
@@ -44,6 +45,7 @@
// Either create the first EditorState, or get the last one
(changeState newState
(set newState.text text)
(set newState.outputTerminator (KTxt2.outputBlockTerminator (Stream.fromString text)))
(whenMonacoIsAvailable
->{
(updateContent "told by the provider" text)
@@ -290,6 +292,14 @@
(function tryFullAutoConvert []
(postMessage (object type "tryFullAutoConvert")))
(function withOutputTerminator [:String text]
(if text
(let [outputTerminator .outputTerminator (getState)]
(if (text.endsWith outputTerminator)
text
"${text}$outputTerminator"))
text))
(function blockElements [source output locked idx]
(let [outerDiv (document.createElement "div")
:js.html.Element sourceDiv (cast (document.createElement "div"))
@@ -321,7 +331,7 @@
->editor (replaceSourceBlock (nth ktxt2Elements idx) (.replace (editor.getValue) "\r" "")))
(monacoEditor outputDiv "flex-grow: 1;" output /* TODO get the real extension of the output file: */ "txt" locked
->editor (replaceOutputBlock (nth ktxt2Elements idx) (.replace (editor.getValue) "\r" "")))
->editor (replaceOutputBlock (nth ktxt2Elements idx) (withOutputTerminator (.replace (editor.getValue) "\r" ""))))
// Link that will delete the whole block:
(set xLink.innerHTML "x")