当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Editor.updateContents方法代码示例

本文整理汇总了TypeScript中@typewriter/editor.Editor.updateContents方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Editor.updateContents方法的具体用法?TypeScript Editor.updateContents怎么用?TypeScript Editor.updateContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在@typewriter/editor.Editor的用法示例。


在下文中一共展示了Editor.updateContents方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: onMutate

    // Final fallback. Handles composition text etc. Detects text changes from e.g. spell-check or Opt+E to produce ´
    function onMutate(list: MutationRecord[]) {
      // Optimize for text changes (typing text)
      const textChange = getTextChange(list);
      const selection = getSelection(root, paper);

      if (textChange) {
        undoMutation(list, !options.forceTextUpdates);
        editor.updateContents(textChange, SOURCE_USER, selection);
      } else {
        // Handle everything else, pasted content, cut, spellcheck replacements
        const delta = deltaFromDom(root, paper);
        const change = editor.contents.diff(delta);
        undoMutation(list);
        editor.updateContents(change, SOURCE_USER, selection);
      }
    }
开发者ID:jacwright,项目名称:typewriter,代码行数:17,代码来源:input.ts

示例2: getAttributes

 return blockReplacements.some(([ regexp, getAttributes ]) => {
   const match = prefix.match(regexp);
   if (match) {
     const attributes = getAttributes(match[1]);
     const change = editor.getChange(() => {
       editor.formatLine(index, attributes);
       editor.deleteText(index - prefix.length, index);
     });
     editor.updateContents(change, SOURCE_USER, index - prefix.length);
     return true;
   }
 });
开发者ID:jacwright,项目名称:typewriter,代码行数:12,代码来源:smart-entry.ts

示例3: action

 function action(event: Event, source: string, dest: string) {
   if (event.defaultPrevented) return;
   event.preventDefault();
   if (stack[source].length === 0) return;
   const entry = stack[source].pop();
   stack[dest].push(entry);
   cutoff();
   ignoreChange = true;
   if (typeof entry[source] === 'function') {
     entry[source]();
   } else {
     editor.updateContents(entry[source], SOURCE_USER, entry[source + 'Selection']);
   }
   ignoreChange = false;
 }
开发者ID:jacwright,项目名称:typewriter,代码行数:15,代码来源:history.ts

示例4: onTextChange

    function onTextChange({ change, source, selection }) {
      if (source !== 'user' || !editor.selection || !isTextEntry(change)) return;

      const index = editor.selection[1];
      const lastOp = change.ops[change.ops.length - 1];
      const lastChars = editor.getText(index - 1, index) + lastOp.insert.slice(-1);

      const replaced = lastChars.replace(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/, '“')
              .replace(/"$/, '”')
              .replace(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/, '‘')
              .replace(/'$/, '’');

      if (replaced !== lastChars) {
        const quote = replaced.slice(-1);
        lastOp.insert = lastOp.insert.slice(0, -1) + quote;
        editor.updateContents(change, source, selection);
        return false;
      }
    }
开发者ID:jacwright,项目名称:typewriter,代码行数:19,代码来源:smart-quotes.ts


注:本文中的@typewriter/editor.Editor.updateContents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。