From 8783569983d8b3634b1b1eed9b6560dbea5698ab Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 21 Mar 2016 09:09:03 +0000 Subject: Rework visual mode. - Refactor the three visual-mode modes. - Use the key-handling framework from #2022. - Strip some legacy edit-mode code. - Rename the file (the old file name was misleading). - Add "aw" and "as", previously we had the code for this from edit mode. --- lib/dom_utils.coffee | 45 --------------------------------------------- 1 file changed, 45 deletions(-) (limited to 'lib') diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee index 3581bd3f..00b6c676 100644 --- a/lib/dom_utils.coffee +++ b/lib/dom_utils.coffee @@ -306,51 +306,6 @@ DomUtils = t = o || t?.parentNode t - # This calculates the caret coordinates within an input element. It is used by edit mode to calculate the - # caret position for scrolling. It creates a hidden div contain a mirror of element, and all of the text - # from element up to position, then calculates the scroll position. - # From: https://github.com/component/textarea-caret-position/blob/master/index.js - getCaretCoordinates: do -> - # The properties that we copy to the mirrored div. - properties = [ - 'direction', 'boxSizing', 'width', 'height', 'overflowX', 'overflowY', - 'borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth', - 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', - 'fontStyle', 'fontVariant', 'fontWeight', 'fontStretch', 'fontSize', 'fontSizeAdjust', - 'lineHeight', 'fontFamily', - 'textAlign', 'textTransform', 'textIndent', 'textDecoration', - 'letterSpacing', 'wordSpacing' ] - - (element, position) -> - div = @createElement "div" - div.id = "vimium-input-textarea-caret-position-mirror-div" - document.body.appendChild div - - style = div.style - computed = getComputedStyle element - - style.whiteSpace = "pre-wrap" - style.wordWrap = "break-word" if element.nodeName.toLowerCase() != "input" - style.position = "absolute" - style.visibility = "hidden" - style[prop] = computed[prop] for prop in properties - style.overflow = "hidden" - - div.textContent = element.value.substring 0, position - if element.nodeName.toLowerCase() == "input" - div.textContent = div.textContent.replace /\s/g, "\u00a0" - - span = @createElement "span" - span.textContent = element.value.substring(position) || "." - div.appendChild span - - coordinates = - top: span.offsetTop + parseInt computed["borderTopWidth"] - left: span.offsetLeft + parseInt computed["borderLeftWidth"] - - document.body.removeChild div - coordinates - getSelectionFocusElement: -> sel = window.getSelection() if not sel.focusNode? -- cgit v1.2.3