Ctrl+f in ktxt2 editor
This commit is contained in:
@@ -34,7 +34,7 @@
|
|||||||
(window.addEventListener "message"
|
(window.addEventListener "message"
|
||||||
->:Void event
|
->:Void event
|
||||||
(case (the MessageToEditor event.data)
|
(case (the MessageToEditor event.data)
|
||||||
((object type "update" text text)
|
((objectWith [type "update"] text)
|
||||||
// Either create the first EditorState, or get the last one
|
// Either create the first EditorState, or get the last one
|
||||||
(let [newState (getState)]
|
(let [newState (getState)]
|
||||||
(set newState.text text)
|
(set newState.text text)
|
||||||
@@ -44,6 +44,8 @@
|
|||||||
(updateContent "told by the provider" text)
|
(updateContent "told by the provider" text)
|
||||||
(activateFromState newState)
|
(activateFromState newState)
|
||||||
})))
|
})))
|
||||||
|
((objectWith [type "find"] text)
|
||||||
|
(_find text))
|
||||||
(otherType (throw "bad message $event for KTxt2Editor"))))
|
(otherType (throw "bad message $event for KTxt2Editor"))))
|
||||||
|
|
||||||
(window.addEventListener "scroll"
|
(window.addEventListener "scroll"
|
||||||
@@ -52,6 +54,10 @@
|
|||||||
(setState s)))
|
(setState s)))
|
||||||
|
|
||||||
(window.addEventListener "keydown" ->:Void e
|
(window.addEventListener "keydown" ->:Void e
|
||||||
|
(if e.ctrlKey
|
||||||
|
(case e.key
|
||||||
|
("f" (find))
|
||||||
|
(otherwise))
|
||||||
(unless activeEditor
|
(unless activeEditor
|
||||||
(case e.key
|
(case e.key
|
||||||
("g" (pageTop))
|
("g" (pageTop))
|
||||||
@@ -61,7 +67,7 @@
|
|||||||
("ArrowLeft" (scrollToPageTop))
|
("ArrowLeft" (scrollToPageTop))
|
||||||
("ArrowRight" (scrollToPageBottom))
|
("ArrowRight" (scrollToPageBottom))
|
||||||
("s" (export))
|
("s" (export))
|
||||||
(otherwise))))
|
(otherwise)))))
|
||||||
|
|
||||||
// Don't use getState helper here because we don't want to force updateContent with blank text
|
// Don't use getState helper here because we don't want to force updateContent with blank text
|
||||||
(whenLet [state (the EditorState (_vscode.getState))]
|
(whenLet [state (the EditorState (_vscode.getState))]
|
||||||
@@ -444,3 +450,23 @@
|
|||||||
|
|
||||||
(function export []
|
(function export []
|
||||||
(postMessage (object type "export")))
|
(postMessage (object type "export")))
|
||||||
|
|
||||||
|
(function find []
|
||||||
|
(postMessage (object type "find")))
|
||||||
|
|
||||||
|
(defMacro __find []
|
||||||
|
`(let [elem (nth ktxt2Elements idx)]
|
||||||
|
(assertLet [(Block block) elem]
|
||||||
|
(whenLet [(Some foundIdx) (indexOf "${block.source}${block.output}" text)]
|
||||||
|
(changeElementScrollY ->(set elementScrollY idx))
|
||||||
|
(return)))))
|
||||||
|
|
||||||
|
(function :Void _find [text]
|
||||||
|
// TODO use (indexOf) to find the text in source/output of elements, then set elementScrollY to that element
|
||||||
|
(let [startIdx elementScrollY]
|
||||||
|
(doFor idx (range (+ 1 startIdx) ktxt2Elements.length)
|
||||||
|
(__find))
|
||||||
|
(doFor idx (range 0 (+ 1 startIdx))
|
||||||
|
(__find))
|
||||||
|
|
||||||
|
(print "No occurances of `${text}` were found.")))
|
||||||
|
@@ -74,6 +74,9 @@
|
|||||||
(errorMessage "No automatic conversions are valid for the chosen block."))))
|
(errorMessage "No automatic conversions are valid for the chosen block."))))
|
||||||
((object type "export")
|
((object type "export")
|
||||||
(exportSourceAndOutputFiles document))
|
(exportSourceAndOutputFiles document))
|
||||||
|
((object type "find")
|
||||||
|
(awaitLet [str (inputBox)]
|
||||||
|
(webviewPanel.webview.postMessage (object type "find" text str))))
|
||||||
(otherwise
|
(otherwise
|
||||||
(errorMessage "bad message $e from KTxt2Editor"))))
|
(errorMessage "bad message $e from KTxt2Editor"))))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user