convertAll button in Ktxt2 editor
This commit is contained in:
@@ -63,7 +63,8 @@
|
||||
(function :String toString [:Array<KTxt2Element> elements]
|
||||
(apply +
|
||||
(for element elements
|
||||
"${blockStartEnd}${element.source}$(if element.outputLocked lockedStart unlockedStart)${element.output}${blockStartEnd}")))
|
||||
(assertLet [(Block (objectWith source outputLocked output)) element]
|
||||
"${blockStartEnd}${source}$(if outputLocked lockedStart unlockedStart)${output}${blockStartEnd}"))))
|
||||
|
||||
// To save window space after each block editor, ¶ can be used in place of \n\n
|
||||
(function :String applySpecialChars [:String text]
|
||||
@@ -101,4 +102,17 @@
|
||||
(objectWith sourceType outputType canConvert name))
|
||||
(dictSet validMap name c))
|
||||
(otherwise {})))
|
||||
validMap))
|
||||
validMap))
|
||||
|
||||
(#when (or sys hxnodejs)
|
||||
(function :String tryFullAutoConvert [:String ktxt2File :Array<KTxt2Conversion> conversions]
|
||||
(let [elements (splitFileElements (Stream.fromFile ktxt2File))
|
||||
[base sourceExt outputExt _] (ktxt2File.split ".")]
|
||||
(doFor element elements
|
||||
(assertLet [(Block element) element]
|
||||
(unless element.outputLocked
|
||||
(let [conversions (validConversions conversions "${base}.${sourceExt}" "${base}.${outputExt}" element.source)]
|
||||
(when (= 1 (count conversions))
|
||||
(let [onlyConversion (first (collect (conversions.iterator)))]
|
||||
(set element.output (onlyConversion.convert element.source))))))))
|
||||
(toString elements))))
|
@@ -273,6 +273,9 @@
|
||||
(postMessage (objectWith [type "tryAutoConvert"] source output outputStart outputEnd)))
|
||||
(otherwise (throw "element $element is not a block"))))
|
||||
|
||||
(function tryFullAutoConvert []
|
||||
(postMessage (object type "tryFullAutoConvert")))
|
||||
|
||||
(function blockElements [source output locked idx]
|
||||
(let [outerDiv (document.createElement "div")
|
||||
:js.html.Element sourceDiv (cast (document.createElement "div"))
|
||||
@@ -280,7 +283,7 @@
|
||||
convertLink (document.createElement "a")
|
||||
xLink (document.createElement "a")
|
||||
lockLink (document.createElement "a")
|
||||
exportLink (document.createElement "a")
|
||||
fullConvLink (document.createElement "a")
|
||||
blockLinkBefore (document.createElement "a")
|
||||
blockLinkAfter (document.createElement "a") ]
|
||||
(outerDiv.setAttribute "class" "container")
|
||||
@@ -325,9 +328,9 @@
|
||||
(lockLink.addEventListener "click"
|
||||
->(changeLockStatus (nth ktxt2Elements idx) !locked))
|
||||
(outerDiv.appendChild lockLink)
|
||||
(set exportLink.innerHTML "export")
|
||||
(exportLink.addEventListener "click" export)
|
||||
(outerDiv.appendChild exportLink)
|
||||
(set fullConvLink.innerHTML "convertAll")
|
||||
(fullConvLink.addEventListener "click" tryFullAutoConvert)
|
||||
(outerDiv.appendChild fullConvLink)
|
||||
(content.appendChild outerDiv)
|
||||
(content.appendChild (document.createElement "br"))
|
||||
(content.appendChild blockLinkAfter)))
|
||||
@@ -413,4 +416,4 @@
|
||||
(scrollToPageTop))
|
||||
|
||||
(function export []
|
||||
(postMessage (object type "export")))
|
||||
(postMessage (object type "export")))
|
||||
|
@@ -51,6 +51,11 @@
|
||||
((objectWith [type "deleteBlock"] start end)
|
||||
(makeEdit
|
||||
->edit (edit.delete document.uri (new Range (streamPosToOffsetDocumentPos start -KTxt2.blockStartEnd.length) (streamPosToOffsetDocumentPos end KTxt2.blockStartEnd.length)))))
|
||||
|
||||
((object type "tryFullAutoConvert")
|
||||
(let [fullConverted (KTxt2.tryFullAutoConvert document.fileName Main.config.conversions)]
|
||||
(makeEdit
|
||||
->edit (edit.replace document.uri (let [fullText (document.getText)] (new Range (document.positionAt 0) (document.positionAt (- fullText.length 1)))) fullConverted))))
|
||||
((objectWith [type "tryAutoConvert"] source output outputStart outputEnd)
|
||||
(let [[base sourceExt outputExt _] (document.fileName.split ".")
|
||||
conversions
|
||||
|
Reference in New Issue
Block a user