Python dedent không hoạt động

CodeMirror là một thành phần soạn thảo mã có thể được nhúng trong các trang Web. Thư viện cốt lõi chỉ cung cấp thành phần trình chỉnh sửa, không có nút đi kèm, tự động hoàn thành hoặc chức năng IDE khác. Nó cung cấp một API phong phú, trên đó chức năng như vậy có thể được triển khai một cách đơn giản. Xem các addon được bao gồm trong bản phân phối và các gói của bên thứ 3 trên npm, để triển khai các tính năng bổ sung có thể tái sử dụng

CodeMirror hoạt động với các chế độ dành riêng cho ngôn ngữ. Các chế độ là các chương trình JavaScript giúp tô màu (và tùy chọn thụt lề) văn bản được viết bằng một ngôn ngữ nhất định. Bản phân phối đi kèm với một số chế độ (xem thư mục

var myCodeMirror = CodeMirror(document.body);
136) và không khó để viết những chế độ mới cho các ngôn ngữ khác

Sử dụng cơ bản

Cách dễ nhất để sử dụng CodeMirror là chỉ cần tải tập lệnh và biểu định kiểu được tìm thấy trong

var myCodeMirror = CodeMirror(document.body);
137 trong bản phân phối, cộng với tập lệnh chế độ từ một trong các thư mục
var myCodeMirror = CodeMirror(document.body);
136. Ví dụ

<script src="lib/codemirror.js"></script>
<link rel="stylesheet" href="lib/codemirror.css">
<script src="mode/javascript/javascript.js"></script>

(Ngoài ra, hãy sử dụng trình tải mô-đun. Thêm về điều đó sau. )

Sau khi hoàn thành việc này, một phiên bản trình chỉnh sửa có thể được tạo như thế này

var myCodeMirror = CodeMirror(document.body);

Trình chỉnh sửa sẽ được thêm vào nội dung tài liệu, sẽ bắt đầu trống và sẽ sử dụng chế độ mà chúng tôi đã tải. Để có nhiều quyền kiểm soát hơn đối với trình soạn thảo mới, một đối tượng cấu hình có thể được chuyển đến

var myCodeMirror = CodeMirror(document.body);
1 làm đối số thứ hai

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

Điều này sẽ khởi tạo trình chỉnh sửa với một đoạn mã đã có trong đó và yêu cầu rõ ràng trình chỉnh sửa sử dụng chế độ JavaScript (rất hữu ích khi nhiều chế độ được tải). Xem bên dưới để biết phần thảo luận đầy đủ về các tùy chọn cấu hình mà CodeMirror chấp nhận

Trong trường hợp bạn không muốn nối 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, đố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 tài liệu tham khảo API để biết 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 AMD (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

var myCodeMirror = CodeMirror(document.body);
1

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
var myCodeMirror = CodeMirror(document.body);
8, như trong

var myCodeMirror = CodeMirror(document.body);
4

Cấu hình

Cả hàm

var myCodeMirror = CodeMirror(document.body);
1 và phương thức
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
0 của nó đều lấy đối số thứ hai (tùy chọn) là một đối tượng chứa các tùy chọn cấu hình. Bất kỳ tùy chọn nào không được cung cấp như thế này sẽ được lấy từ
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
1, một đối tượng chứa các tùy chọn mặc định. Bạn có thể cập nhật đối tượng này để thay đổi các giá trị mặc định trên trang của mình

Các tùy chọn không được kiểm tra theo bất kỳ cách nào, do đó, việc đặt các giá trị tùy chọn không có thật chắc chắn sẽ dẫn đến các lỗi kỳ lạ

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

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
2Giá trị bắt đầu của trình chỉnh sửa. Có thể là một chuỗi hoặc một đối tượng tài liệu.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
3Chế độ sử dụng. Khi không được cung cấp, điều này sẽ mặc định ở chế độ đầu tiên được tải. Nó có thể là một chuỗi, chỉ đơn giản là đặt tên cho chế độ hoặc là một loại MIME được liên kết với chế độ. Giá trị
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
4 cho biết không nên áp dụng đánh dấu. Ngoài ra, nó có thể là một đối tượng chứa các tùy chọn cấu hình cho chế độ, với thuộc tính
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
5 đặt tên cho chế độ (ví dụ:
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
6). Các trang demo cho từng chế độ chứa thông tin về các tham số cấu hình mà chế độ hỗ trợ. Bạn có thể hỏi CodeMirror chế độ và loại MIME nào đã được xác định bằng cách kiểm tra các đối tượng
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
7 và
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
8. Cái đầu tiên ánh xạ tên chế độ tới hàm tạo của chúng và cái thứ hai ánh xạ các loại MIME thành thông số kỹ thuật của chế độ.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
9Thiết lập rõ ràng dấu phân cách dòng cho trình chỉnh sửa. Theo mặc định (giá trị
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0), tài liệu sẽ được phân chia trên các CRLF cũng như các CR và LF đơn lẻ và một LF duy nhất sẽ được sử dụng làm dấu phân cách dòng trong tất cả đầu ra (chẳng hạn như
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
1). Khi một chuỗi cụ thể được đưa ra, các dòng sẽ chỉ được phân tách trên chuỗi đó và theo mặc định, đầu ra sẽ sử dụng cùng một dấu phân cách đó.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
2Chủ đề để tạo kiểu cho trình chỉnh sửa với. Bạn phải đảm bảo rằng tệp CSS xác định các kiểu
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
3 tương ứng đã được tải (xem thư mục
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
4 trong bản phân phối). Giá trị mặc định là
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
5, trong đó các màu được bao gồm trong
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
6. Có thể sử dụng nhiều lớp theo chủ đề cùng một lúc—ví dụ:
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
7 sẽ chỉ định cả lớp
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
8 và lớp
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
9 cho trình chỉnh sửa.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
0Có bao nhiêu khoảng trống trong một khối (bất kể điều đó có nghĩa là gì trong ngôn ngữ đã chỉnh sửa) nên được thụt vào. Mặc định là 2.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
1Có sử dụng thụt đầu dòng theo ngữ cảnh mà chế độ cung cấp hay không (hoặc chỉ thụt lề giống như dòng trước đó). Mặc định là true.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
2Chiều rộng của một ký tự tab. Mặc định là 4.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
3Liệu khi thụt lề, N*
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
4 khoảng trắng đầu tiên có nên được thay thế bằng N tab hay không. Mặc định là sai.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
5 Định cấu hình liệu trình chỉnh sửa có nên thụt lề lại dòng hiện tại khi một ký tự được nhập có thể thay đổi cách thụt lề thích hợp của nó hay không (chỉ hoạt động nếu chế độ hỗ trợ thụt lề). Mặc định là đúng.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
6Một biểu thức chính quy được sử dụng để xác định những ký tự nào sẽ được thay thế bằng một trình giữ chỗ đặc biệt. Hầu hết hữu ích cho các ký tự đặc biệt không in. Mặc định là
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
7.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
8Một hàm, được cung cấp một ký tự đặc biệt được xác định bởi tùy chọn
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
9, tạo ra một nút DOM được sử dụng để đại diện cho ký tự đó. Theo mặc định, một chấm đỏ ( ) được hiển thị cùng với chú giải công cụ tiêu đề để biểu thị mã ký tự.
var myCodeMirror = CodeMirror(document.body);
10Lật bố cục tổng thể và chọn hướng đoạn cơ sở từ trái sang phải hoặc từ phải sang trái. Mặc định là "ltr". CodeMirror áp dụng Thuật toán hai chiều Unicode cho từng dòng, nhưng không tự động phát hiện hướng cơ sở — thuật toán này được đặt thành hướng trình chỉnh sửa cho tất cả các dòng. Thứ tự kết quả đôi khi bị sai khi hướng cơ sở không khớp với ý định của người dùng (ví dụ: dấu chấm câu ở đầu và cuối nhảy sang phía sai của dòng). Do đó, việc cho phép người dùng chuyển đổi tùy chọn này là hữu ích đối với đầu vào đa ngôn ngữ.
var myCodeMirror = CodeMirror(document.body);
11Xác định xem chuyển động của con trỏ ngang qua văn bản từ phải sang trái (tiếng Ả Rập, tiếng Do Thái) là trực quan (nhấn mũi tên trái sẽ di chuyển con trỏ sang trái) hay logic (nhấn mũi tên trái sẽ di chuyển đến chỉ mục thấp hơn tiếp theo trong chuỗi, trực quan là phải . Giá trị mặc định là
var myCodeMirror = CodeMirror(document.body);
12 trên Windows và
var myCodeMirror = CodeMirror(document.body);
13 trên các nền tảng khác.
var myCodeMirror = CodeMirror(document.body);
14Định cấu hình bản đồ chính để sử dụng. Giá trị mặc định là
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
5, là bản đồ khóa duy nhất được xác định trong chính
var myCodeMirror = CodeMirror(document.body);
16. Bản đồ khóa bổ sung được tìm thấy trong thư mục
var myCodeMirror = CodeMirror(document.body);
17. Xem phần trên bản đồ chính để biết thêm thông tin.
var myCodeMirror = CodeMirror(document.body);
18Có thể được sử dụng để chỉ định các ràng buộc phím bổ sung cho trình chỉnh sửa, bên cạnh các ràng buộc được xác định bởi
var myCodeMirror = CodeMirror(document.body);
19. Phải là null hoặc giá trị bản đồ khóa hợp lệ.
var myCodeMirror = CodeMirror(document.body);
40Cho phép bạn định cấu hình hành vi chọn và kéo chuột. Hàm được gọi khi nhấn chuột trái. Đối tượng được trả về có thể có các thuộc tính sau.
var myCodeMirror = CodeMirror(document.body);
41Đơn vị để chọn. Có thể là một trong các đơn vị tích hợp sẵn hoặc một hàm đảm nhận một vị trí và trả về một phạm vi xung quanh vị trí đó, đối với một đơn vị tùy chỉnh. Giá trị mặc định là trả về
var myCodeMirror = CodeMirror(document.body);
42 cho nhấp đúp chuột,
var myCodeMirror = CodeMirror(document.body);
43 cho nhấp chuột ba lần,
var myCodeMirror = CodeMirror(document.body);
44 cho nhấp chuột thay thế (hoặc, trên Chrome OS, nhấp chuột chuyển đổi meta) và
var myCodeMirror = CodeMirror(document.body);
45 nếu không thì.
var myCodeMirror = CodeMirror(document.body);
46Có nên mở rộng phạm vi lựa chọn hiện có 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.
var myCodeMirror = CodeMirror(document.body);
47Khi đượ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.
var myCodeMirror = CodeMirror(document.body);
48Khi 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 việc 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.
var myCodeMirror = CodeMirror(document.body);
49Liệu CodeMirror có nên cuộn hoặc ngắt dòng cho các dòng dài không. Mặc định là
var myCodeMirror = CodeMirror(document.body);
12 (cuộn).
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
71Có hiển thị số dòng ở bên trái của trình chỉnh sửa không.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
72Số nào để bắt đầu đếm dòng. Mặc định là 1.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
73Mộ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.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
74Có thể được sử dụng để thêm máng xối phụ (ngoài hoặc thay cho máng xối 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
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
75 (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
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
76, để đặt 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 chuyển đến
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
77.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
78Xá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 hay không (đúng, mặc định).
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
79Chọn triển khai thanh cuộn. Giá trị mặc định là
var myCodeMirror = CodeMirror(document.body);
1360, 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. Addons có thể triển khai các mô hình thanh cuộn bổ sung.
var myCodeMirror = CodeMirror(document.body);
1362Khi
var myCodeMirror = CodeMirror(document.body);
1363 đượ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
var myCodeMirror = CodeMirror(document.body);
1364.
var myCodeMirror = CodeMirror(document.body);
1365Chọ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
var myCodeMirror = CodeMirror(document.body);
1366 và
var myCodeMirror = CodeMirror(document.body);
1367. Trên trình duyệt di động, mặc định là
var myCodeMirror = CodeMirror(document.body);
1367. Trên trình duyệt máy tính để bàn, mặc định là
var myCodeMirror = CodeMirror(document.body);
1366. Hỗ trợ cho IME và trình đọc màn hình tốt hơn trong kiểu máy
var myCodeMirror = CodeMirror(document.body);
1367. 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.
var myCodeMirror = CodeMirror(document.body);
1371Điều này vô hiệu hóa việc chỉnh sửa nội dung của trình chỉnh sửa bởi người dùng. Nếu giá trị đặc biệt
var myCodeMirror = CodeMirror(document.body);
1372 được cung cấp (thay vì chỉ đơn giản là
var myCodeMirror = CodeMirror(document.body);
13), tiêu điểm của trình chỉnh sửa cũng không được phép.
var myCodeMirror = CodeMirror(document.body);
1374Nhã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.
var myCodeMirror = CodeMirror(document.body);
1375Có nên vẽ con trỏ khi vùng chọn đang hoạt động hay không. Mặc định là sai.
var myCodeMirror = CodeMirror(document.body);
1376Khi đượ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 đó.
var myCodeMirror = CodeMirror(document.body);
1377Khi 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
var myCodeMirror = CodeMirror(document.body);
12 để tắt hành vi đó.
var myCodeMirror = CodeMirror(document.body);
1379Xá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);
02Chỉ mục tab để gán cho trình chỉnh sửa. 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 sử dụng
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
0 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 pháp
var myCodeMirror = CodeMirror(document.body);
07 để 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
var myCodeMirror = CodeMirror(document.body);
11 của đố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);
14Có bao nhiêu khoảng trống để luôn giữ bên trên và bên dưới con trỏ khi đến gầ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 đi hết dòng đến cuối dòng, trông đẹp hơn
var myCodeMirror = CodeMirror(document.body);
17Nếu được đặt thành
var myCodeMirror = CodeMirror(document.body);
13 (mặc định), sẽ giữ nguyên chiều cao của con trỏ . Khi
var myCodeMirror = CodeMirror(document.body);
12, 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à
var myCodeMirror = CodeMirror(document.body);
13.
var myCodeMirror = CodeMirror(document.body);
22Làm nổi bật được thực hiện bởi một chuỗi 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ế độ (bên trong) đã 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ý bằng các phương thức

var myCodeMirror = CodeMirror(document.body);
37 và
var myCodeMirror = CodeMirror(document.body);
38 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 trình soạn thảo

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à đối tượng
var myCodeMirror = CodeMirror(document.body);
44 chứa thông tin về những thay đổi xảy ra dưới dạng đố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 đè. Sự kiện này được kích hoạt trước khi kết thúc một hoạt động, trước khi cập nhật DOM diễn ra.
var myCodeMirror = CodeMirror(document.body);
52Giống như sự kiện
var myCodeMirror = CodeMirror(document.body);
53, nhưng theo đợt cho mỗi thao tác, truyền một mảng chứa tất cả các thay đổi đã xảy ra trong thao tác. 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à trình xử lý của 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
var myCodeMirror = CodeMirror(document.body);
53. 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 hình ảnh của nó. 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 điện của chế độ và điều này khiến 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, hiển thị 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, chuyể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ó cùng hạn chế như trình xử lý
var myCodeMirror = CodeMirror(document.body);
63 — 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 cổng xem của 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 cung cấp điểm bắt đầu và kết thúc mới của chế độ xem.
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);
85.
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 chỉnh sửa (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 trình chỉnh sửa được làm mới hoặc thay đổi kích thướ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);
97.
var myCodeMirror = CodeMirror(document.body);
98Cháy khi trình chỉnh sửa cố 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 cố 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 (tái) hiển thị cho 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ý 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ó một 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ụ về

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
05) 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ó kiểu tương tự như đối tượng được chuyển đến sự kiện
var myCodeMirror = CodeMirror(document.body);
53 của trình soạn thảo.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
09Xem mô tả về cùng một sự kiện trên các phiên bả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 sự kiện cùng tên được kích hoạt trên các phiên bản trình chỉnh sửa

Điều khiển dòng (ví dụ như được trả về bởi

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
12) 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 các điểm đánh dấu máng xối của 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 sự kiện thay đổi trên đối tượng trình chỉnh sửa

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
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
17 và
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
18, 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 di chuyển con trỏ kết hợp với
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
21 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 kéo dài 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 xóa điểm đánh dấu bằng cách chỉnh sửa, 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
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
28, 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

var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
7

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`. Chúng cũng có thể được thêm tiền tố bằng các công cụ sửa đổi và ngoài ra, từ `Double` hoặc `Triple` có thể được đặt trước `Click` (như trong `LeftDoubleClick`) để liên kết thao tác nhấp đúp hoặc nhấp ba lần. 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ó thể chỉ định các liên kết phím nhiều nét 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 liên kết 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 bản đồ đó trước khi có thể sử dụng bản đồ đó. 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 liên kết 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

var myCodeMirror = CodeMirror(document.body);
12. Các chuỗi đề cập đến các lệnh, được mô tả bên dưới. Nếu thuộc tính được đặt thành
var myCodeMirror = CodeMirror(document.body);
12, 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 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ể trì hoãn 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 thứ gì đó khi nó hoạt động hoặc phá bỏ 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ẽ chứa các hàm lấy phiên bản trình chỉnh sửa 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 đối với sơ đồ bàn phím cấp cao nhất, không áp dụng cho bản đồ dự phòng hoặc bản đồ được thêm bằng
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
56 hoặc
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
57

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 bằng phương thức

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

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 phía 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"
});
79.
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 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 cùng khoảng cách.
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 nhấn 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 bên trên).
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 nhóm 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 đến đầu nhóm sau .
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 lựa chọn.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
99 Ctrl-] (PC), Cmd-] (Mac) Thụt lề dòng hiện tại hoặc vùng chọn theo một đơn vị thụt lề.
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 vùng chọn theo một đơn vị thụt lề.
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 khớp với chiều rộng mà tab ở vị trí con trỏ sẽ có.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
03 Tab Nếu thứ gì đó được chọn, hãy thụt lề nó bằng một đơn vị thụt lề. 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 các 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ờ ghi đè.
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 search addon (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ạo kiểu cho chính 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});
14Phần tử 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 tùy chọn
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
17 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 được 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 cái 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ử
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
76 (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 dò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 các phần tử
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
27 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 để loại bỏ các hiệu ứng này một lần nữa đối với các phần tử thuộc 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 addons) 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 biểu diễn, 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ó thuộc tính
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
38 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 trên cả phiên bản
var myCodeMirror = CodeMirror(document.body);
1 (trình chỉnh sửa) 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

Người xây dựng

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 chỉnh sửa 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à tên tùy chọn ánh xạ phần tử thành 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ừ
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
1

Lưu ý rằng đối tượng tùy chọn được truyền cho hàm tạo sẽ bị thay đổi khi các tùy chọn của phiên bản bị thay đổi, 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

var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
50 để biết 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});
54Nhận 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 sang các sự kiện
var myCodeMirror = CodeMirror(document.body);
53 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 nguồn gốc lựa chọn.
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});
69Lấy 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 các chế độ xem phụ được liên kết hoặc tài liệu được khởi tạo với dòng đầu tiên khác 0, giá trị này 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. Đây thường sẽ là
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
72, nhưng đối với các chế độ xem phụ được liên kết, 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 nạp xử lý 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
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
77Lặp lại 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 cung cấp, 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
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
82 cho mỗi dòng, chuyển qua phần điều khiển dòng.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
83 ngừ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 các trình xử lý dòng hơn là gọi
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
12 cho từng người trong số họ. Lưu ý rằng điều khiển dòng có thuộc tính
var myCodeMirror = CodeMirror(document.body);
48 chứa nội dung của dòng (dưới dạng chuỗi).
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', một cờ sẽ giữ lại cho đến khi được chỉnh sửa và sẽ được đặt lại khi hoàn tác chỉnh sửa đó một lần nữa. 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
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
88, 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
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
90 để 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ệnh gọi cuối cùng tới
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
93 nếu không có đối số nào được thông qua hoặc kể từ lệnh gọi phù hợp tới
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
88 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, biểu thị 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 vượt 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);
04.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
05Truy xuất một đầu của lựa 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 nào 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ả về.
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);
20.
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 có nên cuộn đầu lựa chọn vào chế độ 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 (gần về thời gian, cả hai đều bị thu gọn hoặc cả hai không bị thu gọn), thì lựa chọn mới sẽ thay thế nguồn 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. User input uses the
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
32 origin.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
33Determine the direction into which the selection endpoints should be adjusted when they fall inside an atomic range. Can be either -1 (backward) or 1 (forward). When not given, the bias will be based on the relative position of the old selection—the editor will try to move further away from that, to prevent getting stuck.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
34Sets a new set of selections. There must be at least one selection in the given array. When
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
35 is a number, it determines which selection is the primary one. When it is not given, the primary index is taken from the previous selection, or set to the last range if the previous selection had less ranges than the new one. Supports the same options as
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
20.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
15 defaults to
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
14 when not given.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
39Adds a new selection to the existing set of selections, and makes it the primary selection.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
40Similar to
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
20, but will, if shift is held or the extending flag is set, move the head of the selection while leaving the anchor at its current place.
var myCodeMirror = CodeMirror(document.body);
46 is optional, and can be passed to ensure a region (for example a word or paragraph) will end up selected (in addition to whatever lies between that region and the current anchor). When multiple selections are present, all but the primary selection will be dropped by this method. Supports the same options as
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
20.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
44An equivalent of
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
45 that acts on all selections at once.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
46Applies the given function to all existing selections, and calls
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
47 on the result.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
48Sets or clears the 'extending' flag, which acts similar to the shift key, in that it will cause cursor movement and calls to
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
45 to leave the selection anchor in place.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
50Nhận giá trị của cờ 'mở rộng'.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
51Tells you whether the editor currently has focus.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
52Used to find the target position for horizontal cursor motion.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
78 is a
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55 object,
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
55 an integer (may be negative), and
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
56 one of the string
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
57,
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
58, or
var myCodeMirror = CodeMirror(document.body);
42. Will return a position that is produced by moving
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
55 times the distance specified by
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
56. When
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
62 is true, motion in right-to-left text will be visual rather than logical. When the motion was clipped by hitting the end or start of the document, the returned value will have a
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
63 property set to true.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
64Similar to
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
65, but used for vertical motion.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
56 may be
var myCodeMirror = CodeMirror(document.body);
43 or
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
68. The other arguments and the returned value have the same interpretation as they have in
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
65.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
70Returns the start and end of the 'word' (the stretch of letters, whitespace, or punctuation) at the given position

Configuration methods

var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
71Change the configuration of the editor.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
72 should the name of an option, and
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
73 should be a valid value for that option.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
74Retrieves the current value of the given option for this editor instance.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
75Attach an additional key map to the editor. This is mostly useful for addons that need to register some key handlers without trampling on the
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
56 option. Maps added in this way have a higher precedence than the
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
56 and
var myCodeMirror = CodeMirror(document.body);
19 options, and between them, the maps added earlier have a lower precedence than those added later, unless the
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
79 argument was passed, in which case they end up below other key maps added with this method.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
80Disable a keymap added with
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
57. 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);
83Enable a highlighting overlay. This is a stateless mini-mode that can be used to add extra highlighting. For example, the search addon uses it to highlight the term that's currently being searched.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
84 can be a mode spec or a mode object (an object with a
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
85 method). The
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
48 parameter is optional. If given, it should be an object, optionally containing the following options.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
87Defaults to off, but can be given to allow the overlay styling, when not
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0, to override the styling of the base mode entirely, instead of the two being applied together.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
89Determines the ordering in which the overlays are applied. Those with high priority are applied after those with lower priority, and able to override the opaqueness of the ones that come before. Defaults to 0.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
90Pass this the exact value passed for the
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
84 parameter to
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
92, or a string that corresponds to the
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
5 property of that value, to remove an overlay again.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
94Register an event handler for the given event type (a string) on the editor instance. There is also a
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
95 version that allows registering of events on any object.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
96Remove an event handler on the editor instance. An equivalent
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
97 also exists

Document management methods

Each editor is associated with an instance of

var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
05, its document. A document represents the editor content, plus a selection, an undo history, and a mode. A document can only be associated with a single editor at a time. You can create new documents by calling the
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
99 constructor. The last three arguments are optional and can be used to set a mode for the document, make it start at a line number other than 0, and set a specific line separator respectively

var myCodeMirror = CodeMirror(document.body);
100Retrieve the currently active document from an editor.
var myCodeMirror = CodeMirror(document.body);
101Retrieve the editor associated with a document. May return
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0.
var myCodeMirror = CodeMirror(document.body);
103Attach a new document to the editor. Returns the old document, which is now no longer associated with an editor.
var myCodeMirror = CodeMirror(document.body);
104Create an identical copy of the given doc. Khi
var myCodeMirror = CodeMirror(document.body);
105 là đúng, lịch sử cũng sẽ được sao chép. Can not be called directly on an editor.
var myCodeMirror = CodeMirror(document.body);
106Create a new document that's linked to the target document. Linked documents will stay in sync (changes to one are also applied to the other) until unlinked. These are the options that are supported.
var myCodeMirror = CodeMirror(document.body);
107When turned on, the linked copy will share an undo history with the original. Thus, something done in one of the two can be undone in the other, and vice versa.
var myCodeMirror = CodeMirror(document.body);
108
var myCodeMirror = CodeMirror(document.body);
109Can be given to make the new document a subview of the original. Subviews only show a given range of lines. Note that line coordinates inside the subview will be consistent with those of the parent, so that for example a subview starting at line 10 will refer to its first line as line 10, not 0.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
3By default, the new document inherits the mode of the parent. This option can be set to a mode spec to give it a different mode.
var myCodeMirror = CodeMirror(document.body);
111Ngắt liên kết giữa hai tài liệu. After calling this, changes will no longer propagate between the documents, and, if they had a shared history, the history will become separate.
var myCodeMirror = CodeMirror(document.body);
112Sẽ 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ử

var myCodeMirror = CodeMirror(document.body);
113Hoà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ữ).
var myCodeMirror = CodeMirror(document.body);
114Làm lại một chỉnh sửa đã hoàn tác.
var myCodeMirror = CodeMirror(document.body);
115Hoàn tác một chỉnh sửa hoặc thay đổi lựa chọn.
var myCodeMirror = CodeMirror(document.body);
116Làm lại một chỉnh sửa đã hoàn tác hoặc thay đổi lựa chọn.
var myCodeMirror = CodeMirror(document.body);
117Trả về một đối tượng có thuộc tính
var myCodeMirror = CodeMirror(document.body);
118, 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ữ.
var myCodeMirror = CodeMirror(document.body);
119Xóa lịch sử hoàn tác của trình soạn thảo.
var myCodeMirror = CodeMirror(document.body);
120Nhận bản trình bày (có thể tuần tự hóa JSON) của lịch sử hoàn tác.
var myCodeMirror = CodeMirror(document.body);
121Thay thế lịch sử hoàn tác của trình chỉnh sửa bằng lịch sử được cung cấp, phải là một giá trị được trả về bởi
var myCodeMirror = CodeMirror(document.body);
122. 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
var myCodeMirror = CodeMirror(document.body);
122 được gọi

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

var myCodeMirror = CodeMirror(document.body);
124Có 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.
var myCodeMirror = CodeMirror(document.body);
129Gán một lớp CSS cho đoạn văn bản được đánh dấu.
var myCodeMirror = CodeMirror(document.body);
130Determines whether text inserted on the left of the marker will end up inside or outside of it.
var myCodeMirror = CodeMirror(document.body);
131Giống như
var myCodeMirror = CodeMirror(document.body);
132, nhưng dành cho phía bên phải.
var myCodeMirror = CodeMirror(document.body);
133Đố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. Has no effect on non-atomic ranges.
var myCodeMirror = CodeMirror(document.body);
134Giống như
var myCodeMirror = CodeMirror(document.body);
135, nhưng dành cho phía bên phải.
var myCodeMirror = CodeMirror(document.body);
136Atomic ranges act as a single unit when cursor movement is concerned—i. e. không thể đặt con trỏ bên trong chúng. Bạn có thể kiểm soát việc đặt con trỏ trực tiếp trước hoặc sau chúng bằng cách sử dụng
var myCodeMirror = CodeMirror(document.body);
135 hoặc
var myCodeMirror = CodeMirror(document.body);
138. If
var myCodeMirror = CodeMirror(document.body);
135 (or right) is not provided, then
var myCodeMirror = CodeMirror(document.body);
132 (or right) will control this behavior.
var myCodeMirror = CodeMirror(document.body);
141Collapsed ranges do not show up in the display. Setting a range to be collapsed will automatically make it atomic.
var myCodeMirror = CodeMirror(document.body);
142When enabled, will cause the mark to clear itself whenever the cursor enters its range. This is mostly useful for text-replacement widgets that need to 'snap open' when the user tries to edit them. The
var myCodeMirror = CodeMirror(document.body);
143 event fired on the range handle can be used to be notified when this happens.
var myCodeMirror = CodeMirror(document.body);
144Determines whether the mark is automatically cleared when it becomes empty. Default is true.
var myCodeMirror = CodeMirror(document.body);
145Use a given node to display this range. Ngụ ý cả sụp đổ và nguyên tử. The given DOM node must be an inline element (as opposed to a block element).
var myCodeMirror = CodeMirror(document.body);
146When
var myCodeMirror = CodeMirror(document.body);
147 is given, this determines whether the editor will capture mouse and drag events occurring in this widget. Default is false—the events will be left alone for the default browser handler, or specific handlers on the widget, to capture.
var myCodeMirror = CodeMirror(document.body);
148A read-only span can, as long as it is not cleared, not be modified except by calling
var myCodeMirror = CodeMirror(document.body);
149 to reset the whole document. Note. adding a read-only span currently clears the undo history of the editor, because existing undo events being partially nullified by read-only spans would corrupt the history (in the current implementation).
var myCodeMirror = CodeMirror(document.body);
150When set to true (default is false), adding this marker will create an event in the undo history that can be individually undone (clearing the marker).
var myCodeMirror = CodeMirror(document.body);
151Can be used to specify an extra CSS class to be applied to the leftmost span that is part of the marker.
var myCodeMirror = CodeMirror(document.body);
152Equivalent to
var myCodeMirror = CodeMirror(document.body);
153, but for the rightmost span.
var myCodeMirror = CodeMirror(document.body);
154A string of CSS to be applied to the covered text. For example
var myCodeMirror = CodeMirror(document.body);
155.
var myCodeMirror = CodeMirror(document.body);
156When given, add the attributes in the given object to the elements created for the marked text. Adding
var myCodeMirror = CodeMirror(document.body);
157 or
var myCodeMirror = CodeMirror(document.body);
158 attributes this way is not supported.
var myCodeMirror = CodeMirror(document.body);
159When the target document is linked to other documents, you can set
var myCodeMirror = CodeMirror(document.body);
160 to true to make the marker appear in all documents. By default, a marker appears only in its target document. The method will return an object that represents the marker (with constructor
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
16), which exposes three methods.
var myCodeMirror = CodeMirror(document.body);
162, to remove the mark,
var myCodeMirror = CodeMirror(document.body);
163, which returns a
var myCodeMirror = CodeMirror(document.body);
164 object (both holding document positions), indicating the current position of the marked range, or
var myCodeMirror = CodeMirror(document.body);
165 if the marker is no longer in the document, and finally
var myCodeMirror = CodeMirror(document.body);
166, which you can call if you've done something that might change the size of the marker (for example changing the content of a
var myCodeMirror = CodeMirror(document.body);
147 node), and want to cheaply update the display.
var myCodeMirror = CodeMirror(document.body);
168Inserts a bookmark, a handle that follows the text around it as it is being edited, at the given position. A bookmark has two methods
var myCodeMirror = CodeMirror(document.body);
169 and
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
22. The first returns the current position of the bookmark, if it is still in the document, and the second explicitly removes the bookmark. The options argument is optional. If given, the following properties are recognized.
var myCodeMirror = CodeMirror(document.body);
171Can be used to display a DOM node at the current location of the bookmark (analogous to the
var myCodeMirror = CodeMirror(document.body);
147 option to
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
17).
var myCodeMirror = CodeMirror(document.body);
174By default, text typed when the cursor is on top of the bookmark will end up to the right of the bookmark. Set this option to true to make it go to the left instead.
var myCodeMirror = CodeMirror(document.body);
159See the corresponding option to
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
17.
var myCodeMirror = CodeMirror(document.body);
146As with
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
17, this determines whether mouse events on the widget inserted for this bookmark are handled by CodeMirror. The default is false.
var myCodeMirror = CodeMirror(document.body);
179Returns an array of all the bookmarks and marked ranges found between the given positions (non-inclusive).
var myCodeMirror = CodeMirror(document.body);
180Returns an array of all the bookmarks and marked ranges present at the given position.
var myCodeMirror = CodeMirror(document.body);
181Returns an array containing all marked ranges in the document

Widget, gutter, and decoration methods

var myCodeMirror = CodeMirror(document.body);
182Sets the gutter marker for the given gutter (identified by its CSS class, see the
var myCodeMirror = CodeMirror(document.body);
183 option) to the given value. Value can be either
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0, to clear the marker, or a DOM element, to set it. The DOM element will be shown in the specified gutter next to the specified line.
var myCodeMirror = CodeMirror(document.body);
185Remove all gutter markers in the gutter with the given ID.
var myCodeMirror = CodeMirror(document.body);
186Set a CSS class name for the given line.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
34 can be a number or a line handle.
var myCodeMirror = CodeMirror(document.body);
188 determines to which element this class should be applied, can be one of
var myCodeMirror = CodeMirror(document.body);
189 (the text element, which lies in front of the selection),
var myCodeMirror = CodeMirror(document.body);
190 (a background element that will be behind the selection),
var myCodeMirror = CodeMirror(document.body);
191 (the line's gutter space), or
var myCodeMirror = CodeMirror(document.body);
192 (the wrapper node that wraps all of the line's elements, including gutter elements).
var myCodeMirror = CodeMirror(document.body);
157 should be the name of the class to apply.
var myCodeMirror = CodeMirror(document.body);
194Remove a CSS class from a line.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
34 can be a line handle or number.
var myCodeMirror = CodeMirror(document.body);
188 should be one of
var myCodeMirror = CodeMirror(document.body);
189,
var myCodeMirror = CodeMirror(document.body);
190, or
var myCodeMirror = CodeMirror(document.body);
192 (see
var myCodeMirror = CodeMirror(document.body);
400).
var myCodeMirror = CodeMirror(document.body);
157 can be left off to remove all classes for the specified node, or be a string to remove only a specific class.
var myCodeMirror = CodeMirror(document.body);
402Returns the line number, text content, and marker status of the given line, which can be either a number or a line handle. The returned object has the structure
var myCodeMirror = CodeMirror(document.body);
403, where
var myCodeMirror = CodeMirror(document.body);
404 is an object mapping gutter IDs to marker elements, and
var myCodeMirror = CodeMirror(document.body);
405 is an array of line widgets attached to this line, and the various class properties refer to classes added with
var myCodeMirror = CodeMirror(document.body);
400.
var myCodeMirror = CodeMirror(document.body);
407Puts
var myCodeMirror = CodeMirror(document.body);
408, which should be an absolutely positioned DOM node, into the editor, positioned right below the given
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55 position. When
var myCodeMirror = CodeMirror(document.body);
410 is true, the editor will ensure that the entire node is visible (if possible). To remove the widget again, simply use DOM methods (move it somewhere else, or call
var myCodeMirror = CodeMirror(document.body);
411 on its parent).
var myCodeMirror = CodeMirror(document.body);
412Adds a line widget, an element shown below a line, spanning the whole of the editor's width, and moving the lines below it downwards.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
34 should be either an integer or a line handle, and
var myCodeMirror = CodeMirror(document.body);
408 should be a DOM node, which will be displayed below the given line.
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
48, when given, should be an object that configures the behavior of the widget. The following options are supported (all default to false).
var myCodeMirror = CodeMirror(document.body);
416Whether the widget should cover the gutter.
var myCodeMirror = CodeMirror(document.body);
417Whether the widget should stay fixed in the face of horizontal scrolling.
var myCodeMirror = CodeMirror(document.body);
418Causes the widget to be placed above instead of below the text of the line.
var myCodeMirror = CodeMirror(document.body);
146Determines whether the editor will capture mouse and drag events occurring in this widget. Default is false—the events will be left alone for the default browser handler, or specific handlers on the widget, to capture.
var myCodeMirror = CodeMirror(document.body);
420Theo mặc định, tiện ích được thêm bên dưới các tiện ích khác cho dòng. This option can be used to place it at a different position (zero for the top, N to put it after the Nth other widget). Note that this only has effect once, when the widget is created.
var myCodeMirror = CodeMirror(document.body);
129Add an extra CSS class name to the wrapper element created for the widget. Note that the widget node will become a descendant of nodes with CodeMirror-specific CSS classes, and those classes might in some cases affect it. This method returns an object that represents the widget placement. It'll have a
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
34 property pointing at the line handle that it is associated with, and the following methods.
var myCodeMirror = CodeMirror(document.body);
162Removes the widget.
var myCodeMirror = CodeMirror(document.body);
166Call this if you made some change to the widget's DOM node that might affect its height. It'll force CodeMirror to update the height of the line that contains the widget

Sizing, scrolling and positioning methods

var myCodeMirror = CodeMirror(document.body);
425Programmatically set the size of the editor (overriding the applicable CSS rules).
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
75 and
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
15 can be either numbers (interpreted as pixels) or CSS units (
var myCodeMirror = CodeMirror(document.body);
428, for example). You can pass
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0 for either of them to indicate that that dimension should not be changed.
var myCodeMirror = CodeMirror(document.body);
430Scroll the editor to a given (pixel) position. Both arguments may be left as
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0 or
var myCodeMirror = CodeMirror(document.body);
165 to have no effect.
var myCodeMirror = CodeMirror(document.body);
433Get an
var myCodeMirror = CodeMirror(document.body);
434 object that represents the current scroll position, the size of the scrollable area, and the size of the visible area (minus scrollbars).
var myCodeMirror = CodeMirror(document.body);
435Scrolls the given position into view.
var myCodeMirror = CodeMirror(document.body);
436 may be
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0 to scroll the cursor into view, a
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55 position to scroll a character into view, a
var myCodeMirror = CodeMirror(document.body);
439 pixel range (in editor-local coordinates), or a range
var myCodeMirror = CodeMirror(document.body);
164 containing either two character positions or two pixel squares. The
var myCodeMirror = CodeMirror(document.body);
441 parameter is optional. When given, it indicates the amount of vertical pixels around the given area that should be made visible as well.
var myCodeMirror = CodeMirror(document.body);
442Returns an
var myCodeMirror = CodeMirror(document.body);
443 object containing the coordinates of the cursor position. If
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
84 is
var myCodeMirror = CodeMirror(document.body);
445, they will be relative to the top-left corner of the editable document. If it is
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
68 or not given, they are relative to the top-left corner of the page. If
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
84 is
var myCodeMirror = CodeMirror(document.body);
448, the coordinates are relative to the top-left corner of the currently visible (scrolled) window.
var myCodeMirror = CodeMirror(document.body);
188 can be a boolean indicating whether you want the start (
var myCodeMirror = CodeMirror(document.body);
13) or the end (
var myCodeMirror = CodeMirror(document.body);
12) of the selection, or, if a
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55 object is given, it specifies the precise position at which you want to measure.
var myCodeMirror = CodeMirror(document.body);
453Returns the position and dimensions of an arbitrary character.
var myCodeMirror = CodeMirror(document.body);
454 should be a
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55 object. This differs from
var myCodeMirror = CodeMirror(document.body);
456 in that it'll give the size of the whole character, rather than just the position that the cursor would have when it would sit at that position.
var myCodeMirror = CodeMirror(document.body);
457Given an
var myCodeMirror = CodeMirror(document.body);
458 object (e. g. coordinates of a mouse event) returns the
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55 position that corresponds to it. The optional
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
84 parameter determines relative to what the coordinates are interpreted. It may be
var myCodeMirror = CodeMirror(document.body);
448,
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
68 (the default), or
var myCodeMirror = CodeMirror(document.body);
445.
var myCodeMirror = CodeMirror(document.body);
464Computes the line at the given pixel height.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
84 can be one of the same strings that
var myCodeMirror = CodeMirror(document.body);
466 accepts.
var myCodeMirror = CodeMirror(document.body);
467Computes the height of the top of a line, in the coordinate system specified by
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
84 (see
var myCodeMirror = CodeMirror(document.body);
466), which defaults to
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
68. When a line below the bottom of the document is specified, the returned value is the bottom of the last line in the document. By default, the position of the actual text is returned. If `includeWidgets` is true and the line has line widgets, the position above the first line widget is returned.
var myCodeMirror = CodeMirror(document.body);
471Returns the line height of the default font for the editor.
var myCodeMirror = CodeMirror(document.body);
472Returns the pixel width of an 'x' in the default font for the editor. (Note that for non-monospace fonts, this is mostly useless, and even for monospace fonts, non-ascii characters might have a different width).
var myCodeMirror = CodeMirror(document.body);
473Returns a
var myCodeMirror = CodeMirror(document.body);
164 object indicating the start (inclusive) and end (exclusive) of the currently rendered part of the document. In big documents, when most content is scrolled out of view, CodeMirror will only render the visible part, and a margin around it. See also the
var myCodeMirror = CodeMirror(document.body);
475 event.
var myCodeMirror = CodeMirror(document.body);
476If 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. Xem thêm addon autorefresh

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

var myCodeMirror = CodeMirror(document.body);
477Gets the (outer) mode object for the editor. Note that this is distinct from
var myCodeMirror = CodeMirror(document.body);
478, which gives you the mode specification, rather than the resolved, instantiated mode object.
var myCodeMirror = CodeMirror(document.body);
479Gets the inner mode at a given position. This will return the same as
var myCodeMirror = CodeMirror(document.body);
480 for simple modes, but will return an inner mode for nesting modes (such as
var myCodeMirror = CodeMirror(document.body);
481).
var myCodeMirror = CodeMirror(document.body);
482Retrieves 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.
var myCodeMirror = CodeMirror(document.body);
484The character (on the given line) at which the token starts.
var myCodeMirror = CodeMirror(document.body);
485The character at which the token ends.
var myCodeMirror = CodeMirror(document.body);
486The token's string.
var myCodeMirror = CodeMirror(document.body);
487The token type the mode assigned to the token, such as
var myCodeMirror = CodeMirror(document.body);
488 or
var myCodeMirror = CodeMirror(document.body);
489 (may also be null).
var myCodeMirror = CodeMirror(document.body);
490The mode's state at the end of this token. If
var myCodeMirror = CodeMirror(document.body);
491 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.
var myCodeMirror = CodeMirror(document.body);
492This is similar to
var myCodeMirror = CodeMirror(document.body);
493, but collects all tokens for a given line into an array. It is much cheaper than repeatedly calling
var myCodeMirror = CodeMirror(document.body);
493, which re-parses the part of the line before the token for every call.
var myCodeMirror = CodeMirror(document.body);
495This is a (much) cheaper version of
var myCodeMirror = CodeMirror(document.body);
493 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.
var myCodeMirror = CodeMirror(document.body);
498Fetch 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
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
700), 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
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
702 property and finally the mode's name are used. For example, the JavaScript mode has a property
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
703 containing
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
704. When the
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
705 addon is loaded, that defines a helper named
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
706 in the
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
703 namespace. This is then used by the
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
708 addon to figure out that it can use that folding function to fold JavaScript code. When any 'global' 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.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
709Returns the first applicable helper value. See
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
710.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
711Returns 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.
var myCodeMirror = CodeMirror(document.body);
491 is defined as in
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
713

Miscellaneous methods

var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
714CodeMirror 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. Nó sẽ gọi hàm, đệm tất cả các thay đổi và chỉ thực hiện cập nhật đắt tiền sau khi hàm trả về. This can be a lot faster. The return value from this method will be the return value of your function.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
715
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
716In normal circumstances, use the above
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
717 method. But if you want to buffer operations happening asynchronously, or that can't all be wrapped in a callback function, you can call
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
718 to tell CodeMirror to start buffering changes, and
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
719 to actually render all the updates. Be careful. if you use this API and forget to call
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
719, the editor will just never update.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
721Adjust the indentation of the given line. The second argument (which defaults to
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
722) may be one of.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
723Base indentation on the indentation of the previous line.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
724Use the mode's smart indentation if available, behave like
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
725 otherwise.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
726Increase the indentation of the line by one indent unit.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
727Reduce the indentation of the line.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
728Add (positive number) or reduce (negative number) the indentation by the given amount of spaces.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
729Switches between overwrite and normal insert mode (when not given an argument), or sets the overwrite mode to a specific state (when given an argument).
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
730Tells you whether the editor's content can be edited by the user.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
731Returns the preferred line separator string for this document, as per the option 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.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
734Runs the command with the given name on the editor.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
735Calculates and returns a
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
55 object for a zero-based
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
737 who's value is relative to the start of the editor's text. If the
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
737 is out of range of the text then the returned object is clipped to start or end of the text respectively.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
739The reverse of
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
740.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
741Give the editor focus.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
742Allow the given string to be translated with the
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
743 option.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
744Returns the input field for the editor. Will be a textarea or an editable div, depending on the value of the
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
745 option.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
746Returns the DOM node that represents the editor, and controls its size. Remove this from your tree to delete an editor instance.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
747Returns the DOM node that is responsible for the scrolling of the editor.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
748Fetches the DOM node that contains the editor gutters

Static properties

The

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

var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
750It contains a string that indicates the version of the library. This is a triple of integers
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
751, where
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
752 is zero for releases, and something else (usually one) for dev snapshots.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
753This 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.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
754Copy the content of the editor into the textarea.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
755Remove 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.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
756Returns the textarea that the instance was based on.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
757An object containing default values for all options. You can assign to its properties to modify defaults (though this won't affect editors that have already been created).
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
758If you want to define extra methods in terms of the CodeMirror API, it is possible to use
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
759. This will cause the given value (usually a method) to be added to all CodeMirror instances created from then on.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
760Like
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
759, but the method will be added to the interface for
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
762 objects instead.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
763Similarly,
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
764 can be used to define new options for CodeMirror. The
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
765 will be called with the editor instance and the new value when an editor is initialized, and whenever the option is modified through
var myCodeMirror = CodeMirror(document.body);
97.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
767If your extension just needs to run some code whenever a CodeMirror instance is initialized, use
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
768. 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.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
769Registers 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
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
774, the value
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
775 will point to
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
776.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
777Acts like
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
700, but also registers this helper as 'global', meaning that it will be included by
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
710 whenever the given
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
780 returns true when called with the local mode and editor.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
781A 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 mặc định là null, nhưng có thể được đặt thành
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 để làm cho vị trí liên kết rõ ràng với ký tự trước hoặc sau nó.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
785Utility 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 event handlers). The returned position will be the end of the changed range, after the change is applied.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
789Find the column position at a given string index using a given tabsize

Addons

The

var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
790 directory in the distribution contains a number of reusable components that implement extra editor functionality (on top of extension functions like
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
764,
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
759, and
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
700). In brief, they are

var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
794Provides a very simple way to query users for text input. Adds the
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
795 method to CodeMirror instances, which can be called with an HTML fragment or a detached DOM node that provides the prompt (should include an
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
796 or
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
797 tag), and a callback function that is called when the user presses enter. It returns a function
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
798 which, if called, will close the dialog immediately.
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
799 takes the following options.
var myCodeMirror = CodeMirror(document.body);
13600If true, the dialog will be closed when the user presses enter in the input. Defaults to
var myCodeMirror = CodeMirror(document.body);
13.
var myCodeMirror = CodeMirror(document.body);
13602Determines whether the dialog is closed when it loses focus. Defaults to
var myCodeMirror = CodeMirror(document.body);
13.
var myCodeMirror = CodeMirror(document.body);
13604An event handler that will be called whenever
var myCodeMirror = CodeMirror(document.body);
70 fires in the dialog's input. If your callback returns
var myCodeMirror = CodeMirror(document.body);
13, the dialog will not do any further processing of the event.
var myCodeMirror = CodeMirror(document.body);
13607Same as
var myCodeMirror = CodeMirror(document.body);
13608 but for the
var myCodeMirror = CodeMirror(document.body);
13609 event.
var myCodeMirror = CodeMirror(document.body);
13610Same as
var myCodeMirror = CodeMirror(document.body);
13608 but for the
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
796 event.
var myCodeMirror = CodeMirror(document.body);
13613. A callback that will be called after the dialog has been closed and removed from the DOM. No return value

Also adds an

var myCodeMirror = CodeMirror(document.body);
13614 function that simply shows an HTML fragment as a notification at the top of the editor. It takes a single option.
var myCodeMirror = CodeMirror(document.body);
13615, the amount of time after which the notification will be automatically closed. If
var myCodeMirror = CodeMirror(document.body);
13615 is zero, the dialog will not be closed automatically

Depends on

var myCodeMirror = CodeMirror(document.body);
13617

var myCodeMirror = CodeMirror(document.body);
13618Adds the
var myCodeMirror = CodeMirror(document.body);
13619 method to CodeMirror instances, which can be used to implement search/replace functionality.
var myCodeMirror = CodeMirror(document.body);
13620 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.
var myCodeMirror = CodeMirror(document.body);
13624
var myCodeMirror = CodeMirror(document.body);
13625Search forward or backward from the current position. The return value indicates whether a match was found. If matching a regular expression, the return value will be the array returned by the
var myCodeMirror = CodeMirror(document.body);
13626 method, in case you want to extract matched groups.
var myCodeMirror = CodeMirror(document.body);
13627
var myCodeMirror = CodeMirror(document.body);
13628These are only valid when the last call to
var myCodeMirror = CodeMirror(document.body);
13629 or
var myCodeMirror = CodeMirror(document.body);
13630 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.
var myCodeMirror = CodeMirror(document.body);
13632Replaces the currently found match with the given text and adjusts the cursor position to reflect the replacement.
var myCodeMirror = CodeMirror(document.body);
13633Implements 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
var myCodeMirror = CodeMirror(document.body);
13634, and will make use of
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
799 when available to make prompting for search queries less ugly.
var myCodeMirror = CodeMirror(document.body);
13636Implements a
var myCodeMirror = CodeMirror(document.body);
13637 command and binding
var myCodeMirror = CodeMirror(document.body);
13638 to it. Accepts
var myCodeMirror = CodeMirror(document.body);
13639,
var myCodeMirror = CodeMirror(document.body);
13640,
var myCodeMirror = CodeMirror(document.body);
13641,
var myCodeMirror = CodeMirror(document.body);
13642 and
var myCodeMirror = CodeMirror(document.body);
13643 formats. This will make use of
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
799 when available to make prompting for line number neater. Demo available here.
var myCodeMirror = CodeMirror(document.body);
13645Thêm một phương thức
var myCodeMirror = CodeMirror(document.body);
13646 vào các phiên bản trình soạn thảo, phương thức này sẽ được cung cấp một truy vấn (chuỗi hoặc biểu thức chính quy), tùy chọn cờ phân biệt chữ hoa chữ thường (chỉ áp dụng cho chuỗi) và tùy chọn tên lớp (mặc định là
var myCodeMirror = CodeMirror(document.body);
13647) làm đối số. When called, matches of the given query will be displayed on the editor's vertical scrollbar. The method returns an object with a
var myCodeMirror = CodeMirror(document.body);
13648 method that can be called to remove the matches. Depends on the
var myCodeMirror = CodeMirror(document.body);
13649 addon, and the
var myCodeMirror = CodeMirror(document.body);
13650 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
var myCodeMirror = CodeMirror(document.body);
13651 addon to make sure of this. If this addon is loaded, the
var myCodeMirror = CodeMirror(document.body);
13652 addon will automatically use it.
var myCodeMirror = CodeMirror(document.body);
13653Defines an option
var myCodeMirror = CodeMirror(document.body);
13654 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
var myCodeMirror = CodeMirror(document.body);
13654 that forces this to happen once, and a method
var myCodeMirror = CodeMirror(document.body);
13656 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.
var myCodeMirror = CodeMirror(document.body);
13657Only use the character after the start position, never the one before it.
var myCodeMirror = CodeMirror(document.body);
13658Also highlight pairs of non-matching as well as stray brackets. Enabled by default.
var myCodeMirror = CodeMirror(document.body);
13659Causes only matches where both brackets are at the same side of the start position to be considered.
var myCodeMirror = CodeMirror(document.body);
13660Stop after scanning this amount of lines without a successful match. Defaults to 1000.
var myCodeMirror = CodeMirror(document.body);
13661Ignore lines longer than this. Defaults to 10000.
var myCodeMirror = CodeMirror(document.body);
13662Don't highlight a bracket in a line longer than this. Defaults to 1000.
var myCodeMirror = CodeMirror(document.body);
13663Defines an option
var myCodeMirror = CodeMirror(document.body);
13664 that will auto-close brackets and quotes when typed. By default, it'll auto-close
var myCodeMirror = CodeMirror(document.body);
13665, but you can pass it a string similar to that (containing pairs of matching characters), or an object with
var myCodeMirror = CodeMirror(document.body);
13666 and optionally
var myCodeMirror = CodeMirror(document.body);
13667 properties to customize it.
var myCodeMirror = CodeMirror(document.body);
13667 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
var myCodeMirror = CodeMirror(document.body);
13669 property, that overrides the configuration given in the option. But you can add an
var myCodeMirror = CodeMirror(document.body);
13670 property with a truthy value to override mode-specific configuration. Demo here.
var myCodeMirror = CodeMirror(document.body);
13671Defines an option
var myCodeMirror = CodeMirror(document.body);
13672 that, when enabled, will cause the tags around the cursor to be highlighted (using the
var myCodeMirror = CodeMirror(document.body);
13673 class). Also defines a command
var myCodeMirror = CodeMirror(document.body);
13674, which you can bind a key to in order to jump to the tag matching the one under the cursor. Depends on the
var myCodeMirror = CodeMirror(document.body);
13675 addon. Demo here.
var myCodeMirror = CodeMirror(document.body);
13676Adds an option
var myCodeMirror = CodeMirror(document.body);
13677 which, when enabled, adds the CSS class
var myCodeMirror = CodeMirror(document.body);
13678 to stretches of whitespace at the end of lines. The demo has a nice squiggly underline style for this class.
var myCodeMirror = CodeMirror(document.body);
13679Defines an
var myCodeMirror = CodeMirror(document.body);
13680 option that will auto-close XML tags when '
var myCodeMirror = CodeMirror(document.body);
13681' or '
var myCodeMirror = CodeMirror(document.body);
13682' is typed, and a
var myCodeMirror = CodeMirror(document.body);
13683 command that closes the nearest open tag. Depends on the
var myCodeMirror = CodeMirror(document.body);
13684 addon. See the demo.
var myCodeMirror = CodeMirror(document.body);
13685Markdown specific. Defines a
var myCodeMirror = CodeMirror(document.body);
13686 command that can be bound to
var myCodeMirror = CodeMirror(document.body);
13687 to automatically insert the leading characters for continuing a list. See the Markdown mode demo.
var myCodeMirror = CodeMirror(document.body);
13688Addon for commenting and uncommenting code. Adds four methods to CodeMirror instances.
var myCodeMirror = CodeMirror(document.body);
13689Tries to uncomment the current selection, and if that fails, line-comments it.
var myCodeMirror = CodeMirror(document.body);
13690Set the lines in the given range to be line comments. Will fall back to
var myCodeMirror = CodeMirror(document.body);
13691 when no line comment style is defined for the mode.
var myCodeMirror = CodeMirror(document.body);
13692Wrap the code in the given range in a block comment. Will fall back to
var myCodeMirror = CodeMirror(document.body);
13693 when no block comment style is defined for the mode.
var myCodeMirror = CodeMirror(document.body);
13694Try to uncomment the given range. Trả về
var myCodeMirror = CodeMirror(document.body);
13 nếu phạm vi nhận xét được tìm thấy và bị xóa, ngược lại là
var myCodeMirror = CodeMirror(document.body);
12. The
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
48 object accepted by these methods may have the following properties.
var myCodeMirror = CodeMirror(document.body);
13698Override the comment string properties of the mode with custom comment strings.
var myCodeMirror = CodeMirror(document.body);
13699A string that will be inserted after opening and leading markers, and before closing comment markers. Defaults to a single space.
var myCodeMirror = CodeMirror(document.body);
13700Whether, when adding line comments, to also comment lines that contain only whitespace.
var myCodeMirror = CodeMirror(document.body);
13701When 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.
var myCodeMirror = CodeMirror(document.body);
13702When block commenting, this controls whether the whole lines are indented, or only the precise range that is given. Defaults to
var myCodeMirror = CodeMirror(document.body);
13. The addon also defines a
var myCodeMirror = CodeMirror(document.body);
13704 command, which is a shorthand command for calling
var myCodeMirror = CodeMirror(document.body);
13704 with no options.
var myCodeMirror = CodeMirror(document.body);
13706Helps with code folding. Adds a
var myCodeMirror = CodeMirror(document.body);
13707 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
var myCodeMirror = CodeMirror(document.body);
13708), and as second optional argument either a range-finder function, or an options object, supporting the following properties.
var myCodeMirror = CodeMirror(document.body);
13709The function that is used to find foldable ranges. If this is not directly passed, it will default to
var myCodeMirror = CodeMirror(document.body);
13710, which uses
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
710 with a
var myCodeMirror = CodeMirror(document.body);
13712 type to find folding functions appropriate for the local mode. There are files in the
var myCodeMirror = CodeMirror(document.body);
13713 directory providing
var myCodeMirror = CodeMirror(document.body);
13714, which finds blocks in brace languages (JavaScript, C, Java, etc),
var myCodeMirror = CodeMirror(document.body);
13715, for languages where indentation determines block structure (Python, Haskell), and
var myCodeMirror = CodeMirror(document.body);
13716, for XML-style languages, and
var myCodeMirror = CodeMirror(document.body);
13717, for folding comment blocks.
var myCodeMirror = CodeMirror(document.body);
13718The widget to show for folded ranges. Can be either a string, in which case it'll become a span with class
var myCodeMirror = CodeMirror(document.body);
13719, 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.
var myCodeMirror = CodeMirror(document.body);
13720When 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.
var myCodeMirror = CodeMirror(document.body);
13721The 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.
var myCodeMirror = CodeMirror(document.body);
13722Provides an option
var myCodeMirror = CodeMirror(document.body);
13723, which can be used to create a gutter with markers indicating the blocks that can be folded. Create a gutter using the
var myCodeMirror = CodeMirror(document.body);
183 option, giving it the class
var myCodeMirror = CodeMirror(document.body);
13725 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.
var myCodeMirror = CodeMirror(document.body);
13726 . The option can be either set to
var myCodeMirror = CodeMirror(document.body);
13, or an object containing the following optional option fields.
var myCodeMirror = CodeMirror(document.body);
13728The CSS class of the gutter. Defaults to
var myCodeMirror = CodeMirror(document.body);
13729. You will have to style this yourself to give it a width (and possibly a background). See the default gutter style rules above.
var myCodeMirror = CodeMirror(document.body);
13730A CSS class or DOM element to be used as the marker for open, foldable blocks. Defaults to
var myCodeMirror = CodeMirror(document.body);
13731.
var myCodeMirror = CodeMirror(document.body);
13732A CSS class or DOM element to be used as the marker for folded blocks. Defaults to
var myCodeMirror = CodeMirror(document.body);
13733.
var myCodeMirror = CodeMirror(document.body);
13709The range-finder function to use when determining whether something can be folded. When not given,
var myCodeMirror = CodeMirror(document.body);
13710 will be used as default. The
var myCodeMirror = CodeMirror(document.body);
13736 editor option can be set to an object to provide an editor-wide default configuration. Demo here.
var myCodeMirror = CodeMirror(document.body);
13737Can 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
var myCodeMirror = CodeMirror(document.body);
13738 for an example of using the latter).
var myCodeMirror = CodeMirror(document.body);
13739Provides a convenient way to syntax-highlight code snippets in a webpage. Depends on the
var myCodeMirror = CodeMirror(document.body);
13740 addon (or its standalone variant). Provides a
var myCodeMirror = CodeMirror(document.body);
13741 function that can be called with an array (or other array-ish collection) of DOM nodes that represent the code snippets. By default, it'll get all
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
31 tags. Will read the
var myCodeMirror = CodeMirror(document.body);
13743 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.
var myCodeMirror = CodeMirror(document.body);
13744Mode 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
var myCodeMirror = CodeMirror(document.body);
13745, which is used to create such a mode. See this demo for a detailed example.
var myCodeMirror = CodeMirror(document.body);
13746Mode combinator that can be used to easily 'multiplex' between several modes. Defines
var myCodeMirror = CodeMirror(document.body);
13747 which, when given as first argument a mode object, and as other arguments any number of
var myCodeMirror = CodeMirror(document.body);
13748 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
var myCodeMirror = CodeMirror(document.body);
13749 fields of the passed objects. When in a sub-mode, it will go back to the top mode again when the
var myCodeMirror = CodeMirror(document.body);
13750 string is encountered. Pass
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
52 for
var myCodeMirror = CodeMirror(document.body);
13749 or
var myCodeMirror = CodeMirror(document.body);
13750 if you want to switch on a blank line
  • Khi
    var myCodeMirror = CodeMirror(document.body);
    13754 được chỉ định, đó 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ư
    var myCodeMirror = CodeMirror(document.body);
    13755 trên mã thông báo mở và
    var myCodeMirror = CodeMirror(document.body);
    13756 trên mã thông báo đóng)
  • When
    var myCodeMirror = CodeMirror(document.body);
    13757 is specified, it will be the token style added for each inner mode token
  • When
    var myCodeMirror = CodeMirror(document.body);
    13758 is true, the content of the delimiters will also be passed to the inner mode. (And
    var myCodeMirror = CodeMirror(document.body);
    13754 is ignored. )
The outer mode will not see the content between the delimiters. See this demo for an example.
var myCodeMirror = CodeMirror(document.body);
13760Provides a framework for showing autocompletion hints. Defines
var myCodeMirror = CodeMirror(document.body);
13761, 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
var myCodeMirror = CodeMirror(document.body);
13762 option). This function takes an editor instance and an options object, and returns a
var myCodeMirror = CodeMirror(document.body);
13763 object, where
var myCodeMirror = CodeMirror(document.body);
13764 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
var myCodeMirror = CodeMirror(document.body);
13768 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
var myCodeMirror = CodeMirror(document.body);
13769, which calls
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
710 with the
var myCodeMirror = CodeMirror(document.body);
13771 type to find applicable hinting functions, and tries them one by one. If that fails, it looks for a
var myCodeMirror = CodeMirror(document.body);
13772 helper to fetch a list of completeable words for the mode, and uses
var myCodeMirror = CodeMirror(document.body);
13773 to complete from those. When completions aren't simple strings, they should be objects with the following properties.
var myCodeMirror = CodeMirror(document.body);
13774The completion text. This is the only required property.
var myCodeMirror = CodeMirror(document.body);
13775The text that should be displayed in the menu.
var myCodeMirror = CodeMirror(document.body);
129A CSS class name to apply to the completion's line in the menu.
var myCodeMirror = CodeMirror(document.body);
13777A method used to create the DOM structure for showing the completion by appending it to its first argument.
var myCodeMirror = CodeMirror(document.body);
13778A method used to actually apply the completion, instead of the default behavior.
var myCodeMirror = CodeMirror(document.body);
13779Optional
var myCodeMirror = CodeMirror(document.body);
45 position that will be used by
var myCodeMirror = CodeMirror(document.body);
13781 instead of the global one passed with the full list of completions.
var myCodeMirror = CodeMirror(document.body);
13782Optional
var myCodeMirror = CodeMirror(document.body);
46 position that will be used by
var myCodeMirror = CodeMirror(document.body);
13781 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
var myCodeMirror = CodeMirror(document.body);
13785, or provided by setting an
var myCodeMirror = CodeMirror(document.body);
13786 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.
var myCodeMirror = CodeMirror(document.body);
13787A hinting function, as specified above. It is possible to set the
var myCodeMirror = CodeMirror(document.body);
13788 property on a hinting function to true, in which case it will be called with arguments
var myCodeMirror = CodeMirror(document.body);
13789, 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
var myCodeMirror = CodeMirror(document.body);
13790 property with a truthy value to indicate that it supports selections.
var myCodeMirror = CodeMirror(document.body);
13791Determines whether, when only a single completion is available, it is completed without showing the dialog. Defaults to true.
var myCodeMirror = CodeMirror(document.body);
13792Whether the pop-up should be horizontally aligned with the start of the word (true, default), or with the cursor (false).
var myCodeMirror = CodeMirror(document.body);
13793A regular expression object used to match characters which cause the pop up to be closed (default.
var myCodeMirror = CodeMirror(document.body);
13794). If the user types one of these characters, the pop up will close, and the
var myCodeMirror = CodeMirror(document.body);
13795 event is fired on the editor instance.
var myCodeMirror = CodeMirror(document.body);
13796When enabled (which is the default), the pop-up will close when the editor is unfocused.
var myCodeMirror = CodeMirror(document.body);
13797Whether 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.
var myCodeMirror = CodeMirror(document.body);
13798Can 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,
var myCodeMirror = CodeMirror(document.body);
13781, 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);
009Giống như
var myCodeMirror = CodeMirror(document.body);
010 ở trên, nhưng các ràng buộc sẽ được thêm vào tập hợp các ràng buộc mặc định, thay vì thay thế chúng.
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 xml-hint 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),
var myCodeMirror = CodeMirror(document.body);
158, 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
var myCodeMirror = CodeMirror(document.body);
13 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). Xác định tùy chọn
var myCodeMirror = CodeMirror(document.body);
062 có thể được đặt thành nguồn chú thích (ví dụ:
var myCodeMirror = CodeMirror(document.body);
063), thành đối tượng tùy chọn (trong trường hợp đó, trường
var myCodeMirror = CodeMirror(document.body);
064 được sử dụng làm nguồn chú thích) hoặc đơn giản là
var myCodeMirror = CodeMirror(document.body);
13. When no annotation source is specified,
var myCodeMirror = CodeMirror(document.body);
066 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
var myCodeMirror = CodeMirror(document.body);
13788 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). See the demo.
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);
087Defines a
var myCodeMirror = CodeMirror(document.body);
088 function that will try to load a given mode and call the callback when it succeeded.
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
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
790. 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
var myCodeMirror = CodeMirror(document.body);
13).
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
var myCodeMirror = CodeMirror(document.body);
13, 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
var myCodeMirror = CodeMirror(document.body);
121 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
var myCodeMirror = CodeMirror(document.body);
127 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
var myCodeMirror = CodeMirror(document.body);
13648 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. trình diễn ở đây.
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
var myCodeMirror = CodeMirror(document.body);
13648 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
var myCodeMirror = CodeMirror(document.body);
454 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. A demo of the addon is available here.
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
var myCodeMirror = CodeMirror(document.body);
1 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);
179Đặt kiểu được sử dụng để kết nối các đoạn mã đã thay đổi. 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
var myCodeMirror = CodeMirror(document.body);
400 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
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
84 option), returns a mode object

Typically, you should use this second argument to

var myCodeMirror = CodeMirror(document.body);
194 as your module scope function (modes should not leak anything into the global scope. ), i. e. write your whole mode inside this function

The main responsibility of a mode script is parsing the content of the editor. Depending on the language and the amount of functionality desired, this can be done in really easy or extremely complicated ways. Some parsers can be stateless, meaning that they look at one element (token) of the code at a time, with no memory of what came before. Most, however, will need to remember something. 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
var myCodeMirror = CodeMirror(document.body);
489. 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
var myCodeMirror = CodeMirror(document.body);
400 method does—styling the
var myCodeMirror = CodeMirror(document.body);
189 in the simple case, and the
var myCodeMirror = CodeMirror(document.body);
190 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. Cũng trả về
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
0 khi không còn ký tự nào nữa.
var myCodeMirror = CodeMirror(document.body);
215
var myCodeMirror = CodeMirror(document.body);
13626 có thể là một ký tự, một biểu thức chính quy hoặc một hàm nhận một ký tự và trả về một giá trị boolean. Nếu ký tự tiếp theo trong luồng 'khớp' với đối số đã cho, nó sẽ được sử dụng và trả về. Mặt khác,
var myCodeMirror = CodeMirror(document.body);
165 được trả về.
var myCodeMirror = CodeMirror(document.body);
218 Gọi liên tục
var myCodeMirror = CodeMirror(document.body);
219 với đối số đã cho, cho đến khi không thành công. Trả về true nếu bất kỳ ký tự nào bị ăn.
var myCodeMirror = CodeMirror(document.body);
220Phím tắt cho
var myCodeMirror = CodeMirror(document.body);
221 khi khớp với khoảng trắng.
var myCodeMirror = CodeMirror(document.body);
222Di chuyển vị trí đến cuối dòng.
var myCodeMirror = CodeMirror(document.body);
223Bỏ qua để bắt đầu lần xuất hiện tiếp theo của chuỗi đã cho, nếu được tìm thấy trên dòng hiện tại (không chuyển tiếp luồng nếu chuỗi không xuất hiện trên dòng). Trả về true nếu tìm thấy chuỗi.
var myCodeMirror = CodeMirror(document.body);
224
var myCodeMirror = CodeMirror(document.body);
225Hành động như một người có nhiều ký tự
var myCodeMirror = CodeMirror(document.body);
219—nếu
var myCodeMirror = CodeMirror(document.body);
227 là đúng hoặc không được cung cấp—hoặc xem trước không cập nhật vị trí phát trực tiếp—nếu là sai.
var myCodeMirror = CodeMirror(document.body);
228 có thể là một chuỗi hoặc một biểu thức chính quy bắt đầu bằng
var myCodeMirror = CodeMirror(document.body);
229. Khi nó là một chuỗi, thì có thể đặt
var myCodeMirror = CodeMirror(document.body);
230 thành true để khớp không phân biệt chữ hoa chữ thường. Khi khớp thành công một biểu thức chính quy, giá trị trả về sẽ là mảng được trả về bởi
var myCodeMirror = CodeMirror(document.body);
13626, trong trường hợp bạn cần trích xuất các nhóm đã khớp.
var myCodeMirror = CodeMirror(document.body);
232Sao lưu luồng
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
68 ký tự. Sao lưu nó xa hơn điểm bắt đầu của mã thông báo hiện tại sẽ khiến mọi thứ bị hỏng, vì vậy hãy cẩn thận.
var myCodeMirror = CodeMirror(document.body);
234Trả về cột (có tính đến các tab) tại đó mã thông báo hiện tại bắt đầu.
var myCodeMirror = CodeMirror(document.body);
235Cho bạn biết dòng hiện tại đã được thụt lề bao xa, trong khoảng trắng. Sửa các ký tự tab.
var myCodeMirror = CodeMirror(document.body);
236Nhận chuỗi giữa điểm bắt đầu của mã thông báo hiện tại và vị trí luồng hiện tại.
var myCodeMirror = CodeMirror(document.body);
237Lấy dòng
var myCodeMirror = CodeMirror(function(elt) {
  myTextArea.parentNode.replaceChild(elt, myTextArea);
}, {value: myTextArea.value});
68 (>0) sau dòng hiện tại, để quét trước qua các ranh giới dòng. Lưu ý rằng bạn muốn làm điều này một cách cẩn thận, vì nhìn xa về phía trước sẽ làm cho bộ nhớ đệm trạng thái chế độ kém hiệu quả hơn nhiều.
var myCodeMirror = CodeMirror(document.body);
239Các chế độ được thêm thông qua
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
92 (và chỉ những chế độ như vậy) mới có thể sử dụng phương pháp này để kiểm tra mã thông báo hiện tại do chế độ cơ bản tạo ra

Theo mặc định, các dòng trống chỉ bị bỏ qua khi mã hóa tài liệu. Đối với các ngôn ngữ có các dòng trống quan trọng, bạn có thể xác định một phương thức

var myCodeMirror = CodeMirror(document.body);
241 trên chế độ của mình. Phương thức này sẽ được gọi bất cứ khi nào một dòng trống được chuyển qua, để phương thức này có thể cập nhật trạng thái trình phân tích cú pháp

Bởi vì đối tượng trạng thái bị thay đổi và CodeMirror cần giữ các phiên bản hợp lệ của trạng thái xung quanh để nó có thể khởi động lại phân tích cú pháp ở bất kỳ dòng nào, các bản sao phải được tạo từ đối tượng trạng thái. Thuật toán mặc định được sử dụng là một đối tượng trạng thái mới được tạo, nhận tất cả các thuộc tính của đối tượng cũ. Bất kỳ thuộc tính nào chứa mảng đều nhận được một bản sao của các mảng này (vì mảng có xu hướng được sử dụng làm ngăn xếp có thể thay đổi). Khi điều này không đúng, ví dụ do một chế độ làm thay đổi các thuộc tính không phải mảng của đối tượng trạng thái của nó, thì một đối tượng chế độ nên xác định một phương thức

var myCodeMirror = CodeMirror(document.body);
242, phương thức này được cung cấp một trạng thái và sẽ trả về một bản sao an toàn của trạng thái đó

Nếu bạn muốn chế độ của mình cung cấp thụt đầu dòng thông minh (thông qua phương thức

var myCodeMirror = CodeMirror(document.body);
243 và các lệnh
var myCodeMirror = CodeMirror(document.body);
244 và
var myCodeMirror = CodeMirror(document.body);
245, những phím có thể được liên kết), bạn phải xác định phương thức
var myCodeMirror = CodeMirror(document.body);
246 trên đối tượng chế độ của mình

Phương thức thụt lề sẽ kiểm tra đối tượng trạng thái đã cho và tùy chọn chuỗi

var myCodeMirror = CodeMirror(document.body);
247, chứa văn bản trên dòng đang được thụt lề và trả về một số nguyên, lượng khoảng trắng để thụt lề. Nó thường nên tính đến tùy chọn
var myCodeMirror = CodeMirror(document.body);
248. Một phương thức thụt lề có thể trả về
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
48 để cho biết rằng nó không thể tạo ra một cách thụt đầu dòng chính xác

Để hoạt động tốt với addon nhận xét, một chế độ có thể xác định

var myCodeMirror = CodeMirror(document.body);
250 (chuỗi bắt đầu nhận xét dòng),
var myCodeMirror = CodeMirror(document.body);
251,
var myCodeMirror = CodeMirror(document.body);
252 (chuỗi bắt đầu và kết thúc nhận xét khối) và
var myCodeMirror = CodeMirror(document.body);
253 (chuỗi để đặt ở đầu dòng tiếp theo trong một . Tất cả những điều này là tùy chọn

Cuối cùng, một chế độ có thể xác định thuộc tính

var myCodeMirror = CodeMirror(document.body);
254 hoặc
var myCodeMirror = CodeMirror(document.body);
255, được sử dụng để tự động lặp lại dòng khi một số mẫu nhất định được nhập và tùy chọn
var myCodeMirror = CodeMirror(document.body);
254 được bật.
var myCodeMirror = CodeMirror(document.body);
254 có thể là một chuỗi và sẽ kích hoạt reindent bất cứ khi nào một trong các ký tự trong chuỗi đó được nhập. Thông thường, sẽ phù hợp hơn khi sử dụng
var myCodeMirror = CodeMirror(document.body);
255, biểu thức này sẽ chứa biểu thức chính quy và sẽ kích hoạt thụt lề khi phần của dòng trước con trỏ khớp với biểu thức. Nó thường phải kết thúc bằng ký tự
var myCodeMirror = CodeMirror(document.body);
259, để nó chỉ khớp khi mẫu thay đổi thụt đầu dòng vừa được nhập, không phải khi thứ gì đó được nhập sau mẫu

Vì vậy, để tóm tắt, một chế độ phải cung cấp một phương thức

var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
85 và nó có thể cung cấp các phương thức
var myCodeMirror = CodeMirror(document.body);
261,
var myCodeMirror = CodeMirror(document.body);
262 và
var myCodeMirror = CodeMirror(document.body);
263. Để biết ví dụ về chế độ tầm thường, hãy xem chế độ khác, để biết ví dụ liên quan hơn, hãy xem chế độ giống C

Đôi khi, việc các chế độ lồng vào nhau sẽ rất hữu ích—để một chế độ ủy nhiệm công việc cho một chế độ khác. Một ví dụ về loại chế độ này là chế độ HTML hỗn hợp. Để thực hiện việc lồng nhau như vậy, thông thường cần phải tự tạo các đối tượng chế độ và tự sao chép các trạng thái. Để tạo một đối tượng chế độ, có

var myCodeMirror = CodeMirror(document.body);
264, trong đó đối số đầu tiên là đối tượng cấu hình được truyền cho hàm tạo chế độ và đối số thứ hai là đặc tả chế độ như trong tùy chọn
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
84. Để sao chép một đối tượng trạng thái, hãy gọi
var myCodeMirror = CodeMirror(document.body);
266, trong đó
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
84 là chế độ đã tạo trạng thái đã cho

Trong chế độ lồng nhau, bạn nên thêm một phương thức bổ sung,

var myCodeMirror = CodeMirror(document.body);
268, phương thức này, được cung cấp một đối tượng trạng thái, trả về một đối tượng
var myCodeMirror = CodeMirror(document.body);
269 với chế độ bên trong và trạng thái của nó cho vị trí hiện tại. Chúng được sử dụng bởi các tập lệnh tiện ích, chẳng hạn như thẻ gần hơn để lấy thông tin ngữ cảnh. Sử dụng hàm trợ giúp
var myCodeMirror = CodeMirror(document.body);
270 để, bắt đầu từ một chế độ và trạng thái, đi xuống chế độ và trạng thái trong cùng một cách đệ quy

Để làm cho việc thụt đầu dòng hoạt động chính xác trong trình phân tích cú pháp lồng nhau, bạn nên cung cấp cho phương thức

var myCodeMirror = CodeMirror(document.body);
261 của các chế độ được dự định lồng vào một đối số tùy chọn cung cấp thụt đầu dòng cơ sở cho khối mã. Ví dụ: trình phân tích cú pháp JavaScript và CSS thực hiện việc này để cho phép mã JavaScript và CSS bên trong chế độ HTML ở chế độ hỗn hợp được thụt lề đúng cách

Có thể và được khuyến khích liên kết chế độ của bạn hoặc một cấu hình nhất định của chế độ của bạn với loại MIME. Ví dụ: chế độ JavaScript tự liên kết với

var myCodeMirror = CodeMirror(document.body);
272 và biến thể JSON của nó với
var myCodeMirror = CodeMirror(document.body);
273. Để thực hiện việc này, hãy gọi
var myCodeMirror = CodeMirror(document.body);
274, trong đó
var myCodeMirror = CodeMirror(document.body);
275 có thể là một chuỗi hoặc đối tượng chỉ định một chế độ, như trong tùy chọn
var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
84

Nếu một đặc tả chế độ muốn thêm một số thuộc tính vào đối tượng chế độ kết quả, thường được sử dụng với

var myCodeMirror = CodeMirror.fromTextArea(myTextArea);
710, thì nó có thể chứa thuộc tính
var myCodeMirror = CodeMirror(document.body);
278, chứa một đối tượng. Các thuộc tính của đối tượng này sẽ được sao chép sang đối tượng chế độ thực tế

Đôi khi, rất hữu ích khi thêm hoặc ghi đè các thuộc tính đối tượng chế độ từ mã bên ngoài. Hàm

var myCodeMirror = CodeMirror(document.body);
279 có thể được sử dụng để thêm các thuộc tính cho các đối tượng chế độ được tạo cho một chế độ cụ thể. Đối số đầu tiên của nó là tên của chế độ, đối số thứ hai của nó là đối tượng chỉ định các thuộc tính sẽ được thêm vào. Điều này chủ yếu hữu ích để thêm các tiện ích mà sau này có thể tra cứu thông qua
var myCodeMirror = CodeMirror(document.body);
480

API chế độ VIM

CodeMirror có chế độ VIM mạnh mẽ cố gắng mô phỏng trung thực các tính năng hữu ích nhất của VIM. Nó có thể được kích hoạt bằng cách bao gồm

var myCodeMirror = CodeMirror(document.body);
281 và đặt tùy chọn
var myCodeMirror = CodeMirror(document.body);
19 thành
var myCodeMirror = CodeMirror(document.body);
283

Cấu hình

Chế độ VIM chấp nhận các tùy chọn cấu hình để tùy chỉnh hành vi trong thời gian chạy. Các phương thức này có thể được gọi bất cứ lúc nào và sẽ ảnh hưởng đến tất cả các phiên bản CodeMirror hiện có trừ khi có quy định khác. Các phương thức được hiển thị trên đối tượng

var myCodeMirror = CodeMirror(document.body);
284

var myCodeMirror = CodeMirror(document.body);
285Đặt giá trị của tùy chọn VIM.
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
5 phải là tên của một tùy chọn. Nếu
var myCodeMirror = CodeMirror(document.body);
287 không được đặt và
var myCodeMirror = CodeMirror(document.body);
288 được cung cấp, thì hãy đặt giá trị toàn cục và phiên bản của tùy chọn. Mặt khác, đặt giá trị toàn cầu hoặc giá trị phiên bản của tùy chọn tùy thuộc vào việc
var myCodeMirror = CodeMirror(document.body);
287 là
var myCodeMirror = CodeMirror(document.body);
290 hay
var myCodeMirror = CodeMirror(document.body);
291.
var myCodeMirror = CodeMirror(document.body);
292Lấy giá trị hiện tại của tùy chọn VIM. Nếu
var myCodeMirror = CodeMirror(document.body);
287 không được đặt và
var myCodeMirror = CodeMirror(document.body);
288 được cung cấp, sau đó nhận giá trị phiên bản của tùy chọn, quay trở lại giá trị chung nếu không được đặt. Nếu cung cấp
var myCodeMirror = CodeMirror(document.body);
287, thì nhận giá trị
var myCodeMirror = CodeMirror(document.body);
290 hoặc
var myCodeMirror = CodeMirror(document.body);
291 mà không cần kiểm tra giá trị khác.
var myCodeMirror = CodeMirror(document.body);
298Ánh xạ một chuỗi khóa tới một chuỗi khóa khác. Thực hiện lệnh
var myCodeMirror = CodeMirror(document.body);
299 của VIM. Lập bản đồ ; . trong VIM sẽ là
var myCodeMirror = CodeMirror(document.body);
300. Điều đó sẽ dịch thành
var myCodeMirror = CodeMirror(document.body);
301.
var myCodeMirror = CodeMirror(document.body);
302 có thể là
var myCodeMirror = CodeMirror(document.body);
303,
var myCodeMirror = CodeMirror(document.body);
304 hoặc ________ 1305, tương ứng với ________ 1306, ________ 1307 và ________ 1308 tương ứng.
var myCodeMirror = CodeMirror(document.body);
309Ánh xạ chuỗi phím tới lệnh loại
var myCodeMirror = CodeMirror(document.body, {
  value: "function myScript(){return 100;}\n",
  mode:  "javascript"
});
50,
var myCodeMirror = CodeMirror(document.body);
311 hoặc
var myCodeMirror = CodeMirror(document.body);
312. Đối tượng args được chuyển qua lệnh khi nó được gọi bởi chuỗi khóa được cung cấp.
var myCodeMirror = CodeMirror(document.body);
313 có thể là
var myCodeMirror = CodeMirror(document.body);
303,
var myCodeMirror = CodeMirror(document.body);
304 hoặc
var myCodeMirror = CodeMirror(document.body);
305, chỉ ánh xạ chuỗi khóa ở chế độ tương ứng.
var myCodeMirror = CodeMirror(document.body);
317 chỉ áp dụng cho các hành động, xác định xem nó có được ghi lại để phát lại cho lệnh lặp lại một lần
var myCodeMirror = CodeMirror(document.body);
318 hay không.
var myCodeMirror = CodeMirror(document.body);
319Xóa lệnh
var myCodeMirror = CodeMirror(document.body);
320 nếu đó là lệnh do người dùng xác định. Nếu lệnh là ánh xạ Ex to Ex hoặc Ex to key thì ngữ cảnh phải là
var myCodeMirror = CodeMirror(document.body);
165 hoặc
var myCodeMirror = CodeMirror(document.body);
12.
var myCodeMirror = CodeMirror(document.body);
323Xóa tất cả ánh xạ do người dùng xác định cho ngữ cảnh được cung cấp.
var myCodeMirror = CodeMirror(document.body);
324Chức năng bản đồ không đệ quy. 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 demo/vim. html#L101

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);
328Được kích hoạt sau khi thay đổi chế độ, tham số
var myCodeMirror = CodeMirror(document.body);
329 là một đối tượng
var myCodeMirror = CodeMirror(document.body);
330. Modes.
var myCodeMirror = CodeMirror(document.body);
331. Visual sub-modes.
var myCodeMirror = CodeMirror(document.body);
332

mở rộng VIM

Chế độ VIM của CodeMirror triển khai một tập hợp con lớn chức năng chỉnh sửa cốt lõi của VIM. Nhưng vì luôn có nhiều thứ được mong muốn hơn, nên có một bộ API để mở rộng chức năng của VIM. As with the configuration API, the methods are exposed on

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