Vùng văn bản v-html

                public static function renderSelectOptions($selection, $items, &$tagOptions = [])
{
    if (ArrayHelper::isTraversable($selection)) {
        $normalizedSelection = [];
        foreach (ArrayHelper::toArray($selection) as $selectionItem) {
            if (is_bool($selectionItem)) {
                $normalizedSelection[] = $selectionItem ? '1' : '0';
            } else {
                $normalizedSelection[] = (string)$selectionItem;
            }
        }
        $selection = $normalizedSelection;
    } elseif (is_bool($selection)) {
        $selection = $selection ? '1' : '0';
    }
    $lines = [];
    $encodeSpaces = ArrayHelper::remove($tagOptions, 'encodeSpaces', false);
    $encode = ArrayHelper::remove($tagOptions, 'encode', true);
    $strict = ArrayHelper::remove($tagOptions, 'strict', false);
    if (isset($tagOptions['prompt'])) {
        $promptOptions = ['value' => ''];
        if (is_string($tagOptions['prompt'])) {
            $promptText = $tagOptions['prompt'];
        } else {
            $promptText = $tagOptions['prompt']['text'];
            $promptOptions = array_merge($promptOptions, $tagOptions['prompt']['options']);
        }
        $promptText = $encode ? static::encode($promptText) : $promptText;
        if ($encodeSpaces) {
            $promptText = str_replace(' ', ' ', $promptText);
        }
        $lines[] = static::tag('option', $promptText, $promptOptions);
    }
    $options = isset($tagOptions['options']) ? $tagOptions['options'] : [];
    $groups = isset($tagOptions['groups']) ? $tagOptions['groups'] : [];
    unset($tagOptions['prompt'], $tagOptions['options'], $tagOptions['groups']);
    $options['encodeSpaces'] = ArrayHelper::getValue($options, 'encodeSpaces', $encodeSpaces);
    $options['encode'] = ArrayHelper::getValue($options, 'encode', $encode);
    foreach ($items as $key => $value) {
        if (is_array($value)) {
            $groupAttrs = isset($groups[$key]) ? $groups[$key] : [];
            if (!isset($groupAttrs['label'])) {
                $groupAttrs['label'] = $key;
            }
            $attrs = ['options' => $options, 'groups' => $groups, 'encodeSpaces' => $encodeSpaces, 'encode' => $encode, 'strict' => $strict];
            $content = static::renderSelectOptions($selection, $value, $attrs);
            $lines[] = static::tag('optgroup', "\n" . $content . "\n", $groupAttrs);
        } else {
            $attrs = isset($options[$key]) ? $options[$key] : [];
            $attrs['value'] = (string) $key;
            if (!array_key_exists('selected', $attrs)) {
                $selected = false;
                if ($selection !== null) {
                    if (ArrayHelper::isTraversable($selection)) {
                        $selected = ArrayHelper::isIn((string)$key, $selection, $strict);
                    } elseif ($key === '' || $selection === '') {
                        $selected = $selection === $key;
                    } elseif ($strict) {
                        $selected = !strcmp((string)$key, (string)$selection);
                    } else {
                        $selected = $selection == $key;
                    }
                }
                $attrs['selected'] = $selected;
            }
            $text = $encode ? static::encode($value) : $value;
            if ($encodeSpaces) {
                $text = str_replace(' ', ' ', $text);
            }
            $lines[] = static::tag('option', $text, $attrs);
        }
    }
    return implode("\n", $lines);
}

            

CodeMirror is a code-editor component that can be embedded in Web pages. The core library provides only the editor component, no accompanying buttons, auto-completion, or other IDE functionality. It does provide a rich API on top of which such functionality can be straightforwardly implemented. See the included in the distribution, and 3rd party packages on npm, for reusable implementations of extra features

CodeMirror works with language-specific modes. Modes are JavaScript programs that help color (and optionally indent) text written in a given language. The distribution comes with a number of modes (see the mode/ directory), and it isn't hard to for other languages

Basic Usage

The easiest way to use CodeMirror is to simply load the script and style sheet found under lib/ in the distribution, plus a mode script from one of the mode/ directories. For example



(Alternatively, use a module loader. )

Having done this, an editor instance can be created like this

var myCodeMirror = CodeMirror(document.body);

The editor will be appended to the document body, will start empty, and will use the mode that we loaded. To have more control over the new editor, a configuration object can be passed to as a second argument

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});

This will initialize the editor with a piece of code already in it, and explicitly tell it to use the JavaScript mode (which is useful when multiple modes are loaded). See for a full discussion of the configuration options that CodeMirror accepts

Trong trường hợp bạn không muốn nối thêm trình chỉnh sửa vào một phần tử và cần kiểm soát nhiều hơn đối với cách nó được chèn vào, thì đối số đầu tiên của hàm

var myCodeMirror = CodeMirror(document.body);
1 cũng có thể là một hàm mà khi được cung cấp một phần tử DOM, sẽ chèn nó vào . Ví dụ, điều này có thể được sử dụng để thay thế một vùng văn bản bằng một trình soạn thảo thực

var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});

Tuy nhiên, đối với trường hợp sử dụng này, đây là cách phổ biến để sử dụng CodeMirror, thư viện cung cấp một lối tắt mạnh mẽ hơn nhiều

var myCodeMirror = CodeMirror.fromTextArea(myTextArea);

Điều này sẽ, trong số những thứ khác, đảm bảo rằng giá trị của vùng văn bản được cập nhật với nội dung của trình soạn thảo khi biểu mẫu (nếu nó là một phần của biểu mẫu) được gửi. Xem mô tả đầy đủ về phương pháp này

bộ nạp mô-đun

Các tệp trong bản phân phối CodeMirror chứa các miếng chêm để tải chúng (và các phần phụ thuộc của chúng) trong môi trường AMD hoặc CommonJS. Nếu các biến

var myCodeMirror = CodeMirror(document.body);
3 và
var myCodeMirror = CodeMirror(document.body);
4 tồn tại và có kiểu đối tượng, yêu cầu kiểu CommonJS sẽ được sử dụng. Nếu không, nhưng có một hàm
var myCodeMirror = CodeMirror(document.body);
5 với thuộc tính
var myCodeMirror = CodeMirror(document.body);
6, kiểu AND (RequireJS) sẽ được sử dụng

Có thể sử dụng Browserify hoặc các công cụ tương tự để tạo mô-đun tĩnh bằng CodeMirror. Ngoài ra, hãy sử dụng RequireJS để tải động các phụ thuộc khi chạy. Cả hai cách tiếp cận này đều có lợi thế là chúng không sử dụng không gian tên chung và do đó, có thể thực hiện những việc như tải nhiều phiên bản CodeMirror cùng với nhau

Đây là một ví dụ đơn giản về việc sử dụng RequireJS để tải CodeMirror

require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});

Nó sẽ tự động tải các chế độ mà chế độ HTML hỗn hợp phụ thuộc vào (XML, JavaScript và CSS). Không sử dụng tùy chọn

var myCodeMirror = CodeMirror(document.body);
7 của RequireJS để định cấu hình đường dẫn đến CodeMirror, vì tùy chọn này sẽ ngắt tải các mô-đun con thông qua các đường dẫn tương đối. Thay vào đó, hãy sử dụng tùy chọn cấu hình, như trong

require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});

Cấu hình

Both the function and its

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
0 method take as second (optional) argument an object containing configuration options. Any option not supplied like this will be taken from , an object containing the default options. You can update this object to change the defaults on your page

Options are not checked in any way, so setting bogus option values is bound to lead to odd errors

Đây là các tùy chọn được hỗ trợ

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
2The starting value of the editor. Can be a string, or a .
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
3The mode to use. When not given, this will default to the first mode that was loaded. It may be a string, which either simply names the mode or is a MIME type associated with the mode. The value
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
4 indicates no highlighting should be applied. Alternatively, it may be an object containing configuration options for the mode, with a
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
5 property that names the mode (for example
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
6). The demo pages for each mode contain information about what configuration parameters the mode supports. You can ask CodeMirror which modes and MIME types have been defined by inspecting the
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
7 and
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
8 objects. The first maps mode names to their constructors, and the second maps MIME types to mode specs.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
9Explicitly set the line separator for the editor. By default (value
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0), the document will be split on CRLFs as well as lone CRs and LFs, and a single LF will be used as line separator in all output (such as ). When a specific string is given, lines will only be split on that string, and output will, by default, use that same separator.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
2The theme to style the editor with. You must make sure the CSS file defining the corresponding
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
3 styles is loaded (see the
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
4 directory in the distribution). The default is
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
5, for which colors are included in
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
6. It is possible to use multiple theming classes at once—for example
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
7 will assign both the
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
8 and the
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
9 classes to the editor.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
0How many spaces a block (whatever that means in the edited language) should be indented. The default is 2.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
1Whether to use the context-sensitive indentation that the mode provides (or just indent the same as the line before). Defaults to true.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
2The width of a tab character. Defaults to 4.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
3Whether, when indenting, the first N*
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
4 spaces should be replaced by N tabs. Default is false.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
5Configures whether the editor should re-indent the current line when a character is typed that might change its proper indentation (only works if the mode supports indentation). Default is true.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
6A regular expression used to determine which characters should be replaced by a special . Mostly useful for non-printing special characters. The default is
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
7.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
8A function that, given a special character identified by the option, produces a DOM node that is used to represent the character. By default, a red dot ( ) is shown, with a title tooltip to indicate the character code.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
0Flips overall layout and selects base paragraph direction to be left-to-right or right-to-left. Default is "ltr". CodeMirror applies the Unicode Bidirectional Algorithm to each line, but does not autodetect base direction — it's set to the editor direction for all lines. The resulting order is sometimes wrong when base direction doesn't match user intent (for example, leading and trailing punctuation jumps to the wrong side of the line). Therefore, it's helpful for multilingual input to let users toggle this option.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
1Determines whether horizontal cursor movement through right-to-left (Arabic, Hebrew) text is visual (pressing the left arrow moves the cursor left) or logical (pressing the left arrow moves to the next lower index in the string, which is visually right in right-to-left text). The default is
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
2 on Windows, and
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
3 on other platforms.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
4Configures the key map to use. The default is
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
5, which is the only key map defined in
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
6 itself. Extra key maps are found in the
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
7 directory. See the for more information.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
8Can be used to specify extra key bindings for the editor, alongside the ones defined by . Should be either null, or a valid value.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
0Allows you to configure the behavior of mouse selection and dragging. The function is called when the left mouse button is pressed. The returned object may have the following properties.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
1The unit by which to select. May be one of the built-in units or a function that takes a position and returns a range around that, for a custom unit. The default is to return
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
2 for double clicks,
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
3 for triple clicks,
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
4 for alt-clicks (or, on Chrome OS, meta-shift-clicks), and
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
5 otherwise.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
6Có nên mở rộng phạm vi lựa chọn hiện tại hay bắt đầu một phạm vi lựa chọn mới. Theo mặc định, tính năng này được bật khi nhấn shift.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
7Khi được bật, điều này sẽ thêm một phạm vi mới vào lựa chọn hiện tại, thay vì thay thế nó. Hành vi mặc định là kích hoạt tính năng này để nhấp lệnh trên Mac OS và nhấp điều khiển trên các nền tảng khác.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
8Khi chuột thậm chí kéo nội dung xung quanh bên trong trình chỉnh sửa, thao tác này sẽ kiểm soát xem nội dung được sao chép (sai) hay di chuyển (đúng). Theo mặc định, tính năng này được bật bằng cách nhấp vào alt trên Mac OS và nhấp vào ctrl ở nơi khác.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
9Liệu CodeMirror có nên cuộn hoặc ngắt dòng dài không. Mặc định là
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
2 (cuộn).
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
1Có hiển thị số dòng ở bên trái của trình chỉnh sửa không.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
2 Bắt đầu đếm dòng từ số nào. Mặc định là 1.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
3Một hàm dùng để định dạng số dòng. Hàm được truyền số dòng và sẽ trả về một chuỗi sẽ được hiển thị trong máng xối. _______ 61 _______ 4 Có thể được sử dụng để thêm máng phụ (ngoài hoặc thay cho máng số dòng). Phải là một mảng tên lớp CSS hoặc cặp tên lớp/chuỗi CSS, mỗi cặp xác định một
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
5 (và nền tùy chọn) và sẽ được sử dụng để vẽ nền của máng xối. Có thể bao gồm lớp
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
6, để thiết lập rõ ràng vị trí của máng xối số dòng (nó sẽ mặc định ở bên phải của tất cả các máng xối khác). Các tên lớp này là các khóa được truyền cho.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
8Xác định xem rãnh cuộn cùng với nội dung theo chiều ngang (sai) hay liệu nó có cố định trong khi cuộn ngang (đúng, mặc định).
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
9Chọn triển khai thanh cuộn. Giá trị mặc định là mode/0, hiển thị thanh cuộn gốc. Thư viện cốt lõi cũng cung cấp kiểu
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
4, kiểu này ẩn hoàn toàn các thanh cuộn. có thể thực hiện các mô hình thanh cuộn bổ sung. mode/2Khi được bật và có một thanh cuộn ngang, theo mặc định, rãnh sẽ hiển thị ở bên trái của thanh cuộn này. Nếu tùy chọn này được đặt thành true, nó sẽ được bao phủ bởi một phần tử có lớp mode/4. mode/5Chọn cách CodeMirror xử lý đầu vào và tiêu điểm. Thư viện cốt lõi xác định các mô hình đầu vào mode/6 và mode/7. Trên trình duyệt di động, mặc định là mode/7. Trên trình duyệt máy tính để bàn, mặc định là mode/6. Hỗ trợ cho IME và trình đọc màn hình tốt hơn trong kiểu máy mode/7. Mục đích là biến nó thành mặc định trên các trình duyệt máy tính để bàn hiện đại trong tương lai. lib/1This disables editing of the editor content by the user. Nếu giá trị đặc biệt lib/2 được cung cấp (thay vì chỉ đơn giản là
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
3), tiêu điểm của trình chỉnh sửa cũng không được phép. lib/4Nhãn này được trình đọc màn hình đọc khi vùng văn bản CodeMirror được đặt tiêu điểm. Điều này hữu ích cho khả năng tiếp cận. lib/5Có nên vẽ con trỏ khi lựa chọn đang hoạt động hay không. Mặc định là sai. lib/6Khi được bật, đây là mặc định, thực hiện sao chép hoặc cắt khi không có lựa chọn nào sẽ sao chép hoặc cắt toàn bộ dòng có con trỏ trên đó. lib/7Khi dán nội dung nào đó từ nguồn bên ngoài (không phải từ chính trình chỉnh sửa), nếu số dòng khớp với số lượng lựa chọn, CodeMirror theo mặc định sẽ chèn một dòng cho mỗi lựa chọn. Bạn có thể đặt giá trị này thành
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
2 để tắt hành vi đó. lib/9Xác định xem nhiều lựa chọn có được nối ngay khi chúng chạm vào nhau (mặc định) hay chỉ khi chúng trùng nhau (đúng).
var myCodeMirror = CodeMirror(document.body);
00Số mức hoàn tác tối đa mà trình chỉnh sửa lưu trữ. Lưu ý rằng điều này bao gồm các sự kiện thay đổi lựa chọn. Mặc định là 200.
var myCodeMirror = CodeMirror(document.body);
01Khoảng thời gian không hoạt động (tính bằng mili giây) sẽ khiến một sự kiện lịch sử mới được bắt đầu khi nhập hoặc xóa. Mặc định là 1250.
var myCodeMirror = CodeMirror(document.body);
02Việc giao cho biên tập viên. Nếu không được cung cấp, sẽ không có chỉ mục tab nào được chỉ định.
var myCodeMirror = CodeMirror(document.body);
03Có thể được sử dụng để khiến CodeMirror tự tập trung vào quá trình khởi tạo. Mặc định tắt. Khi được sử dụng và không có giá trị rõ ràng nào được cung cấp cho tùy chọn này, nó sẽ được đặt thành true khi vùng văn bản nguồn được đặt tiêu điểm hoặc nó có thuộc tính
var myCodeMirror = CodeMirror(document.body);
05 và không có phần tử nào khác được đặt tiêu điểm.
var myCodeMirror = CodeMirror(document.body);
06Một số addon chạy các chuỗi mà người dùng có thể nhìn thấy (chẳng hạn như nhãn trong giao diện) thông qua phương thức để cho phép dịch. Tùy chọn này xác định giá trị trả về của phương thức đó. Khi nó là null hoặc một đối tượng không có thuộc tính được đặt tên theo chuỗi đầu vào, thì chuỗi đó được trả về. Nếu không, giá trị của thuộc tính tương ứng với chuỗi đó được trả về.

Dưới đây liệt kê một số tùy chọn cấp thấp, chuyên biệt hơn. Chúng chỉ hữu ích trong những tình huống rất cụ thể, bạn có thể muốn bỏ qua chúng khi đọc hướng dẫn này lần đầu tiên

var myCodeMirror = CodeMirror(document.body);
08Kiểm soát xem tính năng kéo và thả có được bật hay không. Bật theo mặc định.
var myCodeMirror = CodeMirror(document.body);
09Khi được đặt (mặc định là
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0) chỉ các tệp có loại trong mảng mới có thể được đưa vào trình chỉnh sửa. Các chuỗi phải là loại MIME và sẽ được kiểm tra đối với đối tượng
var myCodeMirror = CodeMirror(document.body);
12 như được báo cáo bởi trình duyệt.
var myCodeMirror = CodeMirror(document.body);
13Nửa chu kỳ tính bằng mili giây được sử dụng để nhấp nháy con trỏ. Tốc độ chớp mắt mặc định là 530ms. Bằng cách đặt giá trị này thành 0, nhấp nháy có thể bị tắt. Một giá trị âm ẩn hoàn toàn con trỏ.
var myCodeMirror = CodeMirror(document.body);
14Bao nhiêu không gian thừa để luôn giữ bên trên và bên dưới con trỏ khi tiếp cận đầu hoặc cuối chế độ xem hiển thị trong tài liệu có thể cuộn. Mặc định là 0.
var myCodeMirror = CodeMirror(document.body);
15Xác định chiều cao của con trỏ. Mặc định là 1, nghĩa là nó kéo dài toàn bộ chiều cao của dòng. Đối với một số phông chữ (và theo một số sở thích), chiều cao nhỏ hơn (ví dụ:
var myCodeMirror = CodeMirror(document.body);
16), điều này khiến con trỏ không chạm đến hết dòng, trông đẹp hơn
var myCodeMirror = CodeMirror(document.body);
17Nếu được đặt thành
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
3 (mặc định), sẽ giữ nguyên chiều cao của con trỏ . Khi
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
2, chiều cao của con trỏ dựa trên chiều cao của ký tự tham chiếu liền kề.
var myCodeMirror = CodeMirror(document.body);
20Kiểm soát xem khi menu ngữ cảnh được mở bằng một cú nhấp chuột bên ngoài lựa chọn hiện tại, con trỏ có được di chuyển đến điểm nhấp chuột hay không. Mặc định là
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
3.
var myCodeMirror = CodeMirror(document.body);
22Làm nổi bật được thực hiện bởi một luồng nền giả sẽ hoạt động trong khoảng thời gian
var myCodeMirror = CodeMirror(document.body);
23 mili giây, sau đó sử dụng thời gian chờ để ngủ trong khoảng thời gian
var myCodeMirror = CodeMirror(document.body);
24 mili giây. Giá trị mặc định là 200 và 300, bạn có thể thay đổi các tùy chọn này để làm nổi bật nhiều hơn hoặc ít hơn.
var myCodeMirror = CodeMirror(document.body);
25Cho biết tốc độ CodeMirror sẽ thăm dò vùng văn bản đầu vào của nó để tìm các thay đổi (khi được tập trung). Hầu hết đầu vào được ghi lại bởi các sự kiện, nhưng một số thứ, chẳng hạn như đầu vào IME trên một số trình duyệt, không tạo ra các sự kiện cho phép CodeMirror phát hiện đúng cách. Vì vậy, nó thăm dò ý kiến. Mặc định là 100 mili giây.
var myCodeMirror = CodeMirror(document.body);
26Theo mặc định, CodeMirror sẽ kết hợp các mã thông báo liền kề thành một khoảng duy nhất nếu chúng có cùng lớp. Điều này sẽ dẫn đến một cây DOM đơn giản hơn và do đó hoạt động tốt hơn. Với một số kiểu tạo kiểu (chẳng hạn như góc bo tròn), thao tác này sẽ thay đổi giao diện của tài liệu. Bạn có thể đặt tùy chọn này thành false để tắt hành vi này.
var myCodeMirror = CodeMirror(document.body);
27Khi được bật (tắt theo mặc định), một lớp CSS bổ sung sẽ được thêm vào mỗi mã thông báo, cho biết chế độ () đã tạo ra nó, có tiền tố là
var myCodeMirror = CodeMirror(document.body);
28. Ví dụ: mã thông báo từ chế độ XML sẽ nhận lớp
var myCodeMirror = CodeMirror(document.body);
29.
var myCodeMirror = CodeMirror(document.body);
30Khi đánh dấu các dòng dài, để duy trì phản hồi nhanh, trình chỉnh sửa sẽ từ bỏ và chỉ định kiểu phần còn lại của dòng dưới dạng văn bản thuần túy khi nó đạt đến một vị trí nhất định. Mặc định là 10 000. Bạn có thể đặt giá trị này thành
var myCodeMirror = CodeMirror(document.body);
31 để tắt hành vi này.
var myCodeMirror = CodeMirror(document.body);
32Chỉ định số lượng dòng được hiển thị bên trên và bên dưới phần tài liệu hiện đang được cuộn để xem. Điều này ảnh hưởng đến số lượng cập nhật cần thiết khi cuộn và khối lượng công việc mà bản cập nhật đó thực hiện. Thông thường bạn nên để mặc định là 10. Có thể được đặt thành
var myCodeMirror = CodeMirror(document.body);
31 để đảm bảo toàn bộ tài liệu luôn được hiển thị và do đó tìm kiếm văn bản của trình duyệt hoạt động trên đó. Điều này sẽ có ảnh hưởng xấu đến hiệu suất của các tài liệu lớn.
var myCodeMirror = CodeMirror(document.body);
34Chỉ định có bật tính năng kiểm tra chính tả trên đầu vào hay không.
var myCodeMirror = CodeMirror(document.body);
35Chỉ định có bật tính năng tự động sửa lỗi trên đầu vào hay không.
var myCodeMirror = CodeMirror(document.body);
36Chỉ định có bật tính năng viết hoa tự động trên đầu vào hay không

Sự kiện

Nhiều đối tượng liên quan đến CodeMirror phát ra các sự kiện, cho phép mã máy khách phản ứng với các tình huống khác nhau. Trình xử lý cho các sự kiện như vậy có thể được đăng ký với các phương thức và trên các đối tượng mà sự kiện kích hoạt. Để kích hoạt các sự kiện của riêng bạn, hãy sử dụng

var myCodeMirror = CodeMirror(document.body);
39, trong đó
var myCodeMirror = CodeMirror(document.body);
40 là đối tượng không phải nút DOM

Phiên bản trình chỉnh sửa kích hoạt các sự kiện sau. Đối số

var myCodeMirror = CodeMirror(document.body);
41 luôn đề cập đến chính người biên tập

var myCodeMirror = CodeMirror(document.body);
42Cháy mỗi khi nội dung của trình chỉnh sửa bị thay đổi.
var myCodeMirror = CodeMirror(document.body);
43 là một đối tượng
var myCodeMirror = CodeMirror(document.body);
44 chứa thông tin về những thay đổi xảy ra như đối số thứ hai.
var myCodeMirror = CodeMirror(document.body);
45 và
var myCodeMirror = CodeMirror(document.body);
46 là các vị trí (trong hệ tọa độ trước khi thay đổi) nơi thay đổi bắt đầu và kết thúc (ví dụ: có thể là
var myCodeMirror = CodeMirror(document.body);
47 nếu vị trí ở đầu dòng #19).
var myCodeMirror = CodeMirror(document.body);
48 là một mảng các chuỗi đại diện cho văn bản đã thay thế phạm vi đã thay đổi (được chia theo dòng).
var myCodeMirror = CodeMirror(document.body);
49 là văn bản từng nằm trong khoảng từ
var myCodeMirror = CodeMirror(document.body);
45 đến
var myCodeMirror = CodeMirror(document.body);
46, bị thay đổi này ghi đè. This event is fired before the end of an , before the DOM updates happen.
var myCodeMirror = CodeMirror(document.body);
52Giống như sự kiện, nhưng theo đợt cho mỗi , truyền một mảng chứa tất cả các thay đổi đã xảy ra trong hoạt động. Sự kiện này được kích hoạt sau khi thao tác kết thúc và các thay đổi hiển thị mà nó tạo ra sẽ kích hoạt một thao tác mới.
var myCodeMirror = CodeMirror(document.body);
54Sự kiện này được kích hoạt trước khi thay đổi được áp dụng và người xử lý sự kiện có thể chọn sửa đổi hoặc hủy bỏ thay đổi. Đối tượng
var myCodeMirror = CodeMirror(document.body);
43 có các thuộc tính
var myCodeMirror = CodeMirror(document.body);
45,
var myCodeMirror = CodeMirror(document.body);
46 và
var myCodeMirror = CodeMirror(document.body);
48, như với sự kiện. Nó cũng có phương thức
var myCodeMirror = CodeMirror(document.body);
60, có thể được gọi để hủy thay đổi và nếu thay đổi không đến từ sự kiện hoàn tác hoặc làm lại, thì phương thức
var myCodeMirror = CodeMirror(document.body);
61, có thể được sử dụng để sửa đổi thay đổi. Không thể sửa đổi các thay đổi hoàn tác hoặc làm lại vì chúng chứa một số siêu thông tin để khôi phục các phạm vi được đánh dấu cũ chỉ hợp lệ cho thay đổi cụ thể đó. Tất cả ba đối số của
var myCodeMirror = CodeMirror(document.body);
62 là tùy chọn và có thể bỏ qua để giữ nguyên giá trị hiện có cho trường đó. Ghi chú. bạn không được làm bất cứ điều gì từ trình xử lý
var myCodeMirror = CodeMirror(document.body);
63 có thể gây ra thay đổi đối với tài liệu hoặc cách trực quan hóa tài liệu. Làm như vậy, vì trình xử lý này được gọi trực tiếp từ phần trung tâm của quá trình triển khai CodeMirror, có thể khiến trình chỉnh sửa bị hỏng.
var myCodeMirror = CodeMirror(document.body);
64Sẽ được kích hoạt khi con trỏ hoặc lựa chọn di chuyển hoặc bất kỳ thay đổi nào được thực hiện đối với nội dung trình chỉnh sửa.
var myCodeMirror = CodeMirror(document.body);
65Được kích hoạt sau khi khóa được xử lý thông qua bản đồ khóa.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
5 là tên của khóa được xử lý (ví dụ:
var myCodeMirror = CodeMirror(document.body);
67 hoặc
var myCodeMirror = CodeMirror(document.body);
68) và
var myCodeMirror = CodeMirror(document.body);
69 là sự kiện DOM
var myCodeMirror = CodeMirror(document.body);
70 hoặc
var myCodeMirror = CodeMirror(document.body);
71.
var myCodeMirror = CodeMirror(document.body);
72Được kích hoạt bất cứ khi nào đầu vào mới được đọc từ vùng văn bản ẩn (do người dùng nhập hoặc dán).
var myCodeMirror = CodeMirror(document.body);
73Được kích hoạt nếu đầu vào văn bản khớp với các mẫu của chế độ và điều này làm cho vết lõm của dòng thay đổi.
var myCodeMirror = CodeMirror(document.body);
74Sự kiện này được kích hoạt trước khi lựa chọn được di chuyển. Trình xử lý của nó có thể kiểm tra tập hợp các phạm vi lựa chọn, trình bày dưới dạng một mảng gồm các đối tượng
var myCodeMirror = CodeMirror(document.body);
75 trong thuộc tính
var myCodeMirror = CodeMirror(document.body);
76 của đối số
var myCodeMirror = CodeMirror(document.body);
77 và tùy ý thay đổi chúng bằng cách gọi phương thức
var myCodeMirror = CodeMirror(document.body);
62 trên đối tượng này, truyền một mảng các phạm vi có cùng định dạng. Đối tượng cũng chứa thuộc tính
var myCodeMirror = CodeMirror(document.body);
79 giữ chuỗi gốc được truyền cho phương thức thay đổi lựa chọn, nếu có. Trình xử lý cho sự kiện này có hạn chế giống như trình xử lý — chúng không được làm bất cứ điều gì để cập nhật trực tiếp trạng thái của trình chỉnh sửa.
var myCodeMirror = CodeMirror(document.body);
81Cháy bất cứ khi nào trình chỉnh sửa thay đổi (do cuộn, chỉnh sửa hoặc bất kỳ yếu tố nào khác). Các đối số
var myCodeMirror = CodeMirror(document.body);
45 và
var myCodeMirror = CodeMirror(document.body);
46 đưa ra điểm bắt đầu và điểm kết thúc mới của khung nhìn.
var myCodeMirror = CodeMirror(document.body);
84Điều này được báo hiệu khi tài liệu của người biên tập được thay thế bằng phương pháp.
var myCodeMirror = CodeMirror(document.body);
86Cháy khi trình soạn thảo (khu vực số dòng) được nhấp vào. Sẽ chuyển phiên bản trình soạn thảo làm đối số đầu tiên, số (dựa trên số 0) của dòng được nhấp làm đối số thứ hai, lớp CSS của máng xối được nhấp làm đối số thứ ba và đối tượng sự kiện
var myCodeMirror = CodeMirror(document.body);
87 thô làm đối số thứ tư.
var myCodeMirror = CodeMirror(document.body);
88Cháy khi máng xối trình soạn thảo (khu vực số dòng) nhận được sự kiện
var myCodeMirror = CodeMirror(document.body);
89. Sẽ chuyển phiên bản trình soạn thảo làm đối số đầu tiên, số (dựa trên số 0) của dòng được nhấp làm đối số thứ hai, lớp CSS của máng xối được nhấp làm đối số thứ ba và đối tượng sự kiện chuột
var myCodeMirror = CodeMirror(document.body);
89 thô làm đối số thứ tư. Bạn có thể
var myCodeMirror = CodeMirror(document.body);
91 sự kiện, để báo hiệu rằng CodeMirror không nên xử lý thêm.
var myCodeMirror = CodeMirror(document.body);
92Cháy bất cứ khi nào trình chỉnh sửa tập trung.
var myCodeMirror = CodeMirror(document.body);
93Cháy bất cứ khi nào người chỉnh sửa không tập trung.
var myCodeMirror = CodeMirror(document.body);
94Cháy khi trình chỉnh sửa được cuộn.
var myCodeMirror = CodeMirror(document.body);
95Cháy khi người chỉnh sửa hoặc. Chủ yếu hữu ích để làm mất hiệu lực các giá trị được lưu trong bộ nhớ cache phụ thuộc vào trình chỉnh sửa hoặc kích thước ký tự.
var myCodeMirror = CodeMirror(document.body);
96Được gửi đi mỗi khi một tùy chọn được thay đổi với.
var myCodeMirror = CodeMirror(document.body);
98Cháy khi trình soạn thảo cố gắng cuộn con trỏ của nó vào chế độ xem. Có thể được kết nối để xử lý các vùng chứa có thể cuộn bổ sung xung quanh trình chỉnh sửa. Khi đối tượng sự kiện có phương thức
var myCodeMirror = CodeMirror(document.body);
91 được gọi, CodeMirror sẽ không tự cuộn cửa sổ.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
00Sẽ được kích hoạt bất cứ khi nào CodeMirror cập nhật màn hình DOM của nó.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
01Được kích hoạt bất cứ khi nào một dòng được (kết xuất lại) với DOM. Được kích hoạt ngay sau khi phần tử DOM được tạo, trước khi nó được thêm vào tài liệu. Trình xử lý có thể gây rối với kiểu của phần tử kết quả hoặc thêm trình xử lý sự kiện, nhưng không nên cố thay đổi trạng thái của trình chỉnh sửa.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
02Được kích hoạt khi CodeMirror đang xử lý một sự kiện DOM thuộc loại này. Bạn có thể
var myCodeMirror = CodeMirror(document.body);
91 sự kiện hoặc cung cấp cho nó thuộc tính
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
04 trung thực, để báo hiệu rằng CodeMirror không nên xử lý thêm

Các đối tượng tài liệu (ví dụ của ) phát ra các sự kiện sau

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
06Được kích hoạt bất cứ khi nào có thay đổi đối với tài liệu.
var myCodeMirror = CodeMirror(document.body);
43 có loại tương tự như đối tượng được chuyển đến sự kiện của trình chỉnh sửa.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
09Xem các trường hợp trên trình chỉnh sửa.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
10Được kích hoạt bất cứ khi nào con trỏ hoặc lựa chọn trong tài liệu này thay đổi.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
11Tương đương với kích hoạt trên phiên bản trình soạn thảo

Điều khiển dòng (chẳng hạn như được trả về bởi ) hỗ trợ các sự kiện này

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
13Sẽ được kích hoạt khi đối tượng đường bị xóa. Một đối tượng dòng được liên kết với phần đầu của dòng. Chủ yếu hữu ích khi bạn cần tìm hiểu khi nào bạn trên một dòng nhất định bị xóa.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
14Cháy khi nội dung văn bản của dòng bị thay đổi theo bất kỳ cách nào (nhưng dòng không bị xóa hoàn toàn). Đối tượng
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
15 tương tự như đối tượng được truyền vào đối tượng biên tập

Bộ điều khiển phạm vi được đánh dấu (

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
16), như được trả về bởi và , phát ra các sự kiện sau

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
19Được kích hoạt khi con trỏ đi vào phạm vi được đánh dấu. Từ trình xử lý sự kiện này, trạng thái trình chỉnh sửa có thể được kiểm tra nhưng không được sửa đổi, ngoại trừ phạm vi mà sự kiện kích hoạt có thể bị xóa.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
20Được kích hoạt khi phạm vi bị xóa, thông qua chuyển động của con trỏ kết hợp với hoặc thông qua lệnh gọi phương thức
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
22 của nó. Sẽ chỉ được bắn một lần trên mỗi tay cầm. Lưu ý rằng việc xóa phạm vi thông qua chỉnh sửa văn bản không kích hoạt sự kiện này vì hành động hoàn tác có thể khiến phạm vi tồn tại trở lại.
var myCodeMirror = CodeMirror(document.body);
45 và
var myCodeMirror = CodeMirror(document.body);
46 cung cấp một phần của tài liệu mà phạm vi được mở rộng khi nó bị xóa.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
25Được kích hoạt khi phần cuối cùng của điểm đánh dấu bị xóa khỏi tài liệu bằng thao tác chỉnh sửa.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
26Được kích hoạt khi, sau khi điểm đánh dấu bị xóa bằng cách chỉnh sửa, một thao tác hoàn tác đã đưa điểm đánh dấu trở lại

Tiện ích dòng (

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
27), được trả về bởi , kích hoạt các sự kiện này

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
29Được kích hoạt bất cứ khi nào trình chỉnh sửa thêm lại tiện ích vào DOM. Điều này sẽ xảy ra một lần ngay sau khi tiện ích được thêm vào (nếu tiện ích được cuộn vào chế độ xem), và sau đó xảy ra một lần nữa bất cứ khi nào tiện ích được cuộn ra khỏi chế độ xem và quay lại hoặc khi các thay đổi đối với tùy chọn trình chỉnh sửa hoặc dòng mà tiện ích đang bật yêu cầu

Bản đồ chính

Bản đồ phím là cách để liên kết các phím và nút chuột với chức năng. Sơ đồ khóa là một chuỗi ánh xạ đối tượng xác định các nút cho các chức năng thực hiện chức năng của chúng

Các bản phân phối CodeMirror đi kèm với sơ đồ bàn phím kiểu Emacs, Vim và Sublime Text

Các phím được xác định theo tên hoặc theo ký tự. Đối tượng

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
30 xác định tên cho các khóa chung và liên kết chúng với mã khóa của chúng. Ví dụ về các tên được xác định ở đây là
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
31,
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
32 và
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
33. Chúng có thể được đặt trước bằng
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
34,
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
35,
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
36 và
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
37 để chỉ định một công cụ sửa đổi. Vì vậy, ví dụ,
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
38 sẽ là mã định danh khóa hợp lệ

Ví dụ phổ biến. ánh xạ phím Tab để chèn khoảng trắng thay vì ký tự tab

editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});

Ngoài ra, một ký tự có thể được chỉ định trực tiếp bằng cách bao quanh ký tự đó trong dấu nháy đơn, ví dụ:

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
39 hoặc
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
40. Do những hạn chế trong cách trình duyệt kích hoạt các sự kiện quan trọng, những sự kiện này có thể không có tiền tố là các công cụ sửa đổi

Để liên kết các nút chuột, hãy sử dụng tên `Nhấp chuột trái`, `Nhấp chuột giữa` và `Nhấp chuột phải`. These can also be prefixed with modifiers, and in addition, the word `Double` or `Triple` can be put before `Click` (as in `LeftDoubleClick`) to bind a double- or triple-click. Hàm cho một liên kết như vậy được chuyển vào vị trí được nhấp làm đối số thứ hai

Các liên kết phím nhiều nét có thể được chỉ định bằng cách tách các tên phím bằng dấu cách trong tên thuộc tính, ví dụ:

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
41. Khi một bản đồ chứa các ràng buộc hoặc khóa nhiều dấu có các công cụ sửa đổi không được chỉ định theo thứ tự mặc định (
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
42), bạn phải gọi
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
43 trên đó trước khi có thể sử dụng. Hàm này lấy một sơ đồ bàn phím và sửa đổi nó để chuẩn hóa thứ tự của bộ sửa đổi và nhận dạng chính xác các liên kết nhiều nét. Nó sẽ tự trả về sơ đồ bàn phím

Đối tượng

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
44 liên kết các bản đồ chính với tên. Mã người dùng và định nghĩa sơ đồ khóa có thể gán các thuộc tính bổ sung cho đối tượng này. Ở bất kỳ nơi nào cần có bản đồ khóa, một chuỗi có thể được cung cấp, chuỗi này sẽ được tra cứu trong đối tượng này. Nó cũng chứa bản đồ khóa
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
5 giữ các ràng buộc mặc định

Các giá trị của thuộc tính trong sơ đồ khóa có thể là hàm của một đối số (ví dụ CodeMirror), chuỗi hoặc

require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
2. Chuỗi tham chiếu đến, được mô tả bên dưới. Nếu thuộc tính được đặt thành
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
2, CodeMirror để lại việc xử lý khóa cho trình duyệt. Hàm xử lý khóa có thể trả về
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
48 để cho biết rằng nó đã quyết định không xử lý khóa và các trình xử lý khác (hoặc hành vi mặc định) sẽ được thay phiên nhau

Các phím được ánh xạ tới các tên lệnh bắt đầu bằng các ký tự

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
49 hoặc tới các hàm có thuộc tính
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
50 trung thực (được sử dụng cho các hành động di chuyển con trỏ) sẽ được kích hoạt ngay cả khi có thêm công cụ sửa đổi
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
51 (i. e.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
52 phù hợp với cả tăng và tăng). Điều này được sử dụng để dễ dàng thực hiện lựa chọn thay đổi

Các bản đồ chính có thể hỗ trợ lẫn nhau bằng cách xác định thuộc tính

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
53. Điều này chỉ ra rằng khi không tìm thấy khóa trong bản đồ, một hoặc nhiều bản đồ khác sẽ được tìm kiếm. Nó có thể chứa một key map hoặc một mảng các key map

Khi một sơ đồ phím cần thiết lập một thứ gì đó khi nó hoạt động hoặc phá bỏ một thứ gì đó khi bị hủy kích hoạt, nó có thể chứa các thuộc tính

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
54 và/hoặc
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
55, những thuộc tính này sẽ giữ các chức năng lấy phiên bản trình soạn thảo và sơ đồ bàn phím tiếp theo hoặc trước đó. Lưu ý rằng điều này chỉ hoạt động cho , không dành cho bản đồ dự phòng hoặc bản đồ được thêm bằng hoặc

lệnh

Các lệnh là các hành động không có tham số có thể được thực hiện trên trình chỉnh sửa. Công dụng chính của chúng là cho các ràng buộc chính. Các lệnh được xác định bằng cách thêm các thuộc tính vào đối tượng

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
58. Một số lệnh phổ biến được xác định bởi chính thư viện, hầu hết chúng được sử dụng bởi các ràng buộc khóa mặc định. Giá trị của thuộc tính lệnh phải là hàm của một đối số (phiên bản trình soạn thảo)

Một số lệnh bên dưới được tham chiếu trong bản đồ khóa mặc định, nhưng không được xác định bởi thư viện lõi. Chúng được dự định để được xác định bởi mã người dùng hoặc addons

Các lệnh cũng có thể được chạy với phương thức

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
60 Ctrl-A (PC), Cmd-A (Mac) Chọn toàn bộ nội dung của trình chỉnh sửa.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
61 Esc Khi có nhiều lựa chọn, thao tác này sẽ bỏ chọn tất cả trừ lựa chọn chính.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
62 Ctrl-K (Mac) Diệt dòng kiểu Emacs. Xóa một phần của dòng sau con trỏ. Nếu chỉ bao gồm khoảng trắng, dòng mới ở cuối dòng cũng bị xóa.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
63 Ctrl-D (PC), Cmd-D (Mac) Xóa toàn bộ dòng dưới con trỏ, bao gồm cả dòng mới ở cuối.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
64Xóa phần của dòng trước con trỏ.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
65 Cmd-Backspace (Mac) Xóa phần của dòng từ phía bên trái của dòng trực quan mà con trỏ đang ở trên con trỏ.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
66 Cmd-Delete (Mac) Xóa một phần của dòng từ con trỏ sang phía bên phải của dòng trực quan mà con trỏ đang bật.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
67 Ctrl-Z (PC), Cmd-Z (Mac) Hoàn tác thay đổi cuối cùng. Lưu ý rằng, vì các trình duyệt vẫn không cho phép tập lệnh phản ứng hoặc tùy chỉnh menu ngữ cảnh nên việc chọn hoàn tác (hoặc làm lại) từ menu ngữ cảnh trong phiên bản CodeMirror không hoạt động.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
68 Ctrl-Y (PC), Shift-Cmd-Z (Mac), Cmd-Y (Mac) Làm lại thay đổi vừa hoàn tác.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
69 Ctrl-U (PC), Cmd-U (Mac) Hoàn tác thay đổi cuối cùng đối với lựa chọn hoặc nếu không có thay đổi chỉ dành cho lựa chọn tại .
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
70 Alt-U (PC), Shift-Cmd-U (Mac) Làm lại thay đổi cuối cùng đối với lựa chọn hoặc thay đổi văn bản cuối cùng nếu không có lựa chọn nào .
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
71 Ctrl-Home (PC), Cmd-Up (Mac), Cmd-Home (Mac) Di chuyển con trỏ đến đầu tài liệu.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
72 Ctrl-End (PC), Cmd-End (Mac), Cmd-Down (Mac) Di chuyển con trỏ đến cuối tài liệu.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
73 Alt-Left (PC), Ctrl-A (Mac) Di chuyển con trỏ đến đầu dòng.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
74 Trang chủ Di chuyển đến đầu văn bản trên dòng hoặc nếu chúng ta đã ở đó, đến đầu dòng thực sự (bao gồm cả khoảng trắng).
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
75 Alt-Right (PC), Ctrl-E (Mac) Di chuyển con trỏ đến cuối dòng.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
76 Cmd-Right (Mac) Di chuyển con trỏ sang bên phải của đường trực quan mà nó đang bật.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
77 Cmd-Left (Mac) Di chuyển con trỏ sang phía bên trái của dòng trực quan mà nó đang bật. Nếu dòng này được bao bọc, đó có thể không phải là điểm bắt đầu của dòng.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
78Di chuyển con trỏ sang bên trái của đường trực quan mà nó đang bật. Nếu điều đó đưa nó đến đầu dòng, hãy cư xử như.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
80 Lên, Ctrl-P (Mac) Di chuyển con trỏ lên trên một dòng.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
81 Xuống, Ctrl-N (Mac) Di chuyển xuống một dòng.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
82 PageUp, Shift-Ctrl-V (Mac) Di chuyển con trỏ lên một màn hình và cuộn lên theo khoảng cách tương tự.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
83 PageDown, Ctrl-V (Mac) Di chuyển con trỏ xuống một màn hình và cuộn xuống theo khoảng cách tương tự.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
84 Trái, Ctrl-B (Mac) Di chuyển con trỏ sang trái một ký tự, chuyển về dòng trước khi chạm vào đầu dòng.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
85 Phải, Ctrl-F (Mac) Di chuyển con trỏ sang phải một ký tự, chuyển sang dòng tiếp theo khi nhấn vào cuối dòng.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
86Di chuyển con trỏ sang trái một ký tự, nhưng không vượt qua ranh giới của dòng.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
87Di chuyển con trỏ sang phải một ký tự, không vượt qua ranh giới dòng.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
88 Alt-B (Mac) Di chuyển con trỏ đến đầu từ trước đó.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
89 Alt-F (Mac) Di chuyển con trỏ đến cuối từ tiếp theo.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
90 Ctrl-Left (PC), Alt-Left (Mac) Di chuyển sang bên trái của nhóm trước con trỏ. Nhóm là một dải các ký tự từ, một dải các ký tự dấu chấm câu, một dòng mới hoặc một dải có nhiều hơn một ký tự khoảng trắng.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
91 Ctrl-Phải (PC), Alt-Phải (Mac) Di chuyển sang bên phải của nhóm sau con trỏ (xem ).
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
92 Shift-Backspace, Ctrl-H (Mac) Xóa ký tự trước con trỏ.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
93 Xóa, Ctrl-D (Mac) Xóa ký tự sau con trỏ.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
94 Alt-Backspace (Mac) Xóa đến đầu từ trước con trỏ.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
95 Alt-D (Mac) Xóa đến cuối từ sau con trỏ.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
96 Ctrl-Backspace (PC), Alt-Backspace (Mac) Xóa ở bên trái trước con trỏ.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
97 Ctrl-Delete (PC), Ctrl-Alt-Backspace (Mac), Alt-Delete (Mac) Xóa về đầu sau con trỏ.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
98 Shift-Tab Tự động thụt lề dòng hiện tại hoặc vùng chọn.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
99 Ctrl-] (PC), Cmd-] (Mac) Indent the current line or selection by one .
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
00 Ctrl-[ (PC), Cmd-[ (Mac) Xoá dòng hiện tại hoặc chọn theo một.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
01Chèn ký tự tab vào con trỏ.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
02Chèn lượng khoảng trắng phù hợp với chiều rộng mà một tab ở vị trí con trỏ sẽ có.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
03 Tab Nếu một mục nào đó được chọn, hãy thụt vào một mục. Nếu không có gì được chọn, hãy chèn một ký tự tab.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
04 Ctrl-T (Mac) Hoán đổi ký tự trước và sau con trỏ.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
05 Enter Chèn một dòng mới và tự động thụt lề dòng mới.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
06 Chèn Lật cờ.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
07 Ctrl-S (PC), Cmd-S (Mac) Không được xác định bởi thư viện lõi, chỉ được đề cập trong bản đồ chính. Dự định cung cấp một cách dễ dàng để mã người dùng xác định lệnh lưu.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
08 Ctrl-F (PC), Cmd-F (Mac)
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
09 Ctrl-G (PC), Cmd .
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
10Shift-Ctrl-G (PC), Shift-Cmd-G (Mac)
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
11Shift-Ctrl-F (PC), Cmd-Alt-F (Mac)
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
12Shift-Ctrl-R (PC), Shift-Cmd-Alt-F (Mac)Not defined by the core library, but defined in the (or custom client addons).

Kiểu dáng tùy chỉnh

Ở một mức độ nhất định, giao diện của CodeMirror có thể được thay đổi bằng cách sửa đổi các tệp biểu định kiểu. Các biểu định kiểu được cung cấp bởi các chế độ chỉ cung cấp màu sắc cho chế độ đó và có thể được điều chỉnh theo cách rất đơn giản. Để tự tạo kiểu cho trình chỉnh sửa, có thể thay đổi hoặc ghi đè các kiểu được xác định trong

var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
6

Cần phải cẩn thận ở đó, vì rất nhiều quy tắc trong tệp này là cần thiết để CodeMirror hoạt động bình thường. Tất nhiên, việc điều chỉnh màu sắc phải an toàn và nếu cẩn thận, nhiều thứ khác cũng có thể được thay đổi. Các lớp CSS được xác định trong tệp này phục vụ các vai trò sau

var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
14Thành phần bên ngoài của trình soạn thảo. Điều này nên được sử dụng cho chiều rộng, chiều cao, đường viền và định vị của trình chỉnh sửa. Cũng có thể được sử dụng để đặt kiểu phù hợp với mọi thứ bên trong trình chỉnh sửa (chẳng hạn như phông chữ và cỡ chữ) hoặc để đặt nền. Đặt kiểu
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
15 của lớp này thành
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
16 sẽ làm cho trình chỉnh sửa thay đổi kích thước để phù hợp với nội dung của nó (bạn cũng nên đặt thành
var myCodeMirror = CodeMirror(document.body);
31 khi thực hiện việc này.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
19Bất cứ khi nào trình chỉnh sửa tập trung, phần tử trên cùng sẽ nhận được lớp này. Điều này được sử dụng để ẩn con trỏ và cung cấp cho lựa chọn một màu khác khi trình chỉnh sửa không tập trung.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
20Đây là phông nền cho tất cả các máng xối. Sử dụng nó để đặt màu nền máng xối mặc định và tùy ý thêm đường viền ở bên phải máng xối.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
21Sử dụng điều này để tạo nền hoặc chiều rộng cho rãnh số dòng.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
22Được sử dụng để tạo kiểu cho số dòng riêng lẻ thực tế. Đây sẽ không phải là phần tử con của phần tử
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
6 (số nhiều), mà sẽ được định vị tuyệt đối để phủ lên nó. Sử dụng công cụ này để đặt thuộc tính căn chỉnh và văn bản cho số dòng.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
24Các đường có thể nhìn thấy. Đây là nơi bạn chỉ định phần đệm dọc cho nội dung trình chỉnh sửa.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
25Con trỏ là phần tử khối được định vị tuyệt đối. Bạn có thể làm cho nó trông bất cứ cách nào bạn muốn.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
26Lựa chọn được đại diện bởi
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
27 phần tử với lớp này.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
28,
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
29Những cái này được sử dụng để tạo kiểu cho các dấu ngoặc khớp (hoặc không khớp)

Nếu các biểu định kiểu trang của bạn thực hiện những điều thú vị đối với tất cả các phần tử

var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
30 hoặc
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
31 (bạn có thể không nên làm điều đó), bạn sẽ phải xác định các quy tắc để hủy bỏ các hiệu ứng này một lần nữa đối với các phần tử trong lớp
var myCodeMirror = CodeMirror(document.body);
1

Chủ đề cũng chỉ đơn giản là các tệp CSS, xác định màu sắc cho các yếu tố cú pháp khác nhau. Xem các tệp trong thư mục

var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
4

API lập trình

Rất nhiều tính năng của CodeMirror chỉ khả dụng thông qua API của nó. Vì vậy, bạn cần viết mã (hoặc sử dụng ) nếu bạn muốn hiển thị chúng cho người dùng của mình

Bất cứ khi nào các điểm trong tài liệu được trình bày, API sẽ sử dụng các đối tượng có thuộc tính

var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
34 và
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
35. Cả hai đều dựa trên số không. CodeMirror đảm bảo 'cắt' bất kỳ vị trí nào được chuyển bởi mã máy khách để chúng vừa với bên trong tài liệu, vì vậy bạn không nên lo lắng quá nhiều về việc vệ sinh tọa độ của mình. Nếu bạn cung cấp cho
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
35 giá trị của
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0 hoặc không chỉ định giá trị đó, giá trị này sẽ được thay thế bằng độ dài của dòng được chỉ định. Những vị trí như vậy cũng có thể có tài sản
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
38 đang nắm giữ
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
39 hoặc
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
40, cho dù vị trí được liên kết với ký tự trước hay sau nó. Ví dụ, điều này ảnh hưởng đến vị trí con trỏ được vẽ trên ranh giới ngắt dòng hoặc định hướng giá thầu

Các phương thức có tiền tố là

var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
41 có thể, trừ khi được chỉ định khác, được gọi cả trên các phiên bản
var myCodeMirror = CodeMirror(document.body);
1 (biên tập viên) và phiên bản
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
05. Các phương thức có tiền tố là
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
44 chỉ khả dụng trên các phiên bản
var myCodeMirror = CodeMirror(document.body);
1

Hàm tạo

Xây dựng một phiên bản trình soạn thảo được thực hiện với hàm tạo

var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
46. Nếu đối số
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
47 là một phần tử DOM, trình soạn thảo sẽ được thêm vào nó. Nếu nó là một chức năng, nó sẽ được gọi và dự kiến ​​​​sẽ đặt trình soạn thảo vào tài liệu.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
48 có thể là một phần tử ánh xạ tới các giá trị. Các tùy chọn mà nó không chỉ định rõ ràng (hoặc tất cả các tùy chọn, nếu nó không được thông qua) sẽ được lấy từ

Lưu ý rằng đối tượng tùy chọn được chuyển đến hàm tạo sẽ bị thay đổi khi tùy chọn của phiên bản là , vì vậy bạn không nên chia sẻ các đối tượng đó giữa các phiên bản

Xem cách khác để xây dựng phiên bản trình soạn thảo

Phương pháp thao tác nội dung

var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
51Nhận nội dung trình chỉnh sửa hiện tại. Bạn có thể truyền cho nó một đối số tùy chọn để chỉ định chuỗi sẽ được sử dụng để phân tách các dòng (mặc định là
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
52).
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
53Đặt nội dung trình chỉnh sửa.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
54Lấy văn bản giữa các điểm đã cho trong trình chỉnh sửa, đó phải là đối tượng
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55. Có thể đưa ra đối số thứ ba tùy chọn để chỉ ra chuỗi phân cách dòng sẽ sử dụng (mặc định là
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
52).
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
57Thay thế một phần của tài liệu giữa
var myCodeMirror = CodeMirror(document.body);
45 và
var myCodeMirror = CodeMirror(document.body);
46 bằng chuỗi đã cho.
var myCodeMirror = CodeMirror(document.body);
45 và
var myCodeMirror = CodeMirror(document.body);
46 phải là đối tượng
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55. Có thể bỏ đi
var myCodeMirror = CodeMirror(document.body);
46 để chỉ cần chèn chuỗi vào vị trí
var myCodeMirror = CodeMirror(document.body);
45. Khi
var myCodeMirror = CodeMirror(document.body);
79 được cung cấp, nó sẽ được chuyển cho , và chữ cái đầu tiên của nó sẽ được sử dụng để xác định liệu thay đổi này có thể được hợp nhất với các sự kiện lịch sử trước đó hay không, theo cách được mô tả cho.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
67Lấy nội dung của dòng
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
68.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
69Nhận số dòng trong trình chỉnh sửa.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
70Nhận số dòng đầu tiên trong trình chỉnh sửa. Giá trị này thường sẽ bằng 0 nhưng đối với hoặc được khởi tạo bằng dòng đầu tiên khác 0, nó có thể trả về các giá trị khác.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
71Nhận số dòng cuối cùng trong trình chỉnh sửa. Điều này thường sẽ là
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
72, nhưng đối với , nó có thể trả về các giá trị khác.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
73Tìm điều khiển dòng cho số dòng đã cho.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
74Cho một điều khiển dòng, trả về vị trí hiện tại của dòng đó (hoặc
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0 khi nó không còn trong tài liệu).
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
76_______5_______77Lặp lại trên toàn bộ tài liệu, hoặc nếu số dòng
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
78 và
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
79 được đưa ra, thì phạm vi từ
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
78 đến (không bao gồm)
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
79 và gọi số _
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
82 cho mỗi dòng, đi qua phần điều khiển dòng.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
83 dừng lặp lại nếu
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
82 trả về giá trị trung thực. Đây là cách nhanh hơn để truy cập một loạt trình xử lý dòng hơn là gọi cho từng người trong số họ. Note that line handles have a
var myCodeMirror = CodeMirror(document.body);
48 property containing the line's content (as a string).
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
87Đặt nội dung của trình chỉnh sửa là 'sạch', cờ sẽ giữ lại cho đến khi được chỉnh sửa và sẽ được đặt lại khi chỉnh sửa đó được hoàn tác lại. Hữu ích để theo dõi xem nội dung có cần được lưu hay không. Chức năng này không được dùng nữa thay cho , chức năng này cho phép nhiều hệ thống con theo dõi các khái niệm khác nhau về độ sạch mà không can thiệp.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
89Trả về một số mà sau này có thể được chuyển đến để kiểm tra xem có bất kỳ chỉnh sửa nào được thực hiện (và không được hoàn tác) trong thời gian chờ đợi hay không. Nếu
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
91 là đúng, thì sự kiện lịch sử hiện tại sẽ bị 'đóng', nghĩa là không thể kết hợp sự kiện này với các thay đổi tiếp theo (các sự kiện xóa hoặc nhập nhanh thường được kết hợp).
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
92Trả về liệu tài liệu hiện có sạch hay không — không bị sửa đổi kể từ khi khởi tạo hoặc lần gọi cuối cùng nếu không có đối số nào được chuyển hoặc kể từ lần gọi khớp đến nếu giá trị tạo được đưa ra

Con trỏ và phương pháp lựa chọn

var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
95Nhận mã đang chọn. Tùy chọn vượt qua dấu tách dòng để đặt giữa các dòng trong đầu ra. Khi có nhiều lựa chọn, chúng được nối với các phiên bản của
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
96 ở giữa.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
97Trả về một mảng chứa một chuỗi cho mỗi lựa chọn, đại diện cho nội dung của các lựa chọn.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
98Thay thế (các) lựa chọn bằng chuỗi đã cho. Theo mặc định, lựa chọn mới kết thúc sau văn bản được chèn. Đối số tùy chọn
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
99 có thể được sử dụng để thay đổi điều này—việc chuyển qua
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
00 sẽ khiến văn bản mới được chọn, việc chuyển qua
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
01 sẽ thu gọn lựa chọn về đầu văn bản được chèn.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
02Độ dài của mảng đã cho phải giống với số lượng lựa chọn đang hoạt động. Thay thế nội dung của các lựa chọn bằng các chuỗi trong mảng. Đối số
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
99 hoạt động giống như trong.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
05Lấy một đầu của vùng chọn chính.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
78 là một chuỗi tùy chọn cho biết kết thúc của lựa chọn sẽ trả về. Nó có thể là
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
07,
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
08,
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
09 (mặt của vùng chọn di chuyển khi bạn nhấn shift+mũi tên) hoặc
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
10 (mặt cố định của vùng chọn). Bỏ qua đối số cũng giống như chuyển
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
09. Một đối tượng
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55 sẽ được trả lại.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
13Truy xuất danh sách tất cả các lựa chọn hiện tại. Chúng sẽ luôn được sắp xếp và không bao giờ trùng lặp (các lựa chọn chồng chéo được hợp nhất). Mỗi đối tượng trong mảng chứa các thuộc tính
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
14 và
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
15 đề cập đến các đối tượng
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
17Trả về true nếu bất kỳ văn bản nào được chọn.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
18Đặt vị trí con trỏ. Bạn có thể truyền một đối tượng
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55 hoặc dòng và ký tự dưới dạng hai tham số riêng biệt. Sẽ thay thế tất cả các lựa chọn bằng một lựa chọn trống duy nhất ở vị trí đã cho. Các tùy chọn được hỗ trợ giống như đối với.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
21Đặt phạm vi lựa chọn duy nhất.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
14 và
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
15 phải là đối tượng
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
15 mặc định là
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
14 khi không được cung cấp. Các tùy chọn này được hỗ trợ.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
27Xác định xem đầu lựa chọn có được cuộn vào xem hay không. Mặc định là true.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
28Xác định xem sự kiện lịch sử lựa chọn có thể được hợp nhất với sự kiện trước đó hay không. Khi một nguồn gốc bắt đầu bằng ký tự
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
29 và lựa chọn được ghi lại cuối cùng có cùng một nguồn gốc và tương tự nhau (đóng trong , cả hai đều được thu gọn hoặc cả hai không được thu gọn), cái mới sẽ thay thế cái cũ. Khi bắt đầu bằng
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
30, nó sẽ luôn thay thế sự kiện trước đó (nếu sự kiện đó có cùng nguồn gốc). Chuyển động tích hợp sử dụng nguồn gốc
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
31. Đầu vào của người dùng sử dụng nguồn gốc
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
32.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
33Xác định hướng điều chỉnh các điểm cuối lựa chọn khi chúng nằm trong một phạm vi. Có thể là -1 (lùi) hoặc 1 (tiến). Khi không được cung cấp, độ lệch sẽ dựa trên vị trí tương đối của lựa chọn cũ—người chỉnh sửa sẽ cố gắng di chuyển xa hơn khỏi vị trí đó để tránh bị kẹt.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
34Thiết lập một tập hợp các lựa chọn mới. Phải có ít nhất một lựa chọn trong mảng đã cho. Khi
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
35 là một số, nó sẽ xác định lựa chọn nào là lựa chọn chính. Khi nó không được cung cấp, chỉ mục chính được lấy từ lựa chọn trước đó hoặc được đặt thành phạm vi cuối cùng nếu lựa chọn trước đó có ít phạm vi hơn lựa chọn mới. Hỗ trợ các tùy chọn tương tự như.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
15 mặc định là
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
14 khi không được cung cấp.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
39Thêm một lựa chọn mới vào tập hợp các lựa chọn hiện có và biến nó thành lựa chọn chính.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
40Tương tự như , nhưng sẽ, nếu dịch chuyển được giữ hoặc cờ được đặt, di chuyển phần đầu của vùng chọn trong khi để neo ở vị trí hiện tại.
var myCodeMirror = CodeMirror(document.body);
46 là tùy chọn và có thể được thông qua để đảm bảo một vùng (ví dụ: một từ hoặc đoạn văn) sẽ được chọn (ngoài bất kỳ thứ gì nằm giữa vùng đó và neo hiện tại). Khi có nhiều lựa chọn, tất cả trừ lựa chọn chính sẽ bị loại bỏ theo phương pháp này. Hỗ trợ các tùy chọn tương tự như.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
44Một tương đương với điều đó hoạt động trên tất cả các lựa chọn cùng một lúc.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
46Áp dụng hàm đã cho cho tất cả các lựa chọn hiện có và gọi kết quả.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
48Đặt hoặc xóa cờ 'mở rộng', cờ này hoạt động tương tự như phím shift, ở chỗ nó sẽ khiến con trỏ di chuyển và gọi để giữ nguyên vị trí neo chọn.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
50Nhận giá trị của cờ 'mở rộng'.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
51Cho bạn biết liệu trình chỉnh sửa hiện có tiêu điểm hay không.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
52Được sử dụng để tìm vị trí mục tiêu cho chuyển động con trỏ ngang.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
78 là đối tượng
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55,
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
55 là số nguyên (có thể âm) và
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
56 là một trong chuỗi
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
57,
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
58 hoặc
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
2. Sẽ trả về một vị trí được tạo ra bằng cách di chuyển
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
55 lần khoảng cách được chỉ định bởi
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
56. Khi
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
62 là đúng, chuyển động trong văn bản từ phải sang trái sẽ trực quan hơn là logic. Khi chuyển động được cắt bớt bằng cách nhấn vào phần cuối hoặc phần đầu của tài liệu, giá trị được trả về sẽ có thuộc tính
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
63 được đặt thành true.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
64Tương tự như , nhưng được sử dụng cho chuyển động thẳng đứng.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
56 có thể là
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
3 hoặc
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
68. Các đối số khác và giá trị được trả về có cùng cách giải thích như trong
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
65.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
70Trả về phần đầu và phần cuối của 'từ' (độ dài của các chữ cái, khoảng trắng hoặc dấu chấm câu) tại vị trí đã cho

phương pháp cấu hình

var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
71Thay đổi cấu hình của trình chỉnh sửa.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
72 nếu tên của một và
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
73 phải là một giá trị hợp lệ cho tùy chọn đó.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
74Truy xuất giá trị hiện tại của tùy chọn đã cho cho phiên bản trình chỉnh sửa này.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
75Đính kèm một bổ sung cho biên tập viên. Điều này chủ yếu hữu ích cho các addon cần đăng ký một số trình xử lý chính mà không cần giẫm lên tùy chọn. Các bản đồ được thêm theo cách này có mức độ ưu tiên cao hơn so với
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
56 và các tùy chọn và giữa chúng, các bản đồ được thêm vào trước đó có mức độ ưu tiên thấp hơn so với các bản đồ được thêm vào sau, trừ khi đối số
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
79 được thông qua, trong trường hợp đó, chúng sẽ kết thúc bên dưới các bản đồ chính khác được thêm vào .
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
80Vô hiệu hóa sơ đồ bàn phím được thêm bằng. Either pass in the key map object itself, or a string, which will be compared against the
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
5 property of the active key maps.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
83Bật lớp phủ tô sáng. Đây là một chế độ nhỏ không trạng thái có thể được sử dụng để thêm phần tô sáng. Ví dụ: addon tìm kiếm sử dụng nó để đánh dấu cụm từ hiện đang được tìm kiếm.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
84 có thể là một hoặc một đối tượng chế độ (một đối tượng có phương thức). Tham số
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
48 là tùy chọn. Nếu được cung cấp, nó phải là một đối tượng, tùy ý chứa các tùy chọn sau.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
87Mặc định là tắt, nhưng có thể được cung cấp để cho phép kiểu dáng lớp phủ, khi không phải là
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0, ghi đè hoàn toàn kiểu dáng của chế độ cơ bản, thay vì cả hai được áp dụng cùng nhau.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
89Xác định thứ tự áp dụng các lớp phủ. Những cái có mức độ ưu tiên cao được áp dụng sau những cái có mức độ ưu tiên thấp hơn và có thể ghi đè độ mờ đục của những cái đến trước. Mặc định là 0.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
90Truyền giá trị chính xác này được truyền cho tham số
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
84 cho hoặc một chuỗi tương ứng với thuộc tính
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
5 của giá trị đó, để xóa lớp phủ một lần nữa.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
94Đăng ký trình xử lý sự kiện cho loại sự kiện đã cho (một chuỗi) trên phiên bản trình chỉnh sửa. Ngoài ra còn có phiên bản
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
95 cho phép đăng ký các sự kiện trên bất kỳ đối tượng nào.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
96Xóa trình xử lý sự kiện trên phiên bản trình chỉnh sửa. Một
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
97 tương đương cũng tồn tại

Phương pháp quản lý tài liệu

Mỗi trình soạn thảo được liên kết với một thể hiện của

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
05, tài liệu của nó. Một tài liệu đại diện cho nội dung của trình soạn thảo, cùng với một lựa chọn, một lịch sử hoàn tác và một. Một tài liệu chỉ có thể được liên kết với một trình chỉnh sửa duy nhất tại một thời điểm. Bạn có thể tạo tài liệu mới bằng cách gọi phương thức khởi tạo
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
99. Ba đối số cuối cùng là tùy chọn và có thể được sử dụng để đặt chế độ cho tài liệu, làm cho nó bắt đầu ở số dòng khác 0 và đặt dấu phân cách dòng cụ thể tương ứng

require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
00Truy xuất tài liệu hiện đang hoạt động từ trình chỉnh sửa.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
01Truy xuất trình chỉnh sửa được liên kết với tài liệu. Có thể trở lại
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
03Đính kèm tài liệu mới vào trình chỉnh sửa. Trả về tài liệu cũ, hiện không còn được liên kết với trình chỉnh sửa.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
04Tạo một bản sao giống hệt của tài liệu đã cho. Khi
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
05 là đúng, lịch sử cũng sẽ được sao chép. Không thể gọi trực tiếp trên trình chỉnh sửa.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
06Tạo tài liệu mới được liên kết với tài liệu đích. Các tài liệu được liên kết sẽ được đồng bộ hóa (các thay đổi đối với tài liệu này cũng được áp dụng cho tài liệu kia) cho đến khi. Đây là những tùy chọn được hỗ trợ.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
07Khi được bật, bản sao được liên kết sẽ chia sẻ lịch sử hoàn tác với bản gốc. Do đó, một cái gì đó được thực hiện ở một trong hai có thể được hoàn tác ở bên kia và ngược lại.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
08
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
09Có thể được đưa ra để biến tài liệu mới thành một bản xem phụ của tài liệu gốc. Subviews chỉ hiển thị một loạt các dòng nhất định. Lưu ý rằng tọa độ dòng bên trong chế độ xem con sẽ nhất quán với tọa độ của chế độ xem gốc, do đó, ví dụ: chế độ xem con bắt đầu từ dòng 10 sẽ tham chiếu đến dòng đầu tiên của nó là dòng 10, không phải 0.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
3Theo mặc định, tài liệu mới kế thừa chế độ của tài liệu gốc. Tùy chọn này có thể được đặt thành a để cung cấp cho nó một chế độ khác.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
11Ngắt liên kết giữa hai tài liệu. Sau khi gọi điều này, các thay đổi sẽ không còn lan truyền giữa các tài liệu và nếu chúng có lịch sử dùng chung, thì lịch sử sẽ trở nên riêng biệt.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
12Sẽ gọi hàm đã cho cho tất cả các tài liệu được liên kết với tài liệu đích. Nó sẽ được truyền hai đối số, tài liệu được liên kết và một giá trị boolean cho biết liệu tài liệu đó có chia sẻ lịch sử với mục tiêu hay không

phương pháp liên quan đến lịch sử

require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
13Hoàn tác một chỉnh sửa (nếu có bất kỳ sự kiện hoàn tác nào được lưu trữ).
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
14Làm lại một chỉnh sửa đã hoàn tác.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
15Hoàn tác một chỉnh sửa hoặc thay đổi lựa chọn.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
16Làm lại một chỉnh sửa đã hoàn tác hoặc thay đổi lựa chọn.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
17Trả về một đối tượng có thuộc tính
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
18, cả hai đều chứa số nguyên, cho biết số lượng thao tác hoàn tác và làm lại được lưu trữ.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
19Xóa lịch sử hoàn tác của trình chỉnh sửa.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
20Nhận bản trình bày (có thể tuần tự hóa JSON) của lịch sử hoàn tác.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
21Thay thế lịch sử hoàn tác của người chỉnh sửa bằng lịch sử được cung cấp, lịch sử này phải là một giá trị được trả về bởi. Lưu ý rằng điều này sẽ có kết quả hoàn toàn không xác định nếu nội dung trình chỉnh sửa không giống như khi
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
22 được gọi

phương pháp đánh dấu văn bản

require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
24Có thể được sử dụng để đánh dấu một phạm vi văn bản bằng một tên lớp CSS cụ thể.
var myCodeMirror = CodeMirror(document.body);
45 và
var myCodeMirror = CodeMirror(document.body);
46 phải là đối tượng
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55. Tham số
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
48 là tùy chọn. Khi được cung cấp, nó phải là một đối tượng có thể chứa các tùy chọn cấu hình sau.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
29Gán một lớp CSS cho đoạn văn bản được đánh dấu.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
30Xác định xem văn bản được chèn ở bên trái của điểm đánh dấu sẽ nằm bên trong hay bên ngoài điểm đánh dấu.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
31Giống như
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
32, nhưng dành cho phía bên phải.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
33Đối với phạm vi nguyên tử, xác định xem con trỏ có được phép đặt trực tiếp bên trái của phạm vi hay không. Không có tác dụng đối với phạm vi phi nguyên tử.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
34Giống như
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
35, nhưng dành cho phía bên phải.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
36Dải nguyên tử hoạt động như một đơn vị duy nhất khi có liên quan đến chuyển động của con trỏ—i. e. không thể đặt con trỏ bên trong chúng. Bạn có thể kiểm soát xem con trỏ có được phép đặt trực tiếp trước hoặc sau chúng hay không bằng cách sử dụng
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
35 hoặc
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
38. Nếu không cung cấp
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
35 (hoặc quyền) thì
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
32 (hoặc quyền) sẽ kiểm soát hành vi này.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
41Collapsed ranges do not show up in the display. Đặt phạm vi thành thu gọn sẽ tự động biến phạm vi thành nguyên tử.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
42Khi được bật, sẽ khiến dấu tự xóa bất cứ khi nào con trỏ đi vào phạm vi của nó. Điều này chủ yếu hữu ích cho các tiện ích thay thế văn bản cần 'mở nhanh' khi người dùng cố gắng chỉnh sửa chúng. Sự kiện được kích hoạt trên bộ điều khiển phạm vi có thể được sử dụng để được thông báo khi điều này xảy ra.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
44Xác định xem dấu có tự động bị xóa khi nó trở nên trống không. Mặc định là đúng.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
45Sử dụng một nút nhất định để hiển thị phạm vi này. Ngụ ý cả sụp đổ và nguyên tử. Nút DOM đã cho phải là một phần tử nội tuyến (trái ngược với phần tử khối).
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
46Khi
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
47 được cung cấp, điều này xác định liệu trình chỉnh sửa có nắm bắt các sự kiện chuột và kéo xảy ra trong tiện ích con này hay không. Mặc định là sai—các sự kiện sẽ được để yên cho trình xử lý mặc định của trình duyệt hoặc các trình xử lý cụ thể trên tiện ích con nắm bắt.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
48Một khoảng thời gian chỉ đọc có thể, miễn là nó không bị xóa, không bị sửa đổi ngoại trừ bằng cách gọi để đặt lại toàn bộ tài liệu. Ghi chú. việc thêm một khoảng thời gian chỉ đọc hiện sẽ xóa lịch sử hoàn tác của trình chỉnh sửa, vì các sự kiện hoàn tác hiện tại bị vô hiệu hóa một phần bởi các khoảng thời gian chỉ đọc sẽ làm hỏng lịch sử (trong quá trình triển khai hiện tại).
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
50Khi được đặt thành đúng (mặc định là sai), việc thêm điểm đánh dấu này sẽ tạo một sự kiện trong lịch sử hoàn tác có thể được hoàn tác riêng lẻ (xóa điểm đánh dấu).
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
51Có thể được sử dụng để chỉ định một lớp CSS bổ sung sẽ được áp dụng cho khoảng ngoài cùng bên trái là một phần của điểm đánh dấu.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
52Tương đương với
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
53, nhưng đối với nhịp ngoài cùng bên phải.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
54Một chuỗi CSS sẽ được áp dụng cho văn bản được bao phủ. Ví dụ
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
55.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
56Khi được cung cấp, hãy thêm các thuộc tính trong đối tượng đã cho vào các thành phần được tạo cho văn bản được đánh dấu. Cách thêm thuộc tính
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
57 hoặc
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
58 không được hỗ trợ.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
59Khi tài liệu đích là các tài liệu khác, bạn có thể đặt
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
60 thành true để làm cho điểm đánh dấu xuất hiện trong tất cả các tài liệu. Theo mặc định, điểm đánh dấu chỉ xuất hiện trong tài liệu đích của nó. Phương thức sẽ trả về một đối tượng đại diện cho điểm đánh dấu (với hàm tạo
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
16), hiển thị ba phương thức.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
62, để xóa dấu,
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
63, trả về một đối tượng
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
64 (cả hai đều giữ vị trí tài liệu), cho biết vị trí hiện tại của phạm vi được đánh dấu, hoặc
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
65 nếu dấu không còn trong tài liệu và cuối cùng là
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
66, mà bạn có thể gọi .
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
68Chèn một dấu trang, một tay cầm theo sau văn bản xung quanh nó khi nó đang được chỉnh sửa, tại vị trí đã cho. Một dấu trang có hai phương pháp
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
69 và
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
22. Cái đầu tiên trả về vị trí hiện tại của dấu trang, nếu nó vẫn còn trong tài liệu và cái thứ hai xóa dấu trang một cách rõ ràng. Đối số tùy chọn là tùy chọn. Nếu được đưa ra, các thuộc tính sau được công nhận.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
71Có thể được sử dụng để hiển thị nút DOM tại vị trí hiện tại của dấu trang (tương tự như tùy chọn ).
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
74Theo mặc định, văn bản được nhập khi con trỏ ở trên cùng của dấu trang sẽ kết thúc ở bên phải của dấu trang. Thay vào đó, hãy đặt tùy chọn này thành true để làm cho tùy chọn này chuyển sang bên trái.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
59Xem phần tương ứng với
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
17.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
46Như với , điều này xác định xem các sự kiện chuột trên tiện ích được chèn cho dấu trang này có được CodeMirror xử lý hay không. Mặc định này sai.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
79Trả về một mảng gồm tất cả các dấu trang và phạm vi được đánh dấu được tìm thấy giữa các vị trí đã cho (không bao gồm).
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
80Trả về một mảng gồm tất cả các dấu trang và phạm vi được đánh dấu có ở vị trí đã cho.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
81Trả về một mảng chứa tất cả các phạm vi được đánh dấu trong tài liệu

Phương pháp widget, máng xối và trang trí

require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
82Đặt điểm đánh dấu máng xối cho máng xối đã cho (được xác định bởi lớp CSS của nó, xem tùy chọn) thành giá trị đã cho. Giá trị có thể là
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0, để xóa điểm đánh dấu hoặc phần tử DOM, để đặt. Phần tử DOM sẽ được hiển thị trong máng xối được chỉ định bên cạnh dòng được chỉ định.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
85Xóa tất cả các điểm đánh dấu máng xối trong bằng ID đã cho.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
86Đặt tên lớp CSS cho dòng đã cho.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
34 có thể là một số hoặc một dòng xử lý.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
88 xác định lớp này sẽ được áp dụng cho phần tử nào, có thể là một trong số
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
89 (phần tử văn bản, nằm phía trước vùng chọn),
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
90 (phần tử nền sẽ nằm phía sau vùng chọn),
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
91 (khoảng trống của dòng kẻ) .
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
57 nên là tên lớp đăng ký.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
94Xóa một lớp CSS khỏi một dòng.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
34 có thể là một dòng hoặc số.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
88 phải là một trong số
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
89,
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
90 hoặc
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
92 (xem phần ). Có thể bỏ đi
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
57 để xóa tất cả các lớp cho nút đã chỉ định hoặc là một chuỗi để chỉ xóa một lớp cụ thể.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
02Trả về số dòng, nội dung văn bản và trạng thái điểm đánh dấu của dòng đã cho, có thể là số hoặc điều khiển dòng. Đối tượng được trả về có cấu trúc
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
03, trong đó
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
04 là đối tượng ánh xạ ID máng xối tới các phần tử đánh dấu và
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
05 là một mảng được đính kèm với dòng này và các thuộc tính lớp khác nhau đề cập đến các lớp được thêm vào bằng.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
07Đặt
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
08, phải là nút DOM được định vị tuyệt đối, vào trình chỉnh sửa, được định vị ngay bên dưới vị trí
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55 đã cho. Khi
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
10 là đúng, trình chỉnh sửa sẽ đảm bảo rằng toàn bộ nút hiển thị (nếu có thể). Để xóa tiện ích một lần nữa, chỉ cần sử dụng các phương thức DOM (di chuyển tiện ích đó đến nơi khác hoặc gọi ____13_______11 trên cấp độ gốc của tiện ích đó).
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
12Thêm một tiện ích dòng, một phần tử được hiển thị bên dưới một dòng, kéo dài toàn bộ chiều rộng của trình chỉnh sửa và di chuyển các dòng bên dưới nó xuống dưới.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
34 phải là một số nguyên hoặc một dòng điều khiển và
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
08 phải là một nút DOM, nút này sẽ được hiển thị bên dưới dòng đã cho.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
48, khi được cung cấp, phải là một đối tượng định cấu hình hành vi của tiện ích con. Các tùy chọn sau được hỗ trợ (tất cả mặc định là sai).
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
16Liệu vật dụng có nên che máng xối hay không.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
17Whether the widget should stay fixed in the face of horizontal scrolling.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
18Làm cho tiện ích được đặt bên trên thay vì bên dưới văn bản của dòng.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
46Xác định xem trình chỉnh sửa có nắm bắt các sự kiện chuột và kéo xảy ra trong tiện ích con này hay không. Mặc định là sai—các sự kiện sẽ được để yên cho trình xử lý mặc định của trình duyệt hoặc các trình xử lý cụ thể trên tiện ích con nắm bắt.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
20Theo mặc định, tiện ích được thêm bên dưới các tiện ích khác cho dòng. Tùy chọn này có thể được sử dụng để đặt nó ở một vị trí khác (số 0 ở trên cùng, N để đặt nó sau tiện ích khác thứ N). Lưu ý rằng điều này chỉ có hiệu lực một lần, khi tiện ích được tạo.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
29Thêm tên lớp CSS bổ sung vào phần tử trình bao bọc được tạo cho tiện ích con. Lưu ý rằng nút widget sẽ trở thành hậu duệ của các nút có các lớp CSS dành riêng cho CodeMirror và các lớp đó trong một số trường hợp có thể ảnh hưởng đến nó. Phương thức này trả về một đối tượng đại diện cho vị trí widget. Nó sẽ có một thuộc tính
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
34 chỉ vào dòng xử lý mà nó được liên kết và các phương thức sau.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
62Xóa tiện ích.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
66Gọi điều này nếu bạn thực hiện một số thay đổi đối với nút DOM của tiện ích có thể ảnh hưởng đến chiều cao của tiện ích. Nó sẽ buộc CodeMirror cập nhật chiều cao của dòng chứa tiện ích

Phương pháp định cỡ, cuộn và định vị

require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
25Đặt kích thước của trình chỉnh sửa theo chương trình (ghi đè kích thước hiện hành).
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
5 và
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
15 có thể là số (được hiểu là pixel) hoặc đơn vị CSS (ví dụ: ______13_______28). Bạn có thể chuyển
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0 cho một trong hai người để chỉ ra rằng không nên thay đổi thứ nguyên đó.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
30Cuộn trình chỉnh sửa đến một vị trí (pixel) nhất định. Cả hai đối số có thể được để lại là
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0 hoặc
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
65 để không có hiệu lực.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
33Nhận một đối tượng
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
34 đại diện cho vị trí cuộn hiện tại, kích thước của vùng có thể cuộn và kích thước của vùng hiển thị (trừ các thanh cuộn).
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
35Cuộn vị trí đã cho vào chế độ xem.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
36 có thể là
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0 để cuộn con trỏ vào chế độ xem, vị trí
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55 để cuộn một ký tự vào chế độ xem, phạm vi pixel
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
39 (trong tọa độ cục bộ của trình chỉnh sửa) hoặc phạm vi
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
64 chứa hai vị trí ký tự hoặc hai ô vuông pixel. Tham số
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
41 là tùy chọn. Khi được cung cấp, nó cho biết số lượng pixel dọc xung quanh khu vực nhất định cũng sẽ được hiển thị.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
42Trả về một đối tượng
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
43 chứa tọa độ của vị trí con trỏ. Nếu
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
84 là
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
45, chúng sẽ tương ứng với góc trên cùng bên trái của tài liệu có thể chỉnh sửa. Nếu nó là
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
68 hoặc không được cung cấp, chúng có liên quan đến góc trên cùng bên trái của trang. Nếu
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
84 là
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
48, thì tọa độ có liên quan đến góc trên cùng bên trái của cửa sổ (cuộn) hiện đang hiển thị.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
88 có thể là một giá trị boolean cho biết bạn muốn bắt đầu (
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
3) hay kết thúc (
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
2) của lựa chọn, hoặc, nếu một đối tượng
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55 được đưa ra, nó chỉ định vị trí chính xác mà bạn muốn đo.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
53Trả về vị trí và kích thước của một ký tự tùy ý.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
54 phải là một đối tượng
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55. Điều này khác với
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
56 ở chỗ nó sẽ cung cấp kích thước của toàn bộ ký tự, thay vì chỉ vị trí mà con trỏ sẽ có khi nó ngồi ở vị trí đó.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
57Cho một đối tượng
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
58 (e. g. tọa độ của một sự kiện chuột) trả về vị trí
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55 tương ứng với nó. Tham số
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
84 tùy chọn xác định liên quan đến tọa độ được diễn giải. Nó có thể là
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
48,
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
68 (mặc định) hoặc
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
45.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
64Tính toán dòng ở chiều cao pixel đã cho.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
84 có thể là một trong các chuỗi giống nhau chấp nhận.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
67Tính toán chiều cao của đỉnh một đường, trong hệ tọa độ được chỉ định bởi
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
84 (xem ), mặc định là
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
68. Khi một dòng bên dưới cuối tài liệu được chỉ định, giá trị được trả về là cuối dòng cuối cùng trong tài liệu. Theo mặc định, vị trí của văn bản thực được trả về. Nếu `includeWidgets` là đúng và dòng có tiện ích dòng, vị trí phía trên tiện ích dòng đầu tiên được trả về.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
71Trả về chiều cao dòng của phông chữ mặc định cho trình chỉnh sửa.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
72Trả về chiều rộng pixel của 'x' trong phông chữ mặc định cho trình chỉnh sửa. (Lưu ý rằng đối với các phông chữ không phải là đơn cách, điều này hầu như vô dụng và ngay cả đối với các phông chữ đơn cách, các ký tự không phải ascii có thể có chiều rộng khác).
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
73Returns a
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
64 object indicating the start (inclusive) and end (exclusive) of the currently rendered part of the document. Trong các tài liệu lớn, khi hầu hết nội dung được cuộn ra khỏi chế độ xem, CodeMirror sẽ chỉ hiển thị phần hiển thị và lề xung quanh nó. See also the event.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
76If your code does something to change the size of the editor element (window resizes are already listened for), or unhides it, you should probably follow up by calling this method to ensure CodeMirror is still looking as intended. See also the

When writing language-aware functionality, it can often be useful to hook into the knowledge that the CodeMirror language mode has. See for a more detailed description of how these work

require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
77Gets the (outer) mode object for the editor. Note that this is distinct from
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
78, which gives you the mode specification, rather than the resolved, instantiated .
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
79Gets the inner mode at a given position. This will return the same as for simple modes, but will return an inner mode for nesting modes (such as
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
81).
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
82Retrieves information about the token the current mode found before the given position (a
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55 object). The returned object has the following properties.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
84The character (on the given line) at which the token starts.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
85Ký tự kết thúc mã thông báo.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
86The token's string.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
87The token type the mode assigned to the token, such as
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
88 or
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
89 (may also be null).
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
90The mode's state at the end of this token. If
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
91 is true, the token will be guaranteed to be accurate based on recent edits. If false or not specified, the token will use cached state information, which will be faster but might not be accurate if edits were recently made and highlighting has not yet completed.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
92This is similar to , but collects all tokens for a given line into an array. It is much cheaper than repeatedly calling
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
93, which re-parses the part of the line before the token for every call.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
95This is a (much) cheaper version of useful for when you just need the type of the token at a given position, and no other information. Will return
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0 for unstyled tokens, and a string, potentially containing multiple space-separated style names, otherwise.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
98Fetch the set of applicable helper values for the given position. Helpers provide a way to look up functionality appropriate for a mode. The
var myCodeMirror = CodeMirror(document.body);
11 argument provides the helper namespace (see ), in which the values will be looked up. When the mode itself has a property that corresponds to the
var myCodeMirror = CodeMirror(document.body);
11, that directly determines the keys that are used to look up the helper values (it may be either a single string, or an array of strings). Failing that, the mode's
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
02 property and finally the mode's name are used. For example, the JavaScript mode has a property
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
03 containing
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
04. When the
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
05 addon is loaded, that defines a helper named
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
06 in the
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
03 namespace. This is then used by the addon to figure out that it can use that folding function to fold JavaScript code. When any helpers are defined for the given namespace, their predicates are called on the current mode and editor, and all those that declare they are applicable will also be added to the array that is returned.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
09Returns the first applicable helper value. See .
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
11Returns the mode's parser state, if any, at the end of the given line number. If no line number is given, the state at the end of the document is returned. This can be useful for storing parsing errors in the state, or getting other kinds of contextual information for a line.
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
91 is defined as in
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
13

Miscellaneous methods

editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
14CodeMirror internally buffers changes and only updates its DOM structure after it has finished performing some operation. If you need to perform a lot of operations on a CodeMirror instance, you can call this method with a function argument. It will call the function, buffering up all changes, and only doing the expensive update after the function returns. This can be a lot faster. The return value from this method will be the return value of your function.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
15
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
16In normal circumstances, use the above
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
17 method. But if you want to buffer operations happening asynchronously, or that can't all be wrapped in a callback function, you can call
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
18 to tell CodeMirror to start buffering changes, and
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
19 to actually render all the updates. Be careful. if you use this API and forget to call
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
19, the editor will just never update.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
21Adjust the indentation of the given line. The second argument (which defaults to
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
22) may be one of.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
23Base indentation on the indentation of the previous line.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
24Use the mode's smart indentation if available, behave like
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
25 otherwise.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
26Increase the indentation of the line by one .
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
27Reduce the indentation of the line.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
28Add (positive number) or reduce (negative number) the indentation by the given amount of spaces.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
29Switches between overwrite and normal insert mode (when not given an argument), or sets the overwrite mode to a specific state (when given an argument).
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
30Tells you whether the editor's content can be edited by the user.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
31Returns the preferred line separator string for this document, as per the by the same name. When that option is
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0, the string
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
52 is returned.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
34Runs the with the given name on the editor.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
35Calculates and returns a
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55 object for a zero-based
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
37 who's value is relative to the start of the editor's text. If the
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
37 is out of range of the text then the returned object is clipped to start or end of the text respectively.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
39The reverse of .
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
41Give the editor focus.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
42Allow the given string to be translated with the .
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
44Returns the input field for the editor. Will be a textarea or an editable div, depending on the value of the option.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
46Returns the DOM node that represents the editor, and controls its size. Remove this from your tree to delete an editor instance.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
47Returns the DOM node that is responsible for the scrolling of the editor.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
48Fetches the DOM node that contains the editor gutters

Static properties

The

var myCodeMirror = CodeMirror(document.body);
1 object itself provides several useful properties

editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
50It contains a string that indicates the version of the library. This is a triple of integers
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
51, where
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
52 is zero for releases, and something else (usually one) for dev snapshots.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
53This method provides another way to initialize an editor. It takes a textarea DOM node as first argument and an optional configuration object as second. It will replace the textarea with a CodeMirror instance, and wire up the form of that textarea (if any) to make sure the editor contents are put into the textarea when the form is submitted. The text in the textarea will provide the content for the editor. A CodeMirror instance created this way has three additional methods.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
54Copy the content of the editor into the textarea.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
55Remove the editor, and restore the original textarea (with the editor's current content). If you dynamically create and destroy editors made with `fromTextArea`, without destroying the form they are part of, you should make sure to call `toTextArea` to remove the editor, or its `"submit"` handler on the form will cause a memory leak.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
56Returns the textarea that the instance was based on.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
57An object containing default values for all . You can assign to its properties to modify defaults (though this won't affect editors that have already been created).
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
58If you want to define extra methods in terms of the CodeMirror API, it is possible to use
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
59. This will cause the given value (usually a method) to be added to all CodeMirror instances created from then on.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
60Like , but the method will be added to the interface for objects instead.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
63Similarly,
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
64 can be used to define new options for CodeMirror. The
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
65 will be called with the editor instance and the new value when an editor is initialized, and whenever the option is modified through .
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
67If your extension just needs to run some code whenever a CodeMirror instance is initialized, use
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
68. Give it a function as its only argument, and from then on, that function will be called (with the instance as argument) whenever a new CodeMirror instance is initialized.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
69Registers a helper value with the given
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
5 in the given namespace (
var myCodeMirror = CodeMirror(document.body);
11). This is used to define functionality that may be looked up by mode. Will create (if it doesn't already exist) a property on the
var myCodeMirror = CodeMirror(document.body);
1 object for the given
var myCodeMirror = CodeMirror(document.body);
11, pointing to an object that maps names to values. I. e. after doing
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
74, the value
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
75 will point to
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
76.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
77Acts like , but also registers this helper as 'global', meaning that it will be included by whenever the given
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
80 returns true when called with the local mode and editor.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
81A constructor for the objects that are used to represent positions in editor documents.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
38 defaults to null, but can be set to
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
39 or
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
40 to make the position explicitly associate with the character before or after it.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
85Utility function that computes an end position from a change (an object with
var myCodeMirror = CodeMirror(document.body);
45,
var myCodeMirror = CodeMirror(document.body);
46, and
var myCodeMirror = CodeMirror(document.body);
48 properties, as passed to various ). The returned position will be the end of the changed range, after the change is applied.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
89Find the column position at a given string index using a given tabsize

Addons

The

editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
90 directory in the distribution contains a number of reusable components that implement extra editor functionality (on top of extension functions like , , and ). In brief, they are

editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
94Cung cấp một cách rất đơn giản để truy vấn người dùng để nhập văn bản. Thêm phương thức
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
95 vào các phiên bản CodeMirror, phương thức này có thể được gọi bằng một đoạn HTML hoặc nút DOM tách rời cung cấp lời nhắc (nên bao gồm thẻ
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
96 hoặc
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
97) và chức năng gọi lại được gọi khi người dùng nhấn enter. Nó trả về một hàm
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
98, nếu được gọi, nó sẽ đóng hộp thoại ngay lập tức.
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
99 có các tùy chọn sau. mode/00Nếu đúng, hộp thoại sẽ đóng khi người dùng nhấn enter trong mục nhập. Mặc định là
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
3. ________1035 _______02 Xác định xem hộp thoại có bị đóng khi mất tiêu điểm hay không. Mặc định là
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
3. mode/04Một trình xử lý sự kiện sẽ được gọi bất cứ khi nào
var myCodeMirror = CodeMirror(document.body);
70 kích hoạt đầu vào của hộp thoại. Nếu cuộc gọi lại của bạn trả về
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
3, hộp thoại sẽ không thực hiện thêm bất kỳ quá trình xử lý sự kiện nào. mode/07Tương tự như mode/08 nhưng đối với sự kiện mode/09. mode/10Tương tự như mode/08 nhưng đối với sự kiện
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
96. mode/13. Một cuộc gọi lại sẽ được gọi sau khi hộp thoại đã được đóng và xóa khỏi DOM. No return value

Also adds an mode/14 function that simply shows an HTML fragment as a notification at the top of the editor. It takes a single option. mode/15, the amount of time after which the notification will be automatically closed. If mode/15 is zero, the dialog will not be closed automatically

Depends on mode/17

mode/18Adds the mode/19 method to CodeMirror instances, which can be used to implement search/replace functionality. mode/20 can be a regular expression or a string.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
78 provides the starting position of the search. It can be a
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55 object, or can be left off to default to the start of the document.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
48 is an optional object, which can contain the property `caseFold. false` to disable case folding when matching a string, or the property `multiline. disable` to disable multi-line matching for regular expressions (which may help performance). A search cursor has the following methods. mode/24mode/25Search forward or backward from the current position. Giá trị trả về cho biết liệu có tìm thấy kết quả khớp hay không. If matching a regular expression, the return value will be the array returned by the mode/26 method, in case you want to extract matched groups. mode/27mode/28These are only valid when the last call to mode/29 or mode/30 did not return false. They will return
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55 objects pointing at the start and end of the match. mode/32Replaces the currently found match with the given text and adjusts the cursor position to reflect the replacement. mode/33Implements the search commands. CodeMirror has keys bound to these by default, but will not do anything with them unless an implementation is provided. Depends on mode/34, and will make use of when available to make prompting for search queries less ugly. mode/36Implements a mode/37 command and binding mode/38 to it. Accepts mode/39, mode/40, mode/41, mode/42 and mode/43 formats. This will make use of when available to make prompting for line number neater. Demo available here. mode/45Adds a mode/46 method to editor instances, which should be given a query (string or regular expression), optionally a case-fold flag (only applicable for strings), and optionally a class name (defaults to mode/47) as arguments. When called, matches of the given query will be displayed on the editor's vertical scrollbar. The method returns an object with a mode/48 method that can be called to remove the matches. Depends on the addon, and the mode/50 file provides a default (transparent yellowish) definition of the CSS class applied to the matches. Note that the matches are only perfectly aligned if your scrollbar does not have buttons at the top and bottom. You can use the addon to make sure of this. If this addon is loaded, the addon will automatically use it. mode/53Defines an option mode/54 which, when set to true or an options object, causes matching brackets to be highlighted whenever the cursor is next to them. It also adds a method mode/54 that forces this to happen once, and a method mode/56 that can be used to run the bracket-finding algorithm that this uses internally. It takes a start position and an optional config object. By default, it will find the match to a matchable character either before or after the cursor (preferring the one before), but you can control its behavior with these options. mode/57Only use the character after the start position, never the one before it. mode/58Also highlight pairs of non-matching as well as stray brackets. Enabled by default. mode/59Causes only matches where both brackets are at the same side of the start position to be considered. mode/60Stop after scanning this amount of lines without a successful match. Defaults to 1000. mode/61Ignore lines longer than this. Defaults to 10000. mode/62Don't highlight a bracket in a line longer than this. Defaults to 1000. mode/63Defines an option mode/64 that will auto-close brackets and quotes when typed. By default, it'll auto-close mode/65, but you can pass it a string similar to that (containing pairs of matching characters), or an object with mode/66 and optionally mode/67 properties to customize it. mode/67 should be a similar string that gives the pairs of characters that, when enter is pressed between them, should have the second character also moved to its own line. By default, if the active mode has a mode/69 property, that overrides the configuration given in the option. But you can add an mode/70 property with a truthy value to override mode-specific configuration. Demo here. mode/71Defines an option mode/72 that, when enabled, will cause the tags around the cursor to be highlighted (using the mode/73 class). Also defines a mode/74, which you can bind a key to in order to jump to the tag matching the one under the cursor. Depends on the mode/75 addon. Demo here. mode/76Adds an option mode/77 which, when enabled, adds the CSS class mode/78 to stretches of whitespace at the end of lines. The demo has a nice squiggly underline style for this class. mode/79Defines an mode/80 option that will auto-close XML tags when 'mode/81' or 'mode/82' is typed, and a mode/83 that closes the nearest open tag. Depends on the mode/84 addon. See the demo. mode/85Markdown specific. Defines a mode/86 that can be bound to mode/87 to automatically insert the leading characters for continuing a list. See the Markdown mode demo. mode/88Addon for commenting and uncommenting code. Adds four methods to CodeMirror instances. mode/89Tries to uncomment the current selection, and if that fails, line-comments it. mode/90Set the lines in the given range to be line comments. Will fall back to mode/91 when no line comment style is defined for the mode. mode/92Wrap the code in the given range in a block comment. Will fall back to mode/93 when no block comment style is defined for the mode. mode/94Try to uncomment the given range. Returns
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
3 if a comment range was found and removed,
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
2 otherwise. Đối tượng
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
48 được các phương thức này chấp nhận có thể có các thuộc tính sau. mode/98Override the of the mode with custom comment strings. mode/99A string that will be inserted after opening and leading markers, and before closing comment markers. Defaults to a single space. lib/00Whether, when adding line comments, to also comment lines that contain only whitespace. lib/01When adding line comments and this is turned on, it will align the comment block to the current indentation of the first line of the block. lib/02When block commenting, this controls whether the whole lines are indented, or only the precise range that is given. Defaults to
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
3. The addon also defines a lib/04 , which is a shorthand command for calling lib/04 with no options. lib/06Helps with code folding. Adds a lib/07 method to editor instances, which will try to do a code fold starting at the given line, or unfold the fold that is already present. The method takes as first argument the position that should be folded (may be a line number or a ), and as second optional argument either a range-finder function, or an options object, supporting the following properties. lib/09The function that is used to find foldable ranges. If this is not directly passed, it will default to lib/10, which uses with a lib/12 type to find folding functions appropriate for the local mode. There are files in the lib/13 directory providing lib/14, which finds blocks in brace languages (JavaScript, C, Java, etc), lib/15, for languages where indentation determines block structure (Python, Haskell), and lib/16, for XML-style languages, and lib/17, for folding comment blocks. lib/18The widget to show for folded ranges. Can be either a string, in which case it'll become a span with class lib/19, or a DOM node. To dynamically generate the widget, this can be a function that returns a string or DOM node, which will then render as described. The function will be invoked with parameters identifying the range to be folded. lib/20When true (default is false), the addon will try to find foldable ranges on the lines above the current one if there isn't an eligible one on the given line. lib/21The minimum amount of lines that a fold should span to be accepted. Defaults to 0, which also allows single-line folds. See the demo for an example. lib/22Provides an option lib/23, which can be used to create a gutter with markers indicating the blocks that can be folded. Create a gutter using the option, giving it the class lib/25 or something else if you configure the addon to use a different class, and this addon will show markers next to folded and foldable blocks, and handle clicks in this gutter. Note that CSS styles should be applied to make the gutter, and the fold markers within it, visible. A default set of CSS styles are available in. lib/26 . The option can be either set to
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
3, or an object containing the following optional option fields. lib/28The CSS class of the gutter. Defaults to lib/29. You will have to style this yourself to give it a width (and possibly a background). See the default gutter style rules above. lib/30Một lớp CSS hoặc phần tử DOM được sử dụng làm điểm đánh dấu cho các khối mở, có thể gập lại. Defaults to lib/31. lib/32A CSS class or DOM element to be used as the marker for folded blocks. Defaults to lib/33. lib/09Chức năng tìm phạm vi sử dụng khi xác định xem một thứ gì đó có thể được gấp lại hay không. When not given, will be used as default. The lib/36 editor option can be set to an object to provide an editor-wide default configuration. Demo here. lib/37Can be used to run a CodeMirror mode over text without actually opening an editor instance. See the demo for an example. There are alternate versions of the file available for running stand-alone (without including all of CodeMirror) and for running under node. js (see lib/38 for an example of using the latter). lib/39Provides a convenient way to syntax-highlight code snippets in a webpage. Depends on the addon (or its standalone variant). Cung cấp một hàm lib/41 có thể được gọi với một mảng (hoặc bộ sưu tập mảng-ish khác) của các nút DOM đại diện cho các đoạn mã. Theo mặc định, nó sẽ nhận tất cả các thẻ
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
31. Will read the lib/43 attribute of these nodes to figure out their language, and syntax-color their content using the relevant CodeMirror mode (you'll have to load the scripts for the relevant modes yourself). A second argument may be provided to give a default mode, used when no language attribute is found for a node. Used in this manual to highlight example code. lib/44Mode combinator that can be used to extend a mode with an 'overlay' — a secondary mode is run over the stream, along with the base mode, and can color specific pieces of text without interfering with the base mode. Defines lib/45, which is used to create such a mode. See this demo for a detailed example. lib/46Mode combinator that can be used to easily 'multiplex' between several modes. Defines lib/47 which, when given as first argument a mode object, and as other arguments any number of lib/48 objects, will return a mode object that starts parsing using the mode passed as first argument, but will switch to another mode as soon as it encounters a string that occurs in one of the lib/49 fields of the passed objects. When in a sub-mode, it will go back to the top mode again when the lib/50 string is encountered. Pass
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
52 for lib/49 or lib/50 if you want to switch on a blank line
  • Khi lib/54 được chỉ định, nó sẽ là kiểu mã thông báo được trả về cho mã thông báo dấu phân cách (cũng như lib/55 trên mã thông báo mở và lib/56 trên mã thông báo đóng)
  • When lib/57 is specified, it will be the token style added for each inner mode token
  • When lib/58 is true, the content of the delimiters will also be passed to the inner mode. (And lib/54 is ignored. )
The outer mode will not see the content between the delimiters. See this demo for an example. lib/60Provides a framework for showing autocompletion hints. Defines lib/61, which takes an optional options object, and pops up a widget that allows the user to select a completion. Finding hints is done with a hinting function (the lib/62 option). This function takes an editor instance and an options object, and returns a lib/63 object, where lib/64 is an array of strings or objects (the completions), and
var myCodeMirror = CodeMirror(document.body);
45 and
var myCodeMirror = CodeMirror(document.body);
46 give the start and end of the token that is being completed as
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55 objects. An optional lib/68 property (an integer) can be added to the completion object to control the initially selected hint. If no hinting function is given, the addon will use lib/69, which calls with the lib/71 type to find applicable hinting functions, and tries them one by one. If that fails, it looks for a lib/72 helper to fetch a list of completeable words for the mode, and uses lib/73 to complete from those. When completions aren't simple strings, they should be objects with the following properties. lib/74The completion text. This is the only required property. lib/75The text that should be displayed in the menu.
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
29A CSS class name to apply to the completion's line in the menu. lib/77A method used to create the DOM structure for showing the completion by appending it to its first argument. lib/78A method used to actually apply the completion, instead of the default behavior. lib/79Optional
var myCodeMirror = CodeMirror(document.body);
45 position that will be used by lib/81 instead of the global one passed with the full list of completions. lib/82Optional
var myCodeMirror = CodeMirror(document.body);
46 position that will be used by lib/81 instead of the global one passed with the full list of completions. The plugin understands the following options, which may be either passed directly in the argument to lib/85, or provided by setting an lib/86 editor option to an object (the former takes precedence). The options object will also be passed along to the hinting function, which may understand additional options. lib/87A hinting function, as specified above. It is possible to set the lib/88 property on a hinting function to true, in which case it will be called with arguments lib/89, and the completion interface will only be popped up when the hinting function calls the callback, passing it the object holding the completions. The hinting function can also return a promise, and the completion interface will only be popped when the promise resolves. By default, hinting only works when there is no selection. You can give a hinting function a lib/90 property with a truthy value to indicate that it supports selections. lib/91Determines whether, when only a single completion is available, it is completed without showing the dialog. Defaults to true. lib/92Whether the pop-up should be horizontally aligned with the start of the word (true, default), or with the cursor (false). lib/93A regular expression object used to match characters which cause the pop up to be closed (default. lib/94). If the user types one of these characters, the pop up will close, and the lib/95 event is fired on the editor instance. lib/96When enabled (which is the default), the pop-up will close when the editor is unfocused. lib/97Whether a single click on a list item suffices to trigger the completion (which is the default), or if the user has to use a doubleclick. lib/98Can be used to define a custom container for the widget. The default is
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0, in which case the
var myCodeMirror = CodeMirror(document.body);
000-element will be used.
var myCodeMirror = CodeMirror(document.body);
001Allows you to provide a custom key map of keys to be active when the pop-up is active. The handlers will be called with an extra argument, a handle to the completion menu, which has
var myCodeMirror = CodeMirror(document.body);
002,
var myCodeMirror = CodeMirror(document.body);
003, lib/81, and
var myCodeMirror = CodeMirror(document.body);
005 methods (see the source for details), that can be used to change the focused element, pick the current element or close the menu. Additionally
var myCodeMirror = CodeMirror(document.body);
006 can give you access to the size of the current dropdown menu,
var myCodeMirror = CodeMirror(document.body);
007 give you the number of available completions, and
var myCodeMirror = CodeMirror(document.body);
008 give you full access to the completion returned by the hinting function.
var myCodeMirror = CodeMirror(document.body);
009Like
var myCodeMirror = CodeMirror(document.body);
010 above, but the bindings will be added to the set of default bindings, instead of replacing them.
var myCodeMirror = CodeMirror(document.body);
011Show this many lines before and after the selected item. Default is 0. The following events will be fired on the completions object during completion.
var myCodeMirror = CodeMirror(document.body);
012Fired when the pop-up is shown.
var myCodeMirror = CodeMirror(document.body);
013Fired when a completion is selected. Passed the completion value (string or object) and the DOM node that represents it in the menu.
var myCodeMirror = CodeMirror(document.body);
014Fired when a completion is picked. Passed the completion value (string or object).
var myCodeMirror = CodeMirror(document.body);
015Fired when the completion is finished. The following events will be fired on the editor instance during completion.
var myCodeMirror = CodeMirror(document.body);
016Fired when the pop-up is being closed programmatically, e. g. , when the user types a character which matches the
var myCodeMirror = CodeMirror(document.body);
017 option. This addon depends on styles from
var myCodeMirror = CodeMirror(document.body);
018. Check out the demo for an example.
var myCodeMirror = CodeMirror(document.body);
019Defines a simple hinting function for JavaScript (
var myCodeMirror = CodeMirror(document.body);
020) and CoffeeScript (
var myCodeMirror = CodeMirror(document.body);
021) code. This will simply use the JavaScript environment that the editor runs in as a source of information about objects and their properties.
var myCodeMirror = CodeMirror(document.body);
022Defines
var myCodeMirror = CodeMirror(document.body);
023, which produces hints for XML tagnames, attribute names, and attribute values, guided by a
var myCodeMirror = CodeMirror(document.body);
024 option (a property of the second argument passed to the hinting function, or the third argument passed to
var myCodeMirror = CodeMirror(document.body);
025)
The schema info should be an object mapping tag names to information about these tags, with optionally a
var myCodeMirror = CodeMirror(document.body);
026 property containing a list of the names of valid top-level tags. The values of the properties should be objects with optional properties
var myCodeMirror = CodeMirror(document.body);
027 (an array of valid child element names, omit to simply allow all tags to appear) and
var myCodeMirror = CodeMirror(document.body);
028 (an object mapping attribute names to
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0 for free-form attributes, and an array of valid values for restricted attributes)
The hint options accept an additional property.
var myCodeMirror = CodeMirror(document.body);
030Determines whether typed characters are matched anywhere in completions, not just at the beginning. Defaults to false. Demo here.
var myCodeMirror = CodeMirror(document.body);
031Provides schema info to the addon for HTML documents. Defines a schema object
var myCodeMirror = CodeMirror(document.body);
032 that you can pass to as a
var myCodeMirror = CodeMirror(document.body);
024 option, and a
var myCodeMirror = CodeMirror(document.body);
034 hinting function that automatically calls
var myCodeMirror = CodeMirror(document.body);
023 with this schema data. See the demo.
var myCodeMirror = CodeMirror(document.body);
036A hinting function for CSS, SCSS, or LESS code. Defines
var myCodeMirror = CodeMirror(document.body);
037.
var myCodeMirror = CodeMirror(document.body);
038A very simple hinting function (
var myCodeMirror = CodeMirror(document.body);
039) that simply looks for words in the nearby code and completes to those. Takes two optional options,
var myCodeMirror = CodeMirror(document.body);
040, a regular expression that matches words (sequences of one or more character), and
var myCodeMirror = CodeMirror(document.body);
041, which defines how many lines the addon should scan when completing (defaults to 500).
var myCodeMirror = CodeMirror(document.body);
042A simple SQL hinter. Defines
var myCodeMirror = CodeMirror(document.body);
043. Takes two optional options,
var myCodeMirror = CodeMirror(document.body);
044, a object with table names as keys and array of respective column names as values, and
var myCodeMirror = CodeMirror(document.body);
045, a string corresponding to a table name in
var myCodeMirror = CodeMirror(document.body);
044 for autocompletion.
var myCodeMirror = CodeMirror(document.body);
047Adds a
var myCodeMirror = CodeMirror(document.body);
048 option that can be enabled to highlight all instances of a currently selected word. Can be set either to true or to an object containing the following options.
var myCodeMirror = CodeMirror(document.body);
049, for the minimum amount of selected characters that triggers a highlight (default 2),
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
58, for the style to be used to highlight the matches (default
var myCodeMirror = CodeMirror(document.body);
051, which will correspond to CSS class
var myCodeMirror = CodeMirror(document.body);
052),
var myCodeMirror = CodeMirror(document.body);
053, which controls whether whitespace is trimmed from the selection, and
var myCodeMirror = CodeMirror(document.body);
054 which can be set to
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
3 or to a regexp matching the characters that make up a word. When enabled, it causes the current word to be highlighted when nothing is selected (defaults to off). Demo here.
var myCodeMirror = CodeMirror(document.body);
056Defines an interface component for showing linting warnings, with pluggable warning sources (see
var myCodeMirror = CodeMirror(document.body);
057,
var myCodeMirror = CodeMirror(document.body);
058,
var myCodeMirror = CodeMirror(document.body);
059,
var myCodeMirror = CodeMirror(document.body);
060, and
var myCodeMirror = CodeMirror(document.body);
061 in the same directory). Defines a
var myCodeMirror = CodeMirror(document.body);
062 option that can be set to an annotation source (for example
var myCodeMirror = CodeMirror(document.body);
063), to an options object (in which case the
var myCodeMirror = CodeMirror(document.body);
064 field is used as annotation source), or simply to
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
3. When no annotation source is specified, with type
var myCodeMirror = CodeMirror(document.body);
067 is used to find an annotation function. An annotation source function should, when given a document string, an options object, and an editor instance, return an array of
var myCodeMirror = CodeMirror(document.body);
068 objects representing problems. When the function has an lib/88 property with a truthy value, it will be called with an additional second argument, which is a callback to pass the array to. The linting function can also return a promise, in that case the linter will only be executed when the promise resolves. By default, the linter will run (debounced) whenever the document is changed. You can pass a
var myCodeMirror = CodeMirror(document.body);
070 option to disable that. You can pass a
var myCodeMirror = CodeMirror(document.body);
071 option to render the tooltip inside the editor instance. And a
var myCodeMirror = CodeMirror(document.body);
072 option to add a style to lines that contain problems. Depends on
var myCodeMirror = CodeMirror(document.body);
073. A demo can be found here.
var myCodeMirror = CodeMirror(document.body);
074Causes the selected text to be marked with the CSS class
var myCodeMirror = CodeMirror(document.body);
075 when the
var myCodeMirror = CodeMirror(document.body);
076 option is enabled. Useful to change the colour of the selection (in addition to the background), like in this demo.
var myCodeMirror = CodeMirror(document.body);
077Defines a
var myCodeMirror = CodeMirror(document.body);
078 option that, when enabled, gives the wrapper of the line that contains the cursor the class
var myCodeMirror = CodeMirror(document.body);
079, adds a background with the class
var myCodeMirror = CodeMirror(document.body);
080, and adds the class
var myCodeMirror = CodeMirror(document.body);
081 to the line's gutter space is enabled. The option's value may be a boolean or an object specifying the following options.
var myCodeMirror = CodeMirror(document.body);
082Controls whether single-line selections, or just cursor selections, are styled. Defaults to false (only cursor selections). Xem bản trình diễn.
var myCodeMirror = CodeMirror(document.body);
083Defines a
var myCodeMirror = CodeMirror(document.body);
084 option which you can use to control the mouse cursor appearance when hovering over the selection. It can be set to a string, like
var myCodeMirror = CodeMirror(document.body);
085, or to true, in which case the
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
5 (arrow) cursor will be used. You can see a demo here.
var myCodeMirror = CodeMirror(document.body);
087Xác định hàm
var myCodeMirror = CodeMirror(document.body);
088 sẽ cố tải một chế độ nhất định và gọi hàm gọi lại khi nó thành công.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
48 is an optional object that may contain.
var myCodeMirror = CodeMirror(document.body);
090Defines the way mode names are mapped to paths.
var myCodeMirror = CodeMirror(document.body);
091Override the way the mode script is loaded. By default, this will use the CommonJS or AMD module loader if one is present, and fall back to creating a
var myCodeMirror = CodeMirror(document.body);
092 tag otherwise. This addon also defines
var myCodeMirror = CodeMirror(document.body);
093, which will ensure the given mode is loaded and cause the given editor instance to refresh its mode when the loading succeeded. See the demo.
var myCodeMirror = CodeMirror(document.body);
094Provides meta-information about all the modes in the distribution in a single file. Defines
var myCodeMirror = CodeMirror(document.body);
095, an array of objects with
var myCodeMirror = CodeMirror(document.body);
096 properties, where
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
5 is the human-readable name,
var myCodeMirror = CodeMirror(document.body);
098 the MIME type, and
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
84 the name of the mode file that defines this MIME. There are optional properties
var myCodeMirror = CodeMirror(document.body);
100, which holds an array of MIME types for modes with multiple MIMEs associated, and
var myCodeMirror = CodeMirror(document.body);
101, which holds an array of file extensions associated with this mode. Four convenience functions,
var myCodeMirror = CodeMirror(document.body);
102,
var myCodeMirror = CodeMirror(document.body);
103,
var myCodeMirror = CodeMirror(document.body);
104 and
var myCodeMirror = CodeMirror(document.body);
105 are provided, which return such an object given a MIME, extension, file name or mode name string. Note that, for historical reasons, this file resides in the top-level
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
84 directory, not under
editor.setOption("extraKeys", {
  Tab: function(cm) {
    var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
    cm.replaceSelection(spaces);
  }
});
90. Demo.
var myCodeMirror = CodeMirror(document.body);
108Adds a
var myCodeMirror = CodeMirror(document.body);
109 option, which sets whether the editor will make the next line continue a comment when you press Enter inside a comment block. Can be set to a boolean to enable/disable this functionality. Set to a string, it will continue comments using a custom shortcut. Set to an object, it will use the
var myCodeMirror = CodeMirror(document.body);
110 property for a custom shortcut and the boolean
var myCodeMirror = CodeMirror(document.body);
111 property to determine whether single-line comments should be continued (defaulting to
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
3).
var myCodeMirror = CodeMirror(document.body);
113Adds a
var myCodeMirror = CodeMirror(document.body);
114 option that can be used to make content appear in the editor when it is empty and not focused. It can hold either a string or a DOM node. Also gives the editor a
var myCodeMirror = CodeMirror(document.body);
115 CSS class whenever it doesn't contain any text. See the demo.
var myCodeMirror = CodeMirror(document.body);
116Defines an option
var myCodeMirror = CodeMirror(document.body);
117 that, when set to
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
3, will make the editor full-screen (as in, taking up the whole browser window). Depends on
var myCodeMirror = CodeMirror(document.body);
119. Demo here.
var myCodeMirror = CodeMirror(document.body);
120This addon can be useful when initializing an editor in a hidden DOM node, in cases where it is difficult to call when the editor becomes visible. It defines an option
var myCodeMirror = CodeMirror(document.body);
122 which you can set to true to ensure that, if the editor wasn't visible on initialization, it will be refreshed the first time it becomes visible. This is done by polling every 250 milliseconds (you can pass a value like
var myCodeMirror = CodeMirror(document.body);
123 as the option value to configure this). Note that this addon will only refresh the editor once when it first becomes visible, and won't take care of further restyling and resizing.
var myCodeMirror = CodeMirror(document.body);
124Defines two additional scrollbar models,
var myCodeMirror = CodeMirror(document.body);
125 and
var myCodeMirror = CodeMirror(document.body);
126 (see demo) that can be selected with the option. Depends on
var myCodeMirror = CodeMirror(document.body);
128, which can be further overridden to style your own scrollbars.
var myCodeMirror = CodeMirror(document.body);
129Provides functionality for showing markers on the scrollbar to call out certain parts of the document. Adds a method
var myCodeMirror = CodeMirror(document.body);
130 to editor instances that can be called, with a CSS class name as argument, to create a set of annotations. The method returns an object whose
var myCodeMirror = CodeMirror(document.body);
62 method can be called with a sorted array of
var myCodeMirror = CodeMirror(document.body);
132 objects marking the ranges to be highlighted. To detach the annotations, call the object's mode/48 method.
var myCodeMirror = CodeMirror(document.body);
134Adds a
var myCodeMirror = CodeMirror(document.body);
135 option, which can be used to show one or more vertical rulers in the editor. The option, if defined, should be given an array of
var myCodeMirror = CodeMirror(document.body);
136 objects or numbers (which indicate a column). The ruler will be displayed at the column indicated by the number or the
var myCodeMirror = CodeMirror(document.body);
137 property. The
var myCodeMirror = CodeMirror(document.body);
138 property can be used to assign a custom style to a ruler. Demo here.
var myCodeMirror = CodeMirror(document.body);
139Defines an
var myCodeMirror = CodeMirror(document.body);
140 method for CodeMirror instances, which places a DOM node above or below an editor, and shrinks the editor to make room for the node. The method takes as first argument as DOM node, and as second an optional options object. The
var myCodeMirror = CodeMirror(document.body);
141 object returned by this method has a mode/48 method that is used to remove the panel, and a
var myCodeMirror = CodeMirror(document.body);
143 method that can be used to notify the addon when the size of the panel's DOM node has changed
The method accepts the following options.
var myCodeMirror = CodeMirror(document.body);
144Controls the position of the newly added panel. The following values are recognized.
var myCodeMirror = CodeMirror(document.body);
145Adds the panel at the very top.
var myCodeMirror = CodeMirror(document.body);
146Adds the panel at the bottom of the top panels.
var myCodeMirror = CodeMirror(document.body);
147Adds the panel at the very bottom.
var myCodeMirror = CodeMirror(document.body);
148Adds the panel at the top of the bottom panels.
var myCodeMirror = CodeMirror(document.body);
149The new panel will be added before the given panel.
var myCodeMirror = CodeMirror(document.body);
150The new panel will be added after the given panel.
var myCodeMirror = CodeMirror(document.body);
151The new panel will replace the given panel.
var myCodeMirror = CodeMirror(document.body);
152Whether to scroll the editor to keep the text's vertical position stable, when adding a panel above it. Defaults to false. When using the
var myCodeMirror = CodeMirror(document.body);
153,
var myCodeMirror = CodeMirror(document.body);
154 or
var myCodeMirror = CodeMirror(document.body);
155 options, if the panel doesn't exists or has been removed, the value of the
var myCodeMirror = CodeMirror(document.body);
156 option will be used as a fallback
A demo of the addon is available here.
var myCodeMirror = CodeMirror(document.body);
157Addon to perform hard line wrapping/breaking for paragraphs of text. Adds these methods to editor instances.
var myCodeMirror = CodeMirror(document.body);
158Wraps the paragraph at the given position. If
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
54 is not given, it defaults to the cursor position.
var myCodeMirror = CodeMirror(document.body);
160Wraps the given range as one big paragraph.
var myCodeMirror = CodeMirror(document.body);
161Wraps the paragraphs in (and overlapping with) the given range individually. The following options are recognized.
var myCodeMirror = CodeMirror(document.body);
162Blank lines are always considered paragraph boundaries. These options can be used to specify a pattern that causes lines to be considered the start or end of a paragraph.
var myCodeMirror = CodeMirror(document.body);
163The column to wrap at. Defaults to 80.
var myCodeMirror = CodeMirror(document.body);
164A regular expression that matches only those two-character strings that allow wrapping. By default, the addon wraps on whitespace and after dash characters.
var myCodeMirror = CodeMirror(document.body);
165Whether trailing space caused by wrapping should be preserved, or deleted. Defaults to true.
var myCodeMirror = CodeMirror(document.body);
166If set to true forces a break at
var myCodeMirror = CodeMirror(document.body);
137 in the case when no
var myCodeMirror = CodeMirror(document.body);
168 pattern is found in the range. If set to false allows line to overflow the
var myCodeMirror = CodeMirror(document.body);
137 limit if no
var myCodeMirror = CodeMirror(document.body);
168 pattern found. Defaults to true. Bản demo của addon có sẵn tại đây.
var myCodeMirror = CodeMirror(document.body);
171Defines an option `"scrollPastEnd"` that, when set to a truthy value, allows the user to scroll one editor height of empty space into view at the bottom of the editor.
var myCodeMirror = CodeMirror(document.body);
172Implements an interface for merging changes, using either a 2-way or a 3-way view. The
var myCodeMirror = CodeMirror(document.body);
173 constructor takes arguments similar to the constructor, first a node to append the interface to, and then an options object. Options are passed through to the editors inside the view. These extra options are recognized.
var myCodeMirror = CodeMirror(document.body);
175 and
var myCodeMirror = CodeMirror(document.body);
176If given these provide original versions of the document, which will be shown to the left and right of the editor in non-editable CodeMirror instances. The merge interface will highlight changes between the editable document and the original(s). To create a 2-way (as opposed to 3-way) merge view, provide only one of them.
var myCodeMirror = CodeMirror(document.body);
177Determines whether buttons that allow the user to revert changes are shown. Defaults to true.
var myCodeMirror = CodeMirror(document.body);
178Can be used to define custom behavior when the user reverts a changed chunk.
var myCodeMirror = CodeMirror(document.body);
179Sets the style used to connect changed chunks of code. By default, connectors are drawn. When this is set to
var myCodeMirror = CodeMirror(document.body);
180, the smaller chunk is padded to align with the bigger chunk instead.
var myCodeMirror = CodeMirror(document.body);
181When true (default is false), stretches of unchanged text will be collapsed. When a number is given, this indicates the amount of lines to leave visible around such stretches (which defaults to 2).
var myCodeMirror = CodeMirror(document.body);
182Determines whether the original editor allows editing. Defaults to false.
var myCodeMirror = CodeMirror(document.body);
183When true (the default), changed pieces of text are highlighted.
var myCodeMirror = CodeMirror(document.body);
184By default the chunk highlights are added using with "background". Override this to customize it to be any valid `where` parameter or an Array of valid `where` parameters. The addon also defines commands
var myCodeMirror = CodeMirror(document.body);
186 and
var myCodeMirror = CodeMirror(document.body);
187 to quickly jump to the next changed chunk. Demo here.
var myCodeMirror = CodeMirror(document.body);
188Provides integration with the Tern JavaScript analysis engine, for completion, definition finding, and minor refactoring help. See the demo for a very simple integration. For more involved scenarios, see the comments at the top of the addon and the implementation of the (multi-file) demonstration on the Tern website

Writing CodeMirror Modes

Modes typically consist of a single JavaScript file. This file defines, 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

This section describes the low-level mode interface. Many modes are written directly against this, since it offers a lot of control, but for a quick mode definition, you might want to use the simple mode addon

The mode script should call

var myCodeMirror = CodeMirror(document.body);
189 to register itself with CodeMirror. This function takes two arguments. The first should be the name of the mode, for which you should use a lowercase string, preferably one that is also the name of the files that define the mode (i. e.
var myCodeMirror = CodeMirror(document.body);
190 is defined in
var myCodeMirror = CodeMirror(document.body);
191). The second argument should be a function that, given a CodeMirror configuration object (the thing passed to the
var myCodeMirror = CodeMirror(document.body);
1 function) and an optional mode configuration object (as in the option), returns a mode object

Thông thường, bạn nên sử dụng đối số thứ hai này cho

var myCodeMirror = CodeMirror(document.body);
194 làm hàm phạm vi mô-đun của mình (các chế độ không được rò rỉ bất kỳ thứ gì vào phạm vi toàn cầu. ), i. e. write your whole mode inside this function

The main responsibility of a mode script is parsing the content of the editor. Tùy thuộc vào ngôn ngữ và số lượng chức năng mong muốn, điều này có thể được thực hiện theo những cách thực sự dễ dàng hoặc cực kỳ phức tạp. Một số trình phân tích cú pháp có thể không có trạng thái, nghĩa là chúng xem xét một phần tử (mã thông báo) của mã tại một thời điểm mà không có ký ức về những gì xảy ra trước đó. Hầu hết, tuy nhiên, sẽ cần phải nhớ một cái gì đó. This is done by using a state object, which is an object that is always passed when reading a token, and which can be mutated by the tokenizer

Modes that use a state must define a

var myCodeMirror = CodeMirror(document.body);
195 method on their mode object. This is a function of no arguments that produces a state object to be used at the start of a document

The most important part of a mode object is its

var myCodeMirror = CodeMirror(document.body);
196 method. All modes must define this method. It should read one token from the stream it is given as an argument, optionally update its state, and return a style string, or
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0 for tokens that do not have to be styled. For your styles, you are encouraged to use the 'standard' names defined in the themes (without the
var myCodeMirror = CodeMirror(document.body);
198 prefix). If that fails, it is also possible to come up with your own and write your own CSS theme file

A typical token string would be

var myCodeMirror = CodeMirror(document.body);
199 or
require.config({
  packages: [{
    name: "codemirror",
    location: "../path/to/codemirror",
    main: "lib/codemirror"
  }]
});
89. Multiple styles can be returned (separated by spaces), for example
var myCodeMirror = CodeMirror(document.body);
201 for a thing that looks like a string but is invalid somehow (say, missing its closing quote). When a style is prefixed by
var myCodeMirror = CodeMirror(document.body);
202 or
var myCodeMirror = CodeMirror(document.body);
203, the style will be applied to the whole line, analogous to what the method does—styling the
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
89 in the simple case, and the
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
90 element when
var myCodeMirror = CodeMirror(document.body);
203 is prefixed

The stream object that's passed to

var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
85 encapsulates a line of code (tokens may never span lines) and our current position in that line. It has the following API

var myCodeMirror = CodeMirror(document.body);
209Returns true only if the stream is at the end of the line.
var myCodeMirror = CodeMirror(document.body);
210Returns true only if the stream is at the start of the line.
var myCodeMirror = CodeMirror(document.body);
211Returns the next character in the stream without advancing it. Will return a
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0 at the end of the line.
var myCodeMirror = CodeMirror(document.body);
213Returns the next character in the stream and advances it. Also returns
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0 when no more characters are available.
var myCodeMirror = CodeMirror(document.body);
215mode/26 can be a character, a regular expression, or a function that takes a character and returns a boolean. If the next character in the stream 'matches' the given argument, it is consumed and returned. Otherwise,
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
65 is returned.
var myCodeMirror = CodeMirror(document.body);
218Repeatedly calls
var myCodeMirror = CodeMirror(document.body);
219 with the given argument, until it fails. Returns true if any characters were eaten.
var myCodeMirror = CodeMirror(document.body);
220Shortcut for
var myCodeMirror = CodeMirror(document.body);
221 when matching white-space.
var myCodeMirror = CodeMirror(document.body);
222Moves the position to the end of the line.
var myCodeMirror = CodeMirror(document.body);
223Skips to the start of the next occurrence of the given string, if found on the current line (doesn't advance the stream if the string does not occur on the line). Returns true if the string was found.
var myCodeMirror = CodeMirror(document.body);
224
var myCodeMirror = CodeMirror(document.body);
225Act like a multi-character
var myCodeMirror = CodeMirror(document.body);
219—if
var myCodeMirror = CodeMirror(document.body);
227 is true or not given—or a look-ahead that doesn't update the stream position—if it is false.
var myCodeMirror = CodeMirror(document.body);
228 can be either a string or a regular expression starting with
var myCodeMirror = CodeMirror(document.body);
229. When it is a string,
var myCodeMirror = CodeMirror(document.body);
230 can be set to true to make the match case-insensitive. When successfully matching a regular expression, the returned value will be the array returned by mode/26, in case you need to extract matched groups.
var myCodeMirror = CodeMirror(document.body);
232Backs up the stream
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
68 characters. Backing it up further than the start of the current token will cause things to break, so be careful.
var myCodeMirror = CodeMirror(document.body);
234Returns the column (taking into account tabs) at which the current token starts.
var myCodeMirror = CodeMirror(document.body);
235Tells you how far the current line has been indented, in spaces. Corrects for tab characters.
var myCodeMirror = CodeMirror(document.body);
236Get the string between the start of the current token and the current stream position.
var myCodeMirror = CodeMirror(document.body);
237Get the line
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
68 (>0) lines after the current one, in order to scan ahead across line boundaries. Note that you want to do this carefully, since looking far ahead will make mode state caching much less effective.
var myCodeMirror = CodeMirror(document.body);
239Modes added through (and only such modes) can use this method to inspect the current token produced by the underlying mode

By default, blank lines are simply skipped when tokenizing a document. For languages that have significant blank lines, you can define a

var myCodeMirror = CodeMirror(document.body);
241 method on your mode that will get called whenever a blank line is passed over, so that it can update the parser state

Because state object are mutated, and CodeMirror needs to keep valid versions of a state around so that it can restart a parse at any line, copies must be made of state objects. The default algorithm used is that a new state object is created, which gets all the properties of the old object. Any properties which hold arrays get a copy of these arrays (since arrays tend to be used as mutable stacks). When this is not correct, for example because a mode mutates non-array properties of its state object, a mode object should define a

var myCodeMirror = CodeMirror(document.body);
242 method, which is given a state and should return a safe copy of that state

If you want your mode to provide smart indentation (through the method and the

var myCodeMirror = CodeMirror(document.body);
244 and
var myCodeMirror = CodeMirror(document.body);
245 commands, to which keys can be ), you must define an
var myCodeMirror = CodeMirror(document.body);
246 method on your mode object

The indentation method should inspect the given state object, and optionally the

var myCodeMirror = CodeMirror(document.body);
247 string, which contains the text on the line that is being indented, and return an integer, the amount of spaces to indent. It should usually take the option into account. Một phương pháp thụt lề có thể trả về
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
48 để chỉ ra rằng nó không thể đưa ra một cách thụt lề chính xác

To work well with the , a mode may define

var myCodeMirror = CodeMirror(document.body);
250 (string that starts a line comment),
var myCodeMirror = CodeMirror(document.body);
251,
var myCodeMirror = CodeMirror(document.body);
252 (strings that start and end block comments), and
var myCodeMirror = CodeMirror(document.body);
253 (a string to put at the start of continued lines in a block comment). All of these are optional

Finally, a mode may define either an

var myCodeMirror = CodeMirror(document.body);
254 or an
var myCodeMirror = CodeMirror(document.body);
255 property, which are used to automatically reindent the line when certain patterns are typed and the option is enabled.
var myCodeMirror = CodeMirror(document.body);
254 may be a string, and will trigger a reindent whenever one of the characters in that string are typed. Often, it is more appropriate to use
var myCodeMirror = CodeMirror(document.body);
255, which should hold a regular expression, and will trigger indentation when the part of the line before the cursor matches the expression. It should usually end with a
var myCodeMirror = CodeMirror(document.body);
259 character, so that it only matches when the indentation-changing pattern was just typed, not when something was typed after the pattern

So, to summarize, a mode must provide a

var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
85 method, and it may provide
var myCodeMirror = CodeMirror(document.body);
261,
var myCodeMirror = CodeMirror(document.body);
262, and
var myCodeMirror = CodeMirror(document.body);
263 methods. For an example of a trivial mode, see the diff mode, for a more involved example, see the C-like mode

Sometimes, it is useful for modes to nest—to have one mode delegate work to another mode. An example of this kind of mode is the mixed-mode HTML mode. To implement such nesting, it is usually necessary to create mode objects and copy states yourself. To create a mode object, there are

var myCodeMirror = CodeMirror(document.body);
264, where 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 option. To copy a state object, call
var myCodeMirror = CodeMirror(document.body);
266, where
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
84 is the mode that created the given state

In a nested mode, it is recommended to add an extra method,

var myCodeMirror = CodeMirror(document.body);
268 which, given a state object, returns a
var myCodeMirror = CodeMirror(document.body);
269 object with the inner mode and its state for the current position. These are used by utility scripts such as the to get context information. Use the
var myCodeMirror = CodeMirror(document.body);
270 helper function to, starting from a mode and a state, recursively walk down to the innermost mode and state

To make indentation work properly in a nested parser, it is advisable to give the

var myCodeMirror = CodeMirror(document.body);
261 method of modes that are intended to be nested an optional argument that provides the base indentation for the block of code. The JavaScript and CSS parser do this, for example, to allow JavaScript and CSS code inside the mixed-mode HTML mode to be properly indented

It is possible, and encouraged, to associate your mode, or a certain configuration of your mode, with a MIME type. For example, the JavaScript mode associates itself with

var myCodeMirror = CodeMirror(document.body);
272, and its JSON variant with
var myCodeMirror = CodeMirror(document.body);
273. To do this, call
var myCodeMirror = CodeMirror(document.body);
274, where
var myCodeMirror = CodeMirror(document.body);
275 can be a string or object specifying a mode, as in the option

If a mode specification wants to add some properties to the resulting mode object, typically for use with , it may contain a

var myCodeMirror = CodeMirror(document.body);
278 property, which holds an object. This object's properties will be copied to the actual mode object

Sometimes, it is useful to add or override mode object properties from external code. The

var myCodeMirror = CodeMirror(document.body);
279 function can be used to add properties to mode objects produced for a specific mode. Its first argument is the name of the mode, its second an object that specifies the properties that should be added. This is mostly useful to add utilities that can later be looked up through

VIM Mode API

CodeMirror has a robust VIM mode that attempts to faithfully emulate VIM's most useful features. It can be enabled by including

var myCodeMirror = CodeMirror(document.body);
281 and setting the
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
9 option to
var myCodeMirror = CodeMirror(document.body);
283

Cấu hình

VIM mode accepts configuration options for customizing behavior at run time. These methods can be called at any time and will affect all existing CodeMirror instances unless specified otherwise. The methods are exposed on the

var myCodeMirror = CodeMirror(document.body);
284 object

var myCodeMirror = CodeMirror(document.body);
285Sets the value of a VIM option.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
5 should be the name of an option. If
var myCodeMirror = CodeMirror(document.body);
287 is not set and
var myCodeMirror = CodeMirror(document.body);
288 is provided, then sets the global and instance values of the option. Otherwise, sets either the global or instance value of the option depending on whether
var myCodeMirror = CodeMirror(document.body);
287 is
var myCodeMirror = CodeMirror(document.body);
290 or
var myCodeMirror = CodeMirror(document.body);
291.
var myCodeMirror = CodeMirror(document.body);
292Gets the current value of a VIM option. If
var myCodeMirror = CodeMirror(document.body);
287 is not set and
var myCodeMirror = CodeMirror(document.body);
288 is provided, then gets the instance value of the option, falling back to the global value if not set. If
var myCodeMirror = CodeMirror(document.body);
287 is provided, then gets the
var myCodeMirror = CodeMirror(document.body);
290 or
var myCodeMirror = CodeMirror(document.body);
291 value without checking the other.
var myCodeMirror = CodeMirror(document.body);
298Maps a key sequence to another key sequence. Implements VIM's
var myCodeMirror = CodeMirror(document.body);
299 command. To map ; to . in VIM would be
var myCodeMirror = CodeMirror(document.body);
300. That would translate to
var myCodeMirror = CodeMirror(document.body);
301. The
var myCodeMirror = CodeMirror(document.body);
302 can be
var myCodeMirror = CodeMirror(document.body);
303,
var myCodeMirror = CodeMirror(document.body);
304, or
var myCodeMirror = CodeMirror(document.body);
305, which correspond to
var myCodeMirror = CodeMirror(document.body);
306,
var myCodeMirror = CodeMirror(document.body);
307, and
var myCodeMirror = CodeMirror(document.body);
308 respectively.
var myCodeMirror = CodeMirror(document.body);
309Maps a key sequence to a
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
50,
var myCodeMirror = CodeMirror(document.body);
311, or
var myCodeMirror = CodeMirror(document.body);
312 type command. The args object is passed through to the command when it is invoked by the provided key sequence.
var myCodeMirror = CodeMirror(document.body);
313 can be
var myCodeMirror = CodeMirror(document.body);
303,
var myCodeMirror = CodeMirror(document.body);
304, or
var myCodeMirror = CodeMirror(document.body);
305, to map the key sequence only in the corresponding mode.
var myCodeMirror = CodeMirror(document.body);
317 is applicable only to actions, determining whether it is recorded for replay for the
var myCodeMirror = CodeMirror(document.body);
318 single-repeat command.
var myCodeMirror = CodeMirror(document.body);
319Remove the command
var myCodeMirror = CodeMirror(document.body);
320 if it is a user defined command. If the command is an Ex to Ex or Ex to key mapping then the context must be
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
65 or
require([
  "cm/lib/codemirror", "cm/mode/htmlmixed/htmlmixed"
], function(CodeMirror) {
  CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    mode: "htmlmixed"
  });
});
2.
var myCodeMirror = CodeMirror(document.body);
323Remove all user-defined mappings for the provided context.
var myCodeMirror = CodeMirror(document.body);
324Non-recursive map function. This will not create mappings to key maps that aren't present in the default key map. If no context is provided then the mapping will be applied to each of normal, insert, and visual mode

Sự kiện

VIM mode signals a few events on the editor instance. For an example usage, see

var myCodeMirror = CodeMirror(document.body);
325Fired on keypress and mousedown where command has completed or no command found.
var myCodeMirror = CodeMirror(document.body);
326Fired on keypress,
var myCodeMirror = CodeMirror(document.body);
327 is in Vim's key notation.
var myCodeMirror = CodeMirror(document.body);
328Fired after mode change,
var myCodeMirror = CodeMirror(document.body);
329 parameter is a
var myCodeMirror = CodeMirror(document.body);
330 object. chế độ.
var myCodeMirror = CodeMirror(document.body);
331. Visual sub-modes.
var myCodeMirror = CodeMirror(document.body);
332

Extending VIM

CodeMirror's VIM mode implements a large subset of VIM's core editing functionality. But since there's always more to be desired, there is a set of APIs for extending VIM's functionality. As with the configuration API, the methods are exposed on

var myCodeMirror = CodeMirror(document.body);
284 and may be called at any time