src/edit/base_commands.js
// Get an offset moving backward from a current offset inside a node.
Get an offset moving backward from a current offset inside a node.
Get an offset moving backward from a current offset inside a node .
function moveBackward(parent, offset, by) {
  if (by != "char" && by != "word")
    AssertionError.raise("Unknown motion unit: " + by)
  let cat = null, counted = 0
  for (;;) {
    if (offset == 0) return offset
    let {start, node} = parent.chunkBefore(offset)
    if (!node.isText) return cat ? offset : offset - 1
    if (by == "char") {
      for (let i = offset - start; i > 0; i--) {
        if (!isExtendingChar(node.text.charAt(i - 1)))
          return offset - 1
        offset--
      }
    } else if (by == "word") {
      for (let i = offset - start; i > 0; i--) {
        let nextCharCat = charCategory(node.text.charAt(i - 1))
        if (cat == null || counted == 1 && cat == "space") cat = nextCharCat
        else if (cat != nextCharCat) return offset
        offset--
        counted++
      }
    }
  }
}
function moveBackward ( parent , offset , by ) { if ( by != "char" && by != "word" ) AssertionError . raise ( "Unknown motion unit: " + by ) let cat = null , counted = 0 for ( ; ; ) { if ( offset == 0 ) return offset let { start , node } = parent . chunkBefore ( offset ) if ( ! node . isText ) return cat ? offset : offset - 1 if ( by == "char" ) { for ( let i = offset - start ; i > 0 ; i -- ) { if ( ! isExtendingChar ( node . text . charAt ( i - 1 ) ) ) return offset - 1 offset -- } } else if ( by == "word" ) { for ( let i = offset - start ; i > 0 ; i -- ) { let nextCharCat = charCategory ( node . text . charAt ( i - 1 ) ) if ( cat == null || counted == 1 && cat == "space" ) cat = nextCharCat else if ( cat != nextCharCat ) return offset offset -- counted ++ } } } }
Get an offset moving backward from a current offset inside a node.
Get an offset moving backward from a current offset inside a node .
// Work from the current position backwards through text of a singular // character category (e.g. "cat" of "#!*") until reaching a character in a // different category (i.e. the end of the word).