1 utils = require 'utils'
3 CONTAINER_ID = 'VimFxFindContainer'
5 # Create and inserts into DOM find controls and handlers
6 injectFind = (document) ->
7 # Clean up just in case...
10 container = createFindContainer(document)
12 document.documentElement.appendChild container
14 # Removes find controls from DOM
15 removeFind = (document) ->
16 if div = document.getElementById CONTAINER_ID
17 document.documentElement.removeChild div
19 setFindStr = (document, findStr) ->
22 span = document.getElementById "VimFxFindSpan"
23 span.textContent = "/#{ findStr }"
25 createFindContainer = (document) ->
26 return utils.parseHTML document, """
27 <div class="VimFxReset" id="#{ CONTAINER_ID }">
28 <span class="VimFxReset" id="VimFxFindSpan">/</span>
32 find = (window, findStr, backwards=false) ->
34 smartCase = findStr.toLowerCase() != findStr
38 smartCase, # Smart case sensitivity
39 backwards, # To avoid getting last search result in the beginning
40 true, # aWrapAround - Doesn't currently work as expected
41 false, # aWholeWord - Not implemented according to MDN
42 true, # aSearchInFrames - Hell yea, search in frames!
43 false # aShowDialog - No dialog please
48 # Perform find only if query string isn't empty to avoid find dialog pop up
50 # Wrap Around is broken... Therefore
52 # If first search attemp has failed then
53 # reset current selection and try again
54 window.getSelection().removeAllRanges()
60 exports.injectFind = injectFind
61 exports.removeFind = removeFind
62 exports.setFindStr = setFindStr