From f2800e0bcd9230b04292a864510ca4b2912e409d Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Sat, 18 Dec 2021 15:43:03 -0700 Subject: [PATCH] when you change a source block, prompt to convert it again --- projects/kiss-vscode/src/ktxt2/KTxt2Editor.hx | 3 ++- projects/kiss-vscode/src/ktxt2/KTxt2Editor.kiss | 14 ++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/projects/kiss-vscode/src/ktxt2/KTxt2Editor.hx b/projects/kiss-vscode/src/ktxt2/KTxt2Editor.hx index 941061ca..fab6a8c5 100644 --- a/projects/kiss-vscode/src/ktxt2/KTxt2Editor.hx +++ b/projects/kiss-vscode/src/ktxt2/KTxt2Editor.hx @@ -26,7 +26,8 @@ typedef EditorState = { startCursorPos:Int, endCursorPos:Int, lastSearch:String, - outputTerminator:String + outputTerminator:String, + sourceBlockChanged:Null }; typedef Disposable = { diff --git a/projects/kiss-vscode/src/ktxt2/KTxt2Editor.kiss b/projects/kiss-vscode/src/ktxt2/KTxt2Editor.kiss index c956feb0..eddab910 100644 --- a/projects/kiss-vscode/src/ktxt2/KTxt2Editor.kiss +++ b/projects/kiss-vscode/src/ktxt2/KTxt2Editor.kiss @@ -20,7 +20,8 @@ startCursorPos -1 endCursorPos -1 lastSearch "" - outputTerminator ""))) + outputTerminator "" + sourceBlockChanged null))) (function :Void setState [:EditorState state] (_vscode.setState state)) @@ -270,7 +271,8 @@ (s.dropString oldTerminator) (postMessage (objectWith [type "replace" text terminator end (s.position)] start)))) -(function replaceSourceBlock [element newText] +(function replaceSourceBlock [element idx newText] + (changeState s (set s.sourceBlockChanged idx)) (case element ((Block (object source text sourceStart start sourceEnd end)) (postMessage (object type "replace" text newText start start end end))) @@ -339,7 +341,7 @@ (content.appendChild (document.createElement "br")) (monacoEditor sourceDiv "width: 50%;" source /* TODO get the real extension of the source file: */ "txt" locked - ->editor (replaceSourceBlock (nth ktxt2Elements idx) (.replace (editor.getValue) "\r" ""))) + ->editor (replaceSourceBlock (nth ktxt2Elements idx) 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) (withOutputTerminator (.replace (editor.getValue) "\r" "")))) @@ -396,6 +398,11 @@ // (print "updating content because $reason") (try { + (when text (set ktxt2Elements (KTxt2.splitFileElements (Stream.fromString text)))) + (whenLet [sourceBlockChanged .sourceBlockChanged (getState)] + (changeState s (set s.sourceBlockChanged null)) + (tryAutoConvert (nth ktxt2Elements sourceBlockChanged)) + (return)) (set updatingContent true) (when content (set editors []) @@ -404,7 +411,6 @@ (document.body.removeChild content)) (set content (document.createElement "div")) (document.body.appendChild content) - (when text (set ktxt2Elements (KTxt2.splitFileElements (Stream.fromString text)))) (let [terminatorEditor (document.createElement "div") help (document.createElement "p") explanation (document.createElement "p")]