Links to insert blocks in Ktxt2
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
(var unlockedStart "|>|")
|
(var unlockedStart "|>|")
|
||||||
(var lockedStart "|!|")
|
(var lockedStart "|!|")
|
||||||
(var outputStarts [unlockedStart lockedStart])
|
(var outputStarts [unlockedStart lockedStart])
|
||||||
|
(var emptyBlock "${blockStartEnd}${unlockedStart}${blockStartEnd}")
|
||||||
|
|
||||||
// Return [sourceFile outputFile]
|
// Return [sourceFile outputFile]
|
||||||
(function :Array<String> splitFileContents [:Stream fileStream]
|
(function :Array<String> splitFileContents [:Stream fileStream]
|
||||||
|
@@ -37,14 +37,27 @@
|
|||||||
}
|
}
|
||||||
EDIT_TIMEOUT_MILLI)))
|
EDIT_TIMEOUT_MILLI)))
|
||||||
|
|
||||||
(function pElement [text idx]
|
(function commentElements [text idx]
|
||||||
(let [p (document.createElement "p")]
|
(let [p (document.createElement "p")
|
||||||
|
blockLinkBefore (document.createElement "a")
|
||||||
|
blockLinkAfter (document.createElement "a")]
|
||||||
|
// Links that allow inserting a block between existing blocks:
|
||||||
|
(set blockLinkBefore.innerHTML "+")
|
||||||
|
(blockLinkBefore.addEventListener "click"
|
||||||
|
->(insertBlockBeforeComment (nth ktxt2Elements idx)))
|
||||||
|
(set blockLinkAfter.innerHTML "+")
|
||||||
|
(blockLinkAfter.addEventListener "click"
|
||||||
|
->(insertBlockAfterComment (nth ktxt2Elements idx)))
|
||||||
|
|
||||||
|
// Paragraph displaying and allowing editing the comment
|
||||||
(set p.innerHTML text)
|
(set p.innerHTML text)
|
||||||
(p.setAttribute "style" "white-space: pre;")
|
(p.setAttribute "style" "white-space: pre;")
|
||||||
(p.setAttribute "contenteditable" "true")
|
(p.setAttribute "contenteditable" "true")
|
||||||
(p.addEventListener "input"
|
(p.addEventListener "input"
|
||||||
->(addEditTimeout idx ->(replaceComment (nth ktxt2Elements idx) p.innerHTML)))
|
->(addEditTimeout idx ->(replaceComment (nth ktxt2Elements idx) p.innerHTML)))
|
||||||
(content.appendChild p)))
|
(content.appendChild blockLinkBefore)
|
||||||
|
(content.appendChild p)
|
||||||
|
(content.appendChild blockLinkAfter)))
|
||||||
|
|
||||||
(function toPlaintext [:String text]
|
(function toPlaintext [:String text]
|
||||||
(.htmlUnescape
|
(.htmlUnescape
|
||||||
@@ -60,6 +73,18 @@
|
|||||||
(vscode.postMessage (object type "replace" text (toPlaintext newText) start start end end)))
|
(vscode.postMessage (object type "replace" text (toPlaintext newText) start start end end)))
|
||||||
(otherwise (throw "element $element is not a comment"))))
|
(otherwise (throw "element $element is not a comment"))))
|
||||||
|
|
||||||
|
(function insertBlockBeforeComment [element]
|
||||||
|
(case element
|
||||||
|
((Comment (object start position))
|
||||||
|
(vscode.postMessage (object type "insert" text "${KTxt2.emptyBlock}\n" position position)))
|
||||||
|
(otherwise (throw "element $element is not a comment"))))
|
||||||
|
|
||||||
|
(function insertBlockAfterComment [element]
|
||||||
|
(case element
|
||||||
|
((Comment (object end position))
|
||||||
|
(vscode.postMessage (object type "insert" text "${KTxt2.emptyBlock}\n" position position)))
|
||||||
|
(otherwise (throw "element $element is not a comment"))))
|
||||||
|
|
||||||
(function replaceSourceBlock [element newText]
|
(function replaceSourceBlock [element newText]
|
||||||
(case element
|
(case element
|
||||||
((Block (object source text sourceStart start sourceEnd end))
|
((Block (object source text sourceStart start sourceEnd end))
|
||||||
@@ -113,7 +138,7 @@
|
|||||||
(case element
|
(case element
|
||||||
// TODO make an objectWith macro for case that duplicates parameter names with the match expressions:
|
// TODO make an objectWith macro for case that duplicates parameter names with the match expressions:
|
||||||
((Comment (object text text))
|
((Comment (object text text))
|
||||||
(pElement text idx))
|
(commentElements text idx))
|
||||||
((Block (object source source output output outputLocked outputLocked))
|
((Block (object source source output output outputLocked outputLocked))
|
||||||
(blockElements source output outputLocked idx))))
|
(blockElements source output outputLocked idx))))
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,8 @@ typedef MessageFromEditor = {
|
|||||||
type:String,
|
type:String,
|
||||||
?text:String,
|
?text:String,
|
||||||
?start:kiss.Stream.Position,
|
?start:kiss.Stream.Position,
|
||||||
?end:kiss.Stream.Position
|
?end:kiss.Stream.Position,
|
||||||
|
?position:kiss.Stream.Position
|
||||||
};
|
};
|
||||||
|
|
||||||
@:build(kiss.Kiss.build())
|
@:build(kiss.Kiss.build())
|
||||||
|
@@ -33,6 +33,9 @@
|
|||||||
((object type "replace" text text start start end end)
|
((object type "replace" text text start start end end)
|
||||||
(makeEdit
|
(makeEdit
|
||||||
->edit (edit.replace document.uri (rangeFromStartEnd start end) text)))
|
->edit (edit.replace document.uri (rangeFromStartEnd start end) text)))
|
||||||
|
((object type "insert" text text position position)
|
||||||
|
(makeEdit
|
||||||
|
->edit (edit.insert document.uri (streamPosToDocumentPos position) text)))
|
||||||
(otherwise
|
(otherwise
|
||||||
(Vscode.window.showErrorMessage "bad message $e from KTxt2Editor"))))
|
(Vscode.window.showErrorMessage "bad message $e from KTxt2Editor"))))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user