當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript editor_utils.getWordBoundaries函數代碼示例

本文整理匯總了TypeScript中@src/lib/editor_utils.getWordBoundaries函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript getWordBoundaries函數的具體用法?TypeScript getWordBoundaries怎麽用?TypeScript getWordBoundaries使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了getWordBoundaries函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getWordBoundaries

 (text, selectionStart, selectionEnd) => {
     if (selectionStart === 0) return [null, null, null]
     let boundaries = getWordBoundaries(text, selectionStart, true)
     if (selectionStart >= boundaries[0] && selectionStart < boundaries[1])
         boundaries = getWordBoundaries(text, boundaries[0] - 1, true)
     return [null, boundaries[0], null]
 },
開發者ID:antonva,項目名稱:tridactyl,代碼行數:7,代碼來源:editor.ts

示例2: needs_text

 needs_text((text, selectionStart, selectionEnd) => {
     if (selectionStart >= text.length) {
         selectionStart = text.length - 1
     }
     // Find the word the caret is in
     let firstBoundaries = getWordBoundaries(text, selectionStart, false)
     let secondBoundaries = firstBoundaries
     // If there is a word after the word the caret is in, use it for the transselectionStartition, otherwise use the word before it
     const nextWord = wordAfterPos(text, firstBoundaries[1])
     if (nextWord > -1) {
         secondBoundaries = getWordBoundaries(text, nextWord, false)
     } else {
         firstBoundaries = getWordBoundaries(
             text,
             firstBoundaries[0] - 1,
             true,
         )
     }
     const firstWord = text.substring(firstBoundaries[0], firstBoundaries[1])
     const secondWord = text.substring(
         secondBoundaries[0],
         secondBoundaries[1],
     )
     const beginning =
         text.substring(0, firstBoundaries[0]) +
         secondWord +
         text.substring(firstBoundaries[1], secondBoundaries[0])
     selectionStart = beginning.length
     return [
         beginning + firstWord + text.substring(secondBoundaries[1]),
         selectionStart,
         null,
     ]
 }),
開發者ID:antonva,項目名稱:tridactyl,代碼行數:34,代碼來源:editor.ts

示例3: applyWord

/** @hidden
 * Applies a function to the word the caret is in, or to the next word if the caret is not in a word, or to the previous word if the current word is empty.
 */
function applyWord(
    text,
    selectionStart,
    selectionEnd,
    fn: (s: string) => string,
): [string, number, number] {
    if (text.length === 0) return [null, null, null]
    // If the caret is at the end of the text, move it just before the last character
    if (selectionStart >= text.length) {
        selectionStart = text.length - 1
    }
    const boundaries = getWordBoundaries(text, selectionStart, false)
    const beginning =
        text.substring(0, boundaries[0]) +
        fn(text.substring(boundaries[0], boundaries[1]))
    text = beginning + text.substring(boundaries[1])
    selectionStart = beginning.length + 1
    return [text, selectionStart, null]
}
開發者ID:antonva,項目名稱:tridactyl,代碼行數:22,代碼來源:editor.ts


注:本文中的@src/lib/editor_utils.getWordBoundaries函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。