mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-08 14:45:59 +08:00
Merge pull request #3928 from aaudiber/master
Add typings for dealing with modes in codemirror
This commit is contained in:
87
codemirror/codemirror.d.ts
vendored
87
codemirror/codemirror.d.ts
vendored
@@ -919,4 +919,91 @@ declare module CodeMirror {
|
||||
*/
|
||||
current(): string;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Mode is, in the simplest case, a lexer (tokenizer) for your language — a function that takes a character stream as input,
|
||||
* advances it past a token, and returns a style for that token. More advanced modes can also handle indentation for the language.
|
||||
*/
|
||||
interface Mode<T> {
|
||||
/**
|
||||
* This function should read one token from the stream it is given as an argument, optionally update its state,
|
||||
* and return a style string, or null for tokens that do not have to be styled. Multiple styles can be returned, separated by spaces.
|
||||
*/
|
||||
token(stream: StringStream, state: T): string;
|
||||
|
||||
/**
|
||||
* A function that produces a state object to be used at the start of a document.
|
||||
*/
|
||||
startState?: () => T;
|
||||
/**
|
||||
* For languages that have significant blank lines, you can define a blankLine(state) method on your mode that will get called
|
||||
* whenever a blank line is passed over, so that it can update the parser state.
|
||||
*/
|
||||
blankLine?: (state: T) => void;
|
||||
/**
|
||||
* Given a state returns a safe copy of that state.
|
||||
*/
|
||||
copyState?: (state: T) => T;
|
||||
|
||||
/**
|
||||
* The indentation method should inspect the given state object, and optionally the textAfter string, which contains the text on
|
||||
* the line that is being indented, and return an integer, the amount of spaces to indent.
|
||||
*/
|
||||
indent?: (state: T, textAfter: string) => number;
|
||||
|
||||
/** The four below strings are used for working with the commenting addon. */
|
||||
/**
|
||||
* String that starts a line comment.
|
||||
*/
|
||||
lineComment?: string;
|
||||
/**
|
||||
* String that starts a block comment.
|
||||
*/
|
||||
blockCommentStart?: string;
|
||||
/**
|
||||
* String that ends a block comment.
|
||||
*/
|
||||
blockCommentEnd?: string;
|
||||
/**
|
||||
* String to put at the start of continued lines in a block comment.
|
||||
*/
|
||||
blockCommentLead?: string;
|
||||
|
||||
/**
|
||||
* Trigger a reindent whenever one of the characters in the string is typed.
|
||||
*/
|
||||
electricChars?: string
|
||||
/**
|
||||
* Trigger a reindent whenever the regex matches the part of the line before the cursor.
|
||||
*/
|
||||
electricinput?: RegExp
|
||||
}
|
||||
|
||||
/**
|
||||
* A function that, given a CodeMirror configuration object and an optional mode configuration object, returns a mode object.
|
||||
*/
|
||||
interface ModeFactory<T> {
|
||||
(config: CodeMirror.EditorConfiguration, modeOptions?: any): Mode<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* id will be the id for the defined mode. Typically, you should use this second argument to defineMode as your module scope function
|
||||
* (modes should not leak anything into the global scope!), i.e. write your whole mode inside this function.
|
||||
*/
|
||||
function defineMode(id: string, modefactory: ModeFactory<any>): void;
|
||||
|
||||
/**
|
||||
* The first argument is a configuration object as passed to the mode constructor function, and the second argument
|
||||
* is a mode specification as in the EditorConfiguration mode option.
|
||||
*/
|
||||
function getMode<T>(config: CodeMirror.EditorConfiguration, mode: any): Mode<T>;
|
||||
|
||||
/**
|
||||
* Utility function from the overlay.js addon that allows modes to be combined. The mode given as the base argument takes care of
|
||||
* most of the normal mode functionality, but a second (typically simple) mode is used, which can override the style of text.
|
||||
* Both modes get to parse all of the text, but when both assign a non-null style to a piece of code, the overlay wins, unless
|
||||
* the combine argument was true and not overridden, or state.overlay.combineTokens was true, in which case the styles are combined.
|
||||
*/
|
||||
function overlayMode<T, S>(base: Mode<T>, overlay: Mode<S>, combine?: boolean): Mode<any>
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user