实例方法

findMatches() 查找文本

  1. /**
  2. * Search the model.
  3. * @param searchString The string used to search. If it is a regular expression, set `isRegex` to true.
  4. * @param searchOnlyEditableRange Limit the searching to only search inside the editable range of the model.
  5. * @param isRegex Used to indicate that `searchString` is a regular expression.
  6. * @param matchCase Force the matching to match lower/upper case exactly.
  7. * @param wordSeparators Force the matching to match entire words only. Pass null otherwise.
  8. * @param captureMatches The result will contain the captured groups.
  9. * @param limitResultCount Limit the number of results
  10. * @return The ranges where the matches are. It is empty if not matches have been found.
  11. */
  12. findMatches(searchString: string, searchOnlyEditableRange: boolean, isRegex: boolean, matchCase: boolean, wordSeparators: string | null, captureMatches: boolean, limitResultCount?: number): FindMatch[];

功能和 “⌘ + F” 一致,通过字符串或正则表达式查找编辑器内匹配的文本,并返回匹配文本 range 的集合。

getOptions

setValue

  1. setValue(newValue: string | ITextSnapshot): void;

getValue

  1. /**
  2. * Get the text stored in this model.
  3. * @param eol The end of line character preference. Defaults to `EndOfLinePreference.TextDefined`.
  4. * @param preserverBOM Preserve a BOM character if it was detected when the model was constructed.
  5. * @return The text.
  6. */
  7. getValue(eol?: EndOfLinePreference, preserveBOM?: boolean): string;

getValueInRange(range)

通过 range 获取范围内的文本,返回一个字符串。
image.png

  1. monacoCompletionProvide = monaco.languages.registerCompletionItemProvider('lua', {
  2. provideCompletionItems: function (model, position) {
  3. let textUntilPosition = model.getValueInRange({
  4. startLineNumber: position.lineNumber,
  5. startColumn: 1,
  6. endLineNumber: position.lineNumber,
  7. endColumn: position.column
  8. })
  9. let suggestions = createCompleters(textUntilPosition)
  10. console.log("🚀 ~ file: Index.vue ~ line 84 ~ init ~ suggestions", suggestions)
  11. return {
  12. suggestions: suggestions
  13. }
  14. }
  15. })

getLineContent(lineNumber) 获取指定行的文本字符串

  1. /**
  2. * Get the text for a certain line.
  3. */
  4. getLineContent(lineNumber: number): string;

getLinesContent() 获取所有行的文本字符串的集合

返回所有行的文本字符串的集合。

  1. /**
  2. * Get the text for all lines.
  3. */
  4. getLinesContent(): string[];

getValueLength 获取文本长度

  1. /**
  2. * Get the length of the text stored in this model.
  3. */
  4. getValueLength(eol?: EndOfLinePreference, preserveBOM?: boolean): number;

包含 \n, \t 等符号

getLineLength 获取指定行的文本长度

  1. /**
  2. * Get the text length for a certain line.
  3. */
  4. getLineLength(lineNumber: number): number;

getValueLengthInRange 获取指定范围的文本长度


getCharacterCountInRange

getWordUntilPosition

获取在指定行列位置的字符

  1. getWordUntilPosition(position: IPosition): IWordAtPosition;
  2. export interface IPosition {
  3. /**
  4. * line number (starts at 1)
  5. */
  6. readonly lineNumber: number;
  7. /**
  8. * column (the first character in a line is between column 1 and column 2)
  9. */
  10. readonly column: number;
  11. }
  12. /**
  13. * Word inside a model.
  14. */
  15. export interface IWordAtPosition {
  16. /**
  17. * The word.
  18. */
  19. readonly word: string;
  20. /**
  21. * The column where the word starts.
  22. */
  23. readonly startColumn: number;
  24. /**
  25. * The column where the word ends.
  26. */
  27. readonly endColumn: number;
  28. }

getLineCount() 获取行数

  1. /**
  2. * Get the number of lines in the model.
  3. */
  4. getLineCount(): number;

getEOL

  1. /**
  2. * Get the end of line sequence predominantly used in the text buffer.
  3. * @return EOL char sequence (e.g.: '\n' or '\r\n').
  4. */
  5. getEOL(): string;

getEndOfLineSequence() 获取行尾序列

  1. /**
  2. * Get the end of line sequence predominantly used in the text buffer.
  3. */
  4. getEndOfLineSequence(): EndOfLineSequence;

image.png