双击选择带连字符的单词

时间:2012-11-20 15:43:10

标签: windows google-chrome windows-7

更新:根据下面的建议,这里特别是我想做的事情:如果我双击鼠标光标从“b”到“蓝绿”的“n”,我想要全部应突出显示“蓝绿色”一词。如何才能做到这一点?目前,根据您单击的位置,它将“蓝绿色”视为三个单独的字符串。因此,如果您在“蓝色”的“b”和“e”之间双击,则仅突出显示“蓝色”而不是“绿色”。如果双击连字符,它会单独突出显示连字符。如果你在“绿色”的“g”和“n”之间双击,它只会突出显示“绿色”而不是“蓝色 - ”。

ORIGINAL:当我双击带连字符的单词或一组字符(例如“123-abc”或“blue-green”等)时,只会双击我双击的单词部分。我希望突出整个词。

我正在使用Windows 7专业版。如果需要在每个应用程序的基础上完成,我最感兴趣的是为Google Chrome修复它,但任何与Windows兼容的Web浏览器都可以。

2 个答案:

答案 0 :(得分:1)

老问题,但我碰巧在同一个问题上工作。这是我的解决方案:

jsFiddle.net

"use strict"

// Tweak to make a double-click select words with hyphens
// 
// As of 2016-0816, None of the major Mac browser selects whole words
// with hyphens, like "ad-lib". This tweak fixes the hypen issue.
// 
// Note: Firefox 48.0 doesn't automatically select whole words with 
// apostrophes like "doesn't". This tweak also treats that.

;(function selectWholeWordsWithHyphens(){
  var pOutput = document.getElementById("output")
  var selection = window.getSelection()
  // Regex designed to find a word+hyphen before the selected word.
  // Example: ad-|lib|
  // It finds the last chunk with no non-word characters (except for
  // ' and -) before the first selected character. 
  var startRegex = /(\w+'?-?)+-$/g
  // Regex designed to find a hyphen+word after the selected word.
  // Example: |ad|-lib
  var endRegex = /^-('?-?\w+)+/
  // Edge case: check if the selection contains no word
  // characters. If so, then don't do anything to extend it.
  var edgeRegex = /\w/

  document.body.ondblclick = selectHyphenatedWords

  function selectHyphenatedWords(event) {
    if (!selection.rangeCount) {
      return
    }
    var range = selection.getRangeAt(0)
    var container = range.startContainer
    var string = container.textContent
    var selectionUpdated = false

    if (string.substring(range.startOffset, range.endOffset)
              .search(edgeRegex) < 0) {
      // There are no word characters selected
      return
    }

    extendSelectionBackBeforeHypen(string, range.startOffset)
    extendSelectionForwardAfterHyphen(string, range.endOffset)

    if (selectionUpdated) {
      selection.removeAllRanges()
      selection.addRange(range)
    }

    function extendSelectionBackBeforeHypen(string, offset) {
      var lastIndex = 0
      var result
        , index
      string = string.substring(0, offset)

      while (result = startRegex.exec(string)) {
        index = result.index
        lastIndex = startRegex.lastIndex
      }

      if (lastIndex === offset) {
        range.setStart(container, index)
        selectionUpdated = true
      }
    }

    function extendSelectionForwardAfterHyphen(string, offset) { 
      if (!offset) {
        return
      }

      string = string.substring(offset)
      var result = endRegex.exec(string)

      if (result) {
        range.setEnd(container, offset + result[0].length)
        selectionUpdated = true
      }
    }
  }
})()

答案 1 :(得分:0)

它是所有程序的标准,因为它们都会运行操作系统的输入配置/程序。要修复它,您需要在System32中执行某些操作。我不知道你需要做什么,但我怀疑这是你的问题。你可能应该详细了解它的具体内容。