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


TypeScript codemirror.defineOption函数代码示例

本文整理汇总了TypeScript中codemirror.defineOption函数的典型用法代码示例。如果您正苦于以下问题:TypeScript defineOption函数的具体用法?TypeScript defineOption怎么用?TypeScript defineOption使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: showTooltip


//.........这里部分代码省略.........
    if (options instanceof Function)
      return {
        getTextHover : options
      };
    if (!options || options === true)
      options = {};
    if (!options.getTextHover)
      options.getTextHover = cm.getHelper(CodeMirror.Pos(0, 0), "textHover");
    if (!options.getTextHover)
      throw new Error("Required option 'getTextHover' missing (text-hover addon)");
    return options;
  }

  function onMouseOverWithDelay(cm, e) {
    var state = cm.state.textHover, delay = state.options.delay;
    clearTimeout(state.timeout);
    if (e.srcElement) {
    	// hack for IE, because e.srcElement failed when it is used in the tiemout function
    	var newE = {srcElement: e.srcElement, clientX : e.clientX, clientY: e.clientY};
    	e = newE;
    }
    state.timeout = setTimeout(function() {onMouseOver(cm, e);}, delay);
  }

  function onMouseOver(cm, e) {
    var node = e.target || e.srcElement;
    if (node) {
      var state = cm.state.textHover, data = getTokenAndPosAt(cm, e);
      var result = Promise.resolve(state.options.getTextHover(cm, data, e));

      // Add to queue
      PromiseQueue.push(result);

      // BAS hide any previous
      if (hidePreviousToolTip) {
          hidePreviousToolTip();
          hidePreviousToolTip = null;
      }

      result.then((content) => {
          // If not the last in the queue ... the results don't matter
          if (PromiseQueue[PromiseQueue.length - 1] !== result){
              PromiseQueue = PromiseQueue.filter(p => p != result);
              return;
          }
          PromiseQueue = PromiseQueue.filter(p => p != result);

          if (content) {
              node.className += HOVER_CLASS;
              if (typeof content == 'function') {
                  content(showTooltipFor, data, e, node, state, cm);
              }
              else {
                  showTooltipFor(e, content, node, state, cm);
              }
          }
      });
    }
  }

  function optionHandler(cm, val, old) {
    if (old && old != CodeMirror.Init) {
      CodeMirror.off(cm.getWrapperElement(), "mouseover",
          cm.state.textHover.onMouseOver);
      delete cm.state.textHover;
    }

    if (val) {
      var state = cm.state.textHover = new TextHoverState(cm, parseOptions(cm,
          val));
      CodeMirror.on(cm.getWrapperElement(), "mouseover", state.onMouseOver);
    }
  }

  // When the mouseover fires, the cursor might not actually be over
  // the character itself yet. These pairs of x,y offsets are used to
  // probe a few nearby points when no suitable marked range is found.
  var nearby = [ 0, 0, 0, 5, 0, -5, 5, 0, -5, 0 ];

  function getTokenAndPosAt(cm, e) {
    var node = e.target || e.srcElement, text = node.innerText
        || node.textContent;
    for ( var i = 0; i < nearby.length; i += 2) {
      var pos = cm.coordsChar({
        left : e.clientX + nearby[i],
        top : e.clientY + nearby[i + 1]
      });
      var token = cm.getTokenAt(pos);
      if (token && token.string === text) {
        return {
          token : token,
          pos : pos
        };
      }
    }
  }

  CodeMirror.defineOption("textHover", false, optionHandler); // deprecated

})();
开发者ID:JeyKeu,项目名称:alm,代码行数:101,代码来源:text-hover.ts

示例2: innerMode

declare module "codemirror" {
  function innerMode(mode: any, state: any): any;
}

CodeMirror.defineOption("leanSymbols", false, function(cm, val, old) {
  if (old) {
    cm.removeKeyMap("leanSymbols");
    cm.off("mousedown", lean_symbols);
    cm.off("blur", lean_symbols);
  }
  if (!val) {
    return;
  }
  const map = {
    name: "leanSymbols",
    Enter: lean_symbols,
    Space: lean_symbols,
    Tab: lean_symbols,
    Right: lean_symbols,
    Up: lean_symbols,
    Down: lean_symbols,
    "\\": lean_symbols
  };
  cm.on("mousedown", lean_symbols);
  cm.on("blur", lean_symbols);
  cm.addKeyMap(map);
});

/*
interface Position {
  line: number;
开发者ID:DrXyzzy,项目名称:smc,代码行数:31,代码来源:codemirror-lean-symbols.ts

示例3: innerMode

// This is how to add a new missing declaration via "augmentation":
//   https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
declare module "codemirror" {
  function innerMode(mode: any, state: any): any;
}

import { splitlines } from "smc-util/misc2";

CodeMirror.defineOption("autoCloseLatex", false, function(cm, val, old) {
  if (old) {
    cm.removeKeyMap("autoCloseLatex");
  }
  if (!val) {
    return;
  }
  const map = {
    name: "autoCloseLatex",
    Enter: function(cm) {
      return auto_close_latex(cm);
    }
  };
  cm.addKeyMap(map);
});

interface Position {
  line: number;
  ch: number;
}

interface Selection {
  head: Position;
开发者ID:DrXyzzy,项目名称:smc,代码行数:31,代码来源:codemirror-autoclose-latex.ts

示例4: require

} from 'src/shared/constants/codeMirrorModes'
import 'codemirror/addon/hint/show-hint'

/* tslint:disable */

const CodeMirror = require('codemirror')

CodeMirror.defineOption('placeholder', '', function(cm, val, old) {
  var prev = old && old != CodeMirror.Init
  if (val && !prev) {
    cm.on('blur', onBlur)
    cm.on('change', onChange)
    cm.on('swapDoc', onChange)
    onChange(cm)
  } else if (!val && prev) {
    cm.off('blur', onBlur)
    cm.off('change', onChange)
    cm.off('swapDoc', onChange)
    clearPlaceholder(cm)
    var wrapper = cm.getWrapperElement()
    wrapper.className = wrapper.className.replace(' CodeMirror-empty', '')
  }

  if (val && !cm.hasFocus()) onBlur(cm)
})

CodeMirror.defineSimpleMode = function(name, states) {
  CodeMirror.defineMode(name, function(config) {
    return CodeMirror.simpleMode(config, states)
  })
}
开发者ID:influxdata,项目名称:influxdb,代码行数:31,代码来源:codemirror.ts

示例5: function

 * START COPY PASTE
 */

var defaults = {
  pairs: "()[]{}''\"\"",
  triples: "",
  explode: "[]{}"
};

var Pos = CodeMirror.Pos;

CodeMirror.defineOption("autoCloseBrackets", false, function(cm, val, old) {
  if (old && old != (CodeMirror as any).Init) {
    cm.removeKeyMap(keyMap);
    cm.state.closeBrackets = null;
  }
  if (val) {
    cm.state.closeBrackets = val;
    cm.addKeyMap(keyMap);
  }
});

function getOption(conf, name) {
  if (name == "pairs" && typeof conf == "string") return conf;
  if (typeof conf == "object" && conf[name] != null) return conf[name];
  return defaults[name];
}

var bind = defaults.pairs + "`";
var keyMap = {Backspace: handleBackspace, Enter: handleEnter};
for (var i = 0; i < bind.length; i++)
  keyMap["'" + bind.charAt(i) + "'"] = handler(bind.charAt(i));
开发者ID:JeyKeu,项目名称:alm,代码行数:32,代码来源:insertMatchingPair.ts

示例6: require

} from 'src/shared/constants/codeMirrorModes'
import 'codemirror/addon/hint/show-hint'

/* tslint:disable */

const CodeMirror = require('codemirror')

CodeMirror.defineOption("placeholder", "", function (cm, val, old) {
  var prev = old && old != CodeMirror.Init;
  if (val && !prev) {
    cm.on("blur", onBlur);
    cm.on("change", onChange);
    cm.on("swapDoc", onChange);
    onChange(cm);
  } else if (!val && prev) {
    cm.off("blur", onBlur);
    cm.off("change", onChange);
    cm.off("swapDoc", onChange);
    clearPlaceholder(cm);
    var wrapper = cm.getWrapperElement();
    wrapper.className = wrapper.className.replace(" CodeMirror-empty", "");
  }

  if (val && !cm.hasFocus()) onBlur(cm);
});

CodeMirror.defineSimpleMode = function(name, states) {
  CodeMirror.defineMode(name, function(config) {
    return CodeMirror.simpleMode(config, states)
  })
}
开发者ID:viccom,项目名称:influxdb,代码行数:31,代码来源:codemirror.ts


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