Javascript có thể thao tác xml khô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ụ


[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 thêm trình chỉnh sửa vào một phần tử và cần kiểm soát nhiều hơn đối với cách nó được chèn vào, thì đối số đầu tiên của hàm

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

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

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

var myCodeMirror = CodeMirror.fromTextArea[myTextArea];

Điều này sẽ, trong số những thứ khác, đảm bảo rằng giá trị của vùng văn bản được cập nhật với nội dung của trình soạn thảo khi biểu mẫu [nếu nó là một phần của biểu mẫu] được gửi. Xem 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 cung cấp, 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.
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 xem nội dung được sao chép [sai] hay di chuyển [đúng]. Theo mặc định, tính năng này được bật bằng cách nhấp vào alt trên Mac OS và nhấp vào ctrl ở nơi khác.
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 chạm tới hết 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
var myCodeMirror = CodeMirror[document.body];
23 mili giây, sau đó sử dụng thời gian chờ để ngủ trong
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, được ghi đè bởi thay đổi này. 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, chuyể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, được trình bày dưới dạng một mảng gồm các đối tượng
var myCodeMirror = CodeMirror[document.body];
75 trong thuộc tính
var myCodeMirror = CodeMirror[document.body];
76 của đối số
var myCodeMirror = CodeMirror[document.body];
77 và tùy ý thay đổi chúng bằng cách gọi phương thức
var myCodeMirror = CodeMirror[document.body];
62 trên đối tượng này, truyền một mảng các phạm vi có cùng định dạng. Đối tượng cũng chứa thuộc tính
var myCodeMirror = CodeMirror[document.body];
79 giữ chuỗi gốc được truyền cho phương thức thay đổi lựa chọn, nếu có. Trình xử lý cho sự kiện này có 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"
}];
00Will be fired whenever CodeMirror updates its DOM display.
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 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. It also contains the
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
5 key map holding the default bindings

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 matches both up and shift-up]. Đ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

When a key map needs to set something up when it becomes active, or tear something down when deactivated, it can contain

var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
54 and/or
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
55 properties, which should hold functions that take the editor instance and the next or previous keymap. 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. A number of common commands are defined by the library itself, most of them used by the default key bindings. 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. These are intended to be defined by user code or 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] Select the whole content of the editor.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
61 Esc When multiple selections are present, this deselects all but the primary selection.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
62 Ctrl-K [Mac] Emacs-style line killing. Deletes the part of the line after the cursor. If that consists only of whitespace, the newline at the end of the line is also deleted.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
63 Ctrl-D [PC], Cmd-D [Mac] Deletes the whole line under the cursor, including newline at the end.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
64Delete the part of the line before the cursor.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
65 Cmd-Backspace [Mac] Delete the part of the line from the left side of the visual line the cursor is on to the cursor.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
66 Cmd-Delete [Mac] Delete the part of the line from the cursor to the right side of the visual line the cursor is on.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
67 Ctrl-Z [PC], Cmd-Z [Mac] Undo the last change. Note that, because browsers still don't make it possible for scripts to react to or customize the context menu, selecting undo [or redo] from the context menu in a CodeMirror instance does not work.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
68 Ctrl-Y [PC], Shift-Cmd-Z [Mac], Cmd-Y [Mac] Redo the last undone change.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
69 Ctrl-U [PC], Cmd-U [Mac] Undo the last change to the selection, or if there are no selection-only changes at the top of the history, undo the last change.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
70 Alt-U [PC], Shift-Cmd-U [Mac] Redo the last change to the selection, or the last text change if no selection changes remain.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
71 Ctrl-Home [PC], Cmd-Up [Mac], Cmd-Home [Mac] Move the cursor to the start of the document.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
72 Ctrl-End [PC], Cmd-End [Mac], Cmd-Down [Mac] Move the cursor to the end of the document.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
73 Alt-Left [PC], Ctrl-A [Mac] Move the cursor to the start of the line.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
74 Home Move to the start of the text on the line, or if we are already there, to the actual start of the line [including whitespace].
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
75 Alt-Right [PC], Ctrl-E [Mac] Move the cursor to the end of the line.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
76 Cmd-Right [Mac] Move the cursor to the right side of the visual line it is on.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
77 Cmd-Left [Mac] Move the cursor to the left side of the visual line it is on. If this line is wrapped, that may not be the start of the line.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
78Move the cursor to the left side of the visual line it is on. If that takes it to the start of the line, behave like
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 Up, Ctrl-P [Mac] Move the cursor up one line.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
81 Down, Ctrl-N [Mac] Move down one line.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
82 PageUp, Shift-Ctrl-V [Mac] Move the cursor up one screen, and scroll up by the same distance.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
83 PageDown, Ctrl-V [Mac] Move the cursor down one screen, and scroll down by the same distance.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
84 Left, Ctrl-B [Mac] Move the cursor one character left, going to the previous line when hitting the start of line.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
85 Right, Ctrl-F [Mac] Move the cursor one character right, going to the next line when hitting the end of line.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
86Move the cursor one character left, but don't cross line boundaries.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
87Move the cursor one character right, don't cross line boundaries.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
88 Alt-B [Mac] Move the cursor to the start of the previous word.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
89 Alt-F [Mac] Move the cursor to the end of the next word.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
90 Ctrl-Left [PC], Alt-Left [Mac] Move to the left of the group before the cursor. A group is a stretch of word characters, a stretch of punctuation characters, a newline, or a stretch of more than one whitespace character.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
91 Ctrl-Right [PC], Alt-Right [Mac] Move to the right of the group after the cursor [see above].
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
92 Shift-Backspace, Ctrl-H [Mac] Delete the character before the cursor.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
93 Delete, Ctrl-D [Mac] Delete the character after the cursor.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
94 Alt-Backspace [Mac] Delete up to the start of the word before the cursor.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
95 Alt-D [Mac] Delete up to the end of the word after the cursor.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
96 Ctrl-Backspace [PC], Alt-Backspace [Mac] Delete to the left of the group before the cursor.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
97 Ctrl-Delete [PC], Ctrl-Alt-Backspace [Mac], Alt-Delete [Mac] Delete to the start of the group after the cursor.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
98 Shift-Tab Auto-indent the current line or selection.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
99 Ctrl-] [PC], Cmd-] [Mac] Indent the current line or selection by one indent unit.
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
00 Ctrl-[ [PC], Cmd-[ [Mac] Dedent the current line or selection by one indent unit.
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
01Insert a tab character at the cursor.
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
02Insert the amount of spaces that match the width a tab at the cursor position would have.
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
03 Tab If something is selected, indent it by one indent unit. If nothing is selected, insert a tab character.
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
04 Ctrl-T [Mac] Swap the characters before and after the cursor.
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
05 Enter Insert a newline and auto-indent the new line.
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
06 Insert Flip the overwrite flag.
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. Intended to provide an easy way for user code to define a save command.
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-G [Mac]
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
10 Shift-Ctrl-G [PC], Shift-Cmd-G [Mac]
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
11 Shift-Ctrl-F [PC], Cmd-Alt-F [Mac]
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
12 Shift-Ctrl-R [PC], Shift-Cmd-Alt-F [Mac] Not defined by the core library, but defined in the search addon [or custom client addons].

Customized Styling

Up to a certain extent, CodeMirror's look can be changed by modifying style sheet files. The style sheets supplied by modes simply provide the colors for that mode, and can be adapted in a very straightforward way. To style the editor itself, it is possible to alter or override the styles defined in

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

Some care must be taken there, since a lot of the rules in this file are necessary to have CodeMirror function properly. Adjusting colors should be safe, of course, and with some care a lot of other things can be changed as well. The CSS classes defined in this file serve the following roles

var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
14The outer element of the editor. This should be used for the editor width, height, borders and positioning. Can also be used to set styles that should hold for everything inside the editor [such as font and font size], or to set a background. Setting this class'
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
15 style to
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
16 will make the editor resize to fit its content [it is recommended to also set the
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
17 option to
var myCodeMirror = CodeMirror[document.body];
31 when doing this.
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
19Whenever the editor is focused, the top element gets this class. This is used to hide the cursor and give the selection a different color when the editor is not focused.
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
20This is the backdrop for all gutters. Use it to set the default gutter background color, and optionally add a border on the right of the gutters.
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
21Use this for giving a background or width to the line number gutter.
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
22Used to style the actual individual line numbers. These won't be children of the
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
76 [plural] element, but rather will be absolutely positioned to overlay it. Use this to set alignment and text properties for the line numbers.
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
24The visible lines. This is where you specify vertical padding for the editor content.
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
25The cursor is a block element that is absolutely positioned. You can make it look whichever way you want.
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
26The selection is represented by
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
27 elements with this class.
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}];
29These are used to style matched [or unmatched] brackets

If your page's style sheets do funky things to all

var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
30 or
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
31 elements [you probably shouldn't do that], you'll have to define rules to cancel these effects out again for elements under the
var myCodeMirror = CodeMirror[document.body];
1 class

Themes are also simply CSS files, which define colors for various syntactic elements. See the files in the

var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
4 directory

Programming API

A lot of CodeMirror features are only available through its API. Thus, you need to write code [or use addons] if you want to expose them to your users

Whenever points in the document are represented, the API uses objects with

var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
34 and
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
35 properties. Both are zero-based. CodeMirror makes sure to 'clip' any positions passed by client code so that they fit inside the document, so you shouldn't worry too much about sanitizing your coordinates. If you give
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
35 a value of
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
0, or don't specify it, it will be replaced with the length of the specified line. Such positions may also have a
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
38 property holding
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
39 or
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
40, whether the position is associated with the character before or after it. This influences, for example, where the cursor is drawn on a line-break or bidi-direction boundary

Methods prefixed with

var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
41 can, unless otherwise specified, be called both on
var myCodeMirror = CodeMirror[document.body];
1 [editor] instances and
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
05 instances. Methods prefixed with
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
44 are only available on
var myCodeMirror = CodeMirror[document.body];
1 instances

Constructor

Constructing an editor instance is done with the

var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
46 constructor. 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 đưa ra, 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}];
77Iterate over the whole document, or if
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
78 and
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
79 line numbers are given, the range from
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
78 up to [not including]
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
79, and call
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
82 for each line, passing the line handle.
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 gõ 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ả lại.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
13Retrieves a list of all current selections. 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 được thu gọn], thì lựa chọn mới sẽ thay thế lựa chọn cũ. When it starts with
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
30, it will always replace the previous event [if that had the same origin]. Chuyển động tích hợp sử dụng nguồn gốc
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
31. Đầu vào của người dùng sử dụng nguồn gốc
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
32.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
33Xác định hướng điều chỉnh các điểm cuối lựa chọn khi chúng nằm trong phạm vi nguyên tử. Có thể là -1 [lùi] hoặc 1 [tiến]. Khi không được cung cấp, độ lệch sẽ dựa trên vị trí tương đối của lựa chọn cũ—người chỉnh sửa sẽ cố gắng di chuyển xa hơn khỏi vị trí đó để tránh bị kẹt.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
34Đặt một bộ lựa chọn mới. Phải có ít nhất một lựa chọn trong mảng đã cho. Khi
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
35 là một số, nó sẽ xác định lựa chọn nào là lựa chọn chính. Khi nó không được cung cấp, chỉ mục chính được lấy từ lựa chọn trước đó hoặc được đặt thành phạm vi cuối cùng nếu lựa chọn trước đó có ít phạm vi hơn lựa chọn mới. Hỗ trợ các tùy chọn giống như
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
20.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
15 mặc định là
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
14 khi không được cung cấp.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
39Thêm một lựa chọn mới vào tập hợp các lựa chọn hiện có và biến nó thành lựa chọn chính.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
40Tương tự như
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
20, nhưng nếu dịch chuyển được giữ hoặc cờ mở rộng được đặt, sẽ di chuyển phần đầu của vùng chọn trong khi để neo ở vị trí hiện tại.
var myCodeMirror = CodeMirror[document.body];
46 là tùy chọn và có thể được chuyển để đảm bảo một vùng [ví dụ: một từ hoặc đoạn văn] sẽ được chọn [ngoài bất kỳ thứ gì nằm giữa vùng đó và neo hiện tại]. Khi có nhiều lựa chọn, tất cả trừ lựa chọn chính sẽ bị loại bỏ theo phương pháp này. Hỗ trợ các tùy chọn giống như
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
20.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
44 Tương đương với
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
45 hoạt động trên tất cả các lựa chọn cùng một lúc.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
46Áp dụng hàm đã cho cho tất cả các lựa chọn hiện có và gọi
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
47 trên kết quả.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
48Đặt hoặc xóa cờ 'mở rộng', cờ này hoạt động tương tự như phím shift, ở chỗ nó sẽ khiến con trỏ di chuyển và gọi tới
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
45 để giữ nguyên vị trí neo chọn.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
50Nhận giá trị của cờ 'mở rộng'.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
51Cho bạn biết liệu trình chỉnh sửa hiện có tiêu điểm hay không.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
52Được sử dụng để tìm vị trí mục tiêu cho chuyển động con trỏ ngang.
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
78 là đối tượng
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
55,
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
55 là số nguyên [có thể âm] và
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
56 là một trong chuỗi
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
57,
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
58 hoặc
var myCodeMirror = CodeMirror[document.body];
42. Sẽ trả về một vị trí được tạo ra bằng cách di chuyển
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
55 lần khoảng cách được chỉ định bởi
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
56. Khi
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
62 là đúng, chuyển động trong văn bản từ phải sang trái sẽ trực quan hơn là logic. Khi chuyển động được cắt bớt bằng cách nhấn vào phần cuối hoặc phần đầu của tài liệu, giá trị được trả về sẽ có thuộc tính
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
63 được đặt thành true.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
64Similar to
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
65, but used for vertical motion.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
56 có thể là
var myCodeMirror = CodeMirror[document.body];
43 hoặc
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
68. Các đối số khác và giá trị được trả về có cùng cách giải thích như trong
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
65.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
70Trả về phần đầu và phần cuối của 'từ' [độ dài của các chữ cái, khoảng trắng hoặc dấu chấm câu] tại vị trí đã cho

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

var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
71Thay đổi cấu hình của trình chỉnh sửa.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
72 nên là tên của một tùy chọn và
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
73 phải là một giá trị hợp lệ cho tùy chọn đó.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
74Truy xuất giá trị hiện tại của tùy chọn đã cho cho phiên bản trình chỉnh sửa này.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
75Đính kèm một bản đồ khóa bổ sung cho trình chỉnh sửa. Điều này chủ yếu hữu ích cho các addon cần đăng ký một số trình xử lý chính mà không cần giẫm đạp lên tùy chọn
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
56. Các bản đồ được thêm theo cách này có mức độ ưu tiên cao hơn so với các tùy chọn
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
56 và
var myCodeMirror = CodeMirror[document.body];
19 và giữa chúng, các bản đồ được thêm vào trước đó có mức độ ưu tiên thấp hơn các bản đồ được thêm vào sau, trừ khi đối số
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
79 được thông qua, trong trường hợp đó, chúng sẽ kết thúc bên dưới các bản đồ chính khác .
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
80Vô hiệu hóa sơ đồ bàn phím được thêm bằng
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
57. Chuyển vào chính đối tượng bản đồ khóa hoặc một chuỗi, chuỗi này sẽ được so sánh với thuộc tính
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
5 của bản đồ khóa đang hoạt động.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
83Bật lớp phủ tô sáng. Đây là một chế độ nhỏ không trạng thái có thể được sử dụng để thêm phần tô sáng. Ví dụ: addon tìm kiếm sử dụng nó để đánh dấu cụm từ hiện đang được tìm kiếm.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
84 có thể là thông số chế độ hoặc đối tượng chế độ [đối tượng có phương thức
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
85]. Tham số
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
48 là tùy chọn. Nếu được cung cấp, nó phải là một đối tượng, tùy ý chứa các tùy chọn sau.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
87Mặc định là tắt, nhưng có thể được cung cấp để cho phép kiểu dáng lớp phủ, khi không phải là
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
0, ghi đè hoàn toàn kiểu dáng của chế độ cơ sở, thay vì cả hai được áp dụng cùng nhau.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
89Xác định thứ tự áp dụng các lớp phủ. Những cái có mức độ ưu tiên cao được áp dụng sau những cái có mức độ ưu tiên thấp hơn và có thể ghi đè độ mờ đục của những cái đến trước. Mặc định là 0.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
90Truyền giá trị chính xác này được truyền cho tham số
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
84 cho
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
92 hoặc một chuỗi tương ứng với thuộc tính
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
5 của giá trị đó, để xóa lớp phủ một lần nữa.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
94Đăng ký trình xử lý sự kiện cho loại sự kiện đã cho [chuỗi] trên phiên bản trình chỉnh sửa. 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. Một
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
97 tương đương cũng tồn tại

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

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

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

var myCodeMirror = CodeMirror[document.body];
100Truy xuất tài liệu hiện đang hoạt động từ trình chỉnh sửa.
var myCodeMirror = CodeMirror[document.body];
101Truy xuất trình chỉnh sửa được liên kết với tài liệu. Có thể trở lại
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
0.
var myCodeMirror = CodeMirror[document.body];
103Đính kèm tài liệu mới vào trình chỉnh sửa. Trả về tài liệu cũ, hiện không còn được liên kết với trình chỉnh sửa.
var myCodeMirror = CodeMirror[document.body];
104Tạo một bản sao giống hệt của tài liệu đã cho. Khi
var myCodeMirror = CodeMirror[document.body];
105 là đúng, lịch sử cũng sẽ được sao chép. Không thể gọi trực tiếp trên trình chỉnh sửa.
var myCodeMirror = CodeMirror[document.body];
106Tạo tài liệu mới được liên kết với tài liệu đích. Các tài liệu được liên kết sẽ luôn đồng bộ [các thay đổi đối với tài liệu này cũng được áp dụng cho tài liệu kia] cho đến khi hủy liên kết. Đây là những tùy chọn được hỗ trợ.
var myCodeMirror = CodeMirror[document.body];
107Khi được bật, bản sao được liên kết sẽ chia sẻ lịch sử hoàn tác với bản gốc. Do đó, một cái gì đó được thực hiện ở một trong hai có thể được hoàn tác ở bên kia và ngược lại.
var myCodeMirror = CodeMirror[document.body];
108
var myCodeMirror = CodeMirror[document.body];
109Có thể được đưa ra để làm cho tài liệu mới trở thành một phần phụ của tài liệu gốc. Subviews chỉ hiển thị một loạt các dòng nhất định. Lưu ý rằng tọa độ dòng bên trong chế độ xem con sẽ nhất quán với tọa độ của chế độ xem gốc, do đó, ví dụ: chế độ xem con bắt đầu từ dòng 10 sẽ tham chiếu đến dòng đầu tiên của nó là dòng 10, không phải 0.
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
3Theo mặc định, tài liệu mới kế thừa chế độ của tài liệu gốc. Tùy chọn này có thể được đặt thành một thông số chế độ để cung cấp cho nó một chế độ khác.
var myCodeMirror = CodeMirror[document.body];
111Ngắt liên kết giữa hai tài liệu. Sau khi gọi điều này, các thay đổi sẽ không còn lan truyền giữa các tài liệu và nếu chúng có lịch sử dùng chung, thì lịch sử sẽ trở nên riêng biệt.
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];
130Xác định xem văn bản được chèn ở bên trái của điểm đánh dấu sẽ nằm bên trong hay bên ngoài điểm đánh dấu.
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. Không có tác dụng đối với phạm vi phi nguyên tử.
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];
136Dải nguyên tử hoạt động như một đơn vị duy nhất khi có liên quan đến chuyển động của con trỏ—i. e. không thể đặt con trỏ bên trong chúng. Bạn có thể kiểm soát 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. Nếu không cung cấp
var myCodeMirror = CodeMirror[document.body];
135 [hoặc bên phải] thì
var myCodeMirror = CodeMirror[document.body];
132 [hoặc bên phải] sẽ kiểm soát hành vi này.
var myCodeMirror = CodeMirror[document.body];
141Các phạm vi được thu gọn không hiển thị trên màn hình. Đặt phạm vi thành thu gọn sẽ tự động biến phạm vi thành nguyên tử.
var myCodeMirror = CodeMirror[document.body];
142Khi được bật, sẽ khiến dấu tự xóa bất cứ khi nào con trỏ đi vào phạm vi của nó. Điều này chủ yếu hữu ích cho các tiện ích thay thế văn bản cần 'mở nhanh' khi người dùng cố gắng chỉnh sửa chúng. Sự kiện
var myCodeMirror = CodeMirror[document.body];
143 được kích hoạt trên bộ điều khiển phạm vi có thể được sử dụng để được thông báo khi điều này xảy ra.
var myCodeMirror = CodeMirror[document.body];
144Xác định xem dấu có tự động bị xóa khi nó trống không. Mặc định là đúng.
var myCodeMirror = CodeMirror[document.body];
145Sử dụng một nút nhất định để hiển thị phạm vi này. Ngụ ý cả sụp đổ và nguyên tử. Nút DOM đã cho phải là một phần tử nội tuyến [trái ngược với phần tử khối].
var myCodeMirror = CodeMirror[document.body];
146Khi
var myCodeMirror = CodeMirror[document.body];
147 được cung cấp, điều này xác định liệu trình chỉnh sửa có nắm bắt các sự kiện chuột và kéo xảy ra trong tiện ích con này hay không. Mặc định là sai—các sự kiện sẽ được để yên cho trình xử lý mặc định của trình duyệt hoặc các trình xử lý cụ thể trên tiện ích con nắm bắt.
var myCodeMirror = CodeMirror[document.body];
148Một khoảng thời gian chỉ đọc có thể, miễn là nó không bị xóa, không bị sửa đổi ngoại trừ bằng cách gọi
var myCodeMirror = CodeMirror[document.body];
149 để đặt lại toàn bộ tài liệu. Ghi chú. việc thêm một khoảng thời gian chỉ đọc hiện sẽ xóa lịch sử hoàn tác của trình chỉnh sửa, vì các sự kiện hoàn tác hiện tại bị vô hiệu hóa một phần bởi các khoảng thời gian chỉ đọc sẽ làm hỏng lịch sử [trong quá trình triển khai hiện tại].
var myCodeMirror = CodeMirror[document.body];
150Khi được đặt thành đúng [mặc định là sai], việc thêm điểm đánh dấu này sẽ tạo một sự kiện trong lịch sử hoàn tác có thể được hoàn tác riêng lẻ [xóa điểm đánh dấu].
var myCodeMirror = CodeMirror[document.body];
151Có thể được sử dụng để chỉ định một lớp CSS bổ sung sẽ được áp dụng cho khoảng ngoài cùng bên trái là một phần của điểm đánh dấu.
var myCodeMirror = CodeMirror[document.body];
152Tương đương với
var myCodeMirror = CodeMirror[document.body];
153, nhưng đối với nhịp ngoài cùng bên phải.
var myCodeMirror = CodeMirror[document.body];
154Một chuỗi CSS sẽ được áp dụng cho văn bản được bao phủ. Ví dụ
var myCodeMirror = CodeMirror[document.body];
155.
var myCodeMirror = CodeMirror[document.body];
156Khi được cung cấp, hãy thêm các thuộc tính trong đối tượng đã cho vào các thành phần được tạo cho văn bản được đánh dấu. Cách thêm thuộc tính
var myCodeMirror = CodeMirror[document.body];
157 hoặc
var myCodeMirror = CodeMirror[document.body];
158 không được hỗ trợ.
var myCodeMirror = CodeMirror[document.body];
159Khi tài liệu đích được liên kết với các tài liệu khác, bạn có thể đặt
var myCodeMirror = CodeMirror[document.body];
160 thành true để làm cho điểm đánh dấu xuất hiện trong tất cả các tài liệu. Theo mặc định, điểm đánh dấu chỉ xuất hiện trong tài liệu đích của nó. Phương thức này sẽ trả về một đối tượng đại diện cho điểm đánh dấu [với hàm tạo
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
16], hiển thị ba phương thức.
var myCodeMirror = CodeMirror[document.body];
162, để xóa dấu,
var myCodeMirror = CodeMirror[document.body];
163, trả về một đối tượng
var myCodeMirror = CodeMirror[document.body];
164 [cả hai đều giữ vị trí tài liệu], cho biết vị trí hiện tại của phạm vi được đánh dấu, hoặc
var myCodeMirror = CodeMirror[document.body];
165 nếu dấu không còn trong tài liệu và cuối cùng là
var myCodeMirror = CodeMirror[document.body];
166, mà bạn có thể gọi .
var myCodeMirror = CodeMirror[document.body];
168Chèn một dấu trang, một tay cầm theo sau văn bản xung quanh nó khi nó đang được chỉnh sửa, tại vị trí đã cho. Một dấu trang có hai phương pháp
var myCodeMirror = CodeMirror[document.body];
169 và
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
22. Cái đầu tiên trả về vị trí hiện tại của dấu trang, nếu nó vẫn còn trong tài liệu và cái thứ hai xóa dấu trang một cách rõ ràng. Đối số tùy chọn là tùy chọn. Nếu được đưa ra, các thuộc tính sau được công nhận.
var myCodeMirror = CodeMirror[document.body];
171Có thể được sử dụng để hiển thị nút DOM tại vị trí hiện tại của dấu trang [tương tự như tùy chọn
var myCodeMirror = CodeMirror[document.body];
147 thành
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
17].
var myCodeMirror = CodeMirror[document.body];
174Theo mặc định, văn bản được nhập khi con trỏ ở trên cùng của dấu trang sẽ kết thúc ở bên phải của dấu trang. Thay vào đó, hãy đặt tùy chọn này thành true để làm cho tùy chọn này chuyển sang bên trái.
var myCodeMirror = CodeMirror[document.body];
159Xem tùy chọn tương ứng với
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
17.
var myCodeMirror = CodeMirror[document.body];
146Giống như với
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
17, điều này xác định xem các sự kiện chuột trên tiện ích được chèn cho dấu trang này có được xử lý bởi CodeMirror hay không. Mặc định này sai.
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];
180Trả về một mảng gồm tất cả các dấu trang và phạm vi được đánh dấu có ở vị trí đã cho.
var myCodeMirror = CodeMirror[document.body];
181Trả về một mảng chứa tất cả các phạm vi được đánh dấu trong tài liệu

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

var myCodeMirror = CodeMirror[document.body];
182Đặt điểm đánh dấu máng xối cho máng xối đã cho [được xác định bởi lớp CSS của nó, xem tùy chọn
var myCodeMirror = CodeMirror[document.body];
183] thành giá trị đã cho. Giá trị có thể là
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
0, để xóa điểm đánh dấu hoặc phần tử DOM, để đặt. Phần tử DOM sẽ được hiển thị trong máng xối được chỉ định bên cạnh dòng được chỉ định.
var myCodeMirror = CodeMirror[document.body];
185Xóa tất cả các điểm đánh dấu máng xối trong máng xối bằng ID đã cho.
var myCodeMirror = CodeMirror[document.body];
186Đặt tên lớp CSS cho dòng đã cho.
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
34 có thể là một số hoặc một dòng xử lý.
var myCodeMirror = CodeMirror[document.body];
188 xác định lớp này sẽ được áp dụng cho phần tử nào, có thể là một trong số
var myCodeMirror = CodeMirror[document.body];
189 [phần tử văn bản, nằm phía trước vùng chọn],
var myCodeMirror = CodeMirror[document.body];
190 [phần tử nền sẽ nằm phía sau vùng chọn],
var myCodeMirror = CodeMirror[document.body];
191 [khoảng trống của dòng] .
var myCodeMirror = CodeMirror[document.body];
157 nên là tên của lớp để áp dụng.
var myCodeMirror = CodeMirror[document.body];
194Xóa một lớp CSS khỏi một dòng.
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
34 có thể là một dòng xử lý hoặc số.
var myCodeMirror = CodeMirror[document.body];
188 phải là một trong số
var myCodeMirror = CodeMirror[document.body];
189,
var myCodeMirror = CodeMirror[document.body];
190 hoặc
var myCodeMirror = CodeMirror[document.body];
192 [xem
var myCodeMirror = CodeMirror[document.body];
400]. Có thể để lại
var myCodeMirror = CodeMirror[document.body];
157 để xóa tất cả các lớp cho nút đã chỉ định hoặc là một chuỗi để chỉ xóa một lớp cụ thể.
var myCodeMirror = CodeMirror[document.body];
402Trả về số dòng, nội dung văn bản và trạng thái điểm đánh dấu của dòng đã cho, có thể là số hoặc điều khiển dòng. Đối tượng được trả về có cấu trúc
var myCodeMirror = CodeMirror[document.body];
403, trong đó
var myCodeMirror = CodeMirror[document.body];
404 là ID máng xối ánh xạ đối tượng tới các phần tử đánh dấu và
var myCodeMirror = CodeMirror[document.body];
405 là một mảng các tiện ích dòng được đính kèm với dòng này và các thuộc tính lớp khác nhau đề cập đến các lớp được thêm vào với
var myCodeMirror = CodeMirror[document.body];
400.
var myCodeMirror = CodeMirror[document.body];
407Đặt
var myCodeMirror = CodeMirror[document.body];
408, phải là nút DOM được định vị tuyệt đối, vào trình chỉnh sửa, được định vị ngay bên dưới vị trí
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
55 đã cho. Khi
var myCodeMirror = CodeMirror[document.body];
410 là đúng, trình chỉnh sửa sẽ đảm bảo rằng toàn bộ nút hiển thị [nếu có thể]. Để xóa tiện ích một lần nữa, chỉ cần sử dụng các phương thức DOM [di chuyển tiện ích đó đến nơi khác hoặc gọi
var myCodeMirror = CodeMirror[document.body];
411 trên cấp độ gốc của tiện ích đó].
var myCodeMirror = CodeMirror[document.body];
412Thêm một tiện ích dòng, một phần tử được hiển thị bên dưới một dòng, kéo dài toàn bộ chiều rộng của trình chỉnh sửa và di chuyển các dòng bên dưới nó xuống dưới.
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
34 phải là một số nguyên hoặc một dòng điều khiển và
var myCodeMirror = CodeMirror[document.body];
408 phải là một nút DOM, nút này sẽ được hiển thị bên dưới dòng đã cho.
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
48, khi được cung cấp, phải là một đối tượng định cấu hình hành vi của tiện ích con. Các tùy chọn sau được hỗ trợ [tất cả mặc định là sai].
var myCodeMirror = CodeMirror[document.body];
416Liệu vật dụng có nên che máng xối hay không.
var myCodeMirror = CodeMirror[document.body];
417Liệu tiện ích có nên cố định khi cuộn ngang hay không.
var myCodeMirror = CodeMirror[document.body];
418Làm cho tiện ích con được đặt bên trên thay vì bên dưới văn bản của dòng.
var myCodeMirror = CodeMirror[document.body];
146Xác định xem trình chỉnh sửa có nắm bắt các sự kiện chuột và kéo xảy ra trong tiện ích con này hay không. Mặc định là sai—các sự kiện sẽ được để yên cho trình xử lý mặc định của trình duyệt hoặc các trình xử lý cụ thể trên tiện ích con nắm bắt.
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. Tùy chọn này có thể được sử dụng để đặt nó ở một vị trí khác [số 0 ở trên cùng, N để đặt nó sau tiện ích khác thứ N]. Lưu ý rằng điều này chỉ có hiệu lực một lần, khi tiện ích được tạo.
var myCodeMirror = CodeMirror[document.body];
129Thêm tên lớp CSS bổ sung vào phần tử trình bao bọc được tạo cho tiện ích con. Lưu ý rằng nút tiện ích sẽ trở thành hậu duệ của các nút có lớp CSS dành riêng cho CodeMirror và các lớp đó trong một số trường hợp có thể ảnh hưởng đến nó. Phương thức này trả về một đối tượng đại diện cho vị trí widget. Nó sẽ có một thuộc tính
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
34 chỉ vào điều khiển dòng mà nó được liên kết và các phương thức sau.
var myCodeMirror = CodeMirror[document.body];
162Xóa tiện ích.
var myCodeMirror = CodeMirror[document.body];
166Gọi điều này nếu bạn thực hiện một số thay đổi đối với nút DOM của tiện ích có thể ảnh hưởng đến chiều cao của tiện ích. Nó sẽ buộc CodeMirror cập nhật chiều cao của dòng chứa tiện ích

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

var myCodeMirror = CodeMirror[document.body];
425Đặt kích thước của trình chỉnh sửa theo chương trình [ghi đè các quy tắc CSS hiện hành].
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
75 và
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
15 có thể là số [được hiểu là pixel] hoặc đơn vị CSS [ví dụ: ___1428]. Bạn có thể chuyển
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
0 cho một trong số họ để chỉ ra rằng không nên thay đổi thứ nguyên đó.
var myCodeMirror = CodeMirror[document.body];
430Cuộn trình chỉnh sửa đến một vị trí [pixel] nhất định. Cả hai đối số có thể được để lại là
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
0 hoặc
var myCodeMirror = CodeMirror[document.body];
165 để không có hiệu lực.
var myCodeMirror = CodeMirror[document.body];
433Nhận một đối tượng
var myCodeMirror = CodeMirror[document.body];
434 đại diện cho vị trí cuộn hiện tại, kích thước của vùng có thể cuộn và kích thước của vùng hiển thị [trừ các thanh cuộn].
var myCodeMirror = CodeMirror[document.body];
435Cuộn vị trí đã cho vào chế độ xem.
var myCodeMirror = CodeMirror[document.body];
436 có thể là
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
0 để cuộn con trỏ vào chế độ xem, vị trí
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
55 để cuộn một ký tự vào chế độ xem, phạm vi pixel
var myCodeMirror = CodeMirror[document.body];
439 [trong tọa độ cục bộ của trình soạn thảo] hoặc phạm vi
var myCodeMirror = CodeMirror[document.body];
164 chứa hai vị trí ký tự hoặc hai ô vuông pixel. Tham số
var myCodeMirror = CodeMirror[document.body];
441 là tùy chọn. Khi được cung cấp, nó cho biết số lượng pixel dọc xung quanh khu vực nhất định cũng sẽ được hiển thị.
var myCodeMirror = CodeMirror[document.body];
442Trả về một đối tượng
var myCodeMirror = CodeMirror[document.body];
443 chứa tọa độ của vị trí con trỏ. Nếu
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
84 là
var myCodeMirror = CodeMirror[document.body];
445, chúng sẽ tương đối so với góc trên cùng bên trái của tài liệu có thể chỉnh sửa. Nếu là
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
68 hoặc không được cung cấp, chúng có liên quan đến góc trên cùng bên trái của trang. Nếu
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
84 là
var myCodeMirror = CodeMirror[document.body];
448, thì tọa độ có liên quan đến góc trên cùng bên trái của cửa sổ [cuộn] hiện đang hiển thị.
var myCodeMirror = CodeMirror[document.body];
188 có thể là một giá trị boolean cho biết bạn muốn bắt đầu [
var myCodeMirror = CodeMirror[document.body];
13] hay kết thúc [
var myCodeMirror = CodeMirror[document.body];
12] của lựa chọn, hoặc, nếu một đối tượng
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
55 được đưa ra, nó chỉ định vị trí chính xác mà bạn muốn đo.
var myCodeMirror = CodeMirror[document.body];
453Trả về vị trí và kích thước của một ký tự tùy ý.
var myCodeMirror = CodeMirror[document.body];
454 phải là một đối tượng
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
55. Điều này khác với
var myCodeMirror = CodeMirror[document.body];
456 ở chỗ nó sẽ cung cấp kích thước của toàn bộ ký tự, thay vì chỉ vị trí mà con trỏ sẽ có khi nó ngồi ở vị trí đó.
var myCodeMirror = CodeMirror[document.body];
457Cho một đối tượng
var myCodeMirror = CodeMirror[document.body];
458 [e. g. tọa độ của một sự kiện chuột] trả về vị trí
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
55 tương ứng với nó. Tham số
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
84 tùy chọn xác định liên quan đến tọa độ được diễn giải. Nó có thể là
var myCodeMirror = CodeMirror[document.body];
448,
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
68 [mặc định] hoặc
var myCodeMirror = CodeMirror[document.body];
445.
var myCodeMirror = CodeMirror[document.body];
464Tính toán dòng ở chiều cao pixel đã cho.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
84 có thể là một trong những chuỗi giống như
var myCodeMirror = CodeMirror[document.body];
466 chấp nhận.
var myCodeMirror = CodeMirror[document.body];
467Tính toán chiều cao của đỉnh một đường, trong hệ tọa độ được chỉ định bởi
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
84 [xem
var myCodeMirror = CodeMirror[document.body];
466], mặc định là
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
68. Khi một dòng bên dưới cuối tài liệu được chỉ định, giá trị được trả về là cuối dòng cuối cùng trong tài liệu. Theo mặc định, vị trí của văn bản thực được trả về. Nếu `includeWidgets` là đúng và dòng có tiện ích dòng, vị trí phía trên tiện ích dòng đầu tiên được trả về.
var myCodeMirror = CodeMirror[document.body];
471Trả về chiều cao dòng của phông chữ mặc định cho trình chỉnh sửa.
var myCodeMirror = CodeMirror[document.body];
472Trả về chiều rộng pixel của 'x' trong phông chữ mặc định cho trình chỉnh sửa. [Lưu ý rằng đối với các phông chữ không phải là đơn cách, điều này hầu như vô dụng và ngay cả đối với các phông chữ đơn cách, các ký tự không phải ascii có thể có chiều rộng khác].
var myCodeMirror = CodeMirror[document.body];
473Trả về một đối tượng
var myCodeMirror = CodeMirror[document.body];
164 cho biết phần bắt đầu [bao gồm] và kết thúc [không bao gồm] của phần hiện được hiển thị của tài liệu. Trong các tài liệu lớn, khi hầu hết nội dung được cuộn ra khỏi chế độ xem, CodeMirror sẽ chỉ hiển thị phần hiển thị và lề xung quanh nó. Xem thêm sự kiện
var myCodeMirror = CodeMirror[document.body];
475.
var myCodeMirror = CodeMirror[document.body];
476Nếu mã của bạn thực hiện điều gì đó để thay đổi kích thước của thành phần trình soạn thảo [việc thay đổi kích thước cửa sổ đã được lắng nghe] hoặc bỏ ẩn nó, thì có lẽ bạn nên theo dõi bằng cách gọi phương thức này để đảm bảo CodeMirror vẫn trông như dự kiến. Xem thêm addon autorefresh

Các phương thức liên quan đến chế độ, trạng thái và mã thông báo

Khi viết chức năng nhận biết ngôn ngữ, thường có thể hữu ích khi tìm hiểu kiến ​​thức mà chế độ ngôn ngữ CodeMirror có. Xem phần về các chế độ để biết mô tả chi tiết hơn về cách chúng hoạt động

var myCodeMirror = CodeMirror[document.body];
477Nhận đối tượng chế độ [bên ngoài] cho trình chỉnh sửa. Lưu ý rằng điều này khác với
var myCodeMirror = CodeMirror[document.body];
478, cung cấp cho bạn đặc tả chế độ, thay vì đối tượng chế độ được giải quyết, khởi tạo.
var myCodeMirror = CodeMirror[document.body];
479Nhận chế độ bên trong tại một vị trí nhất định. Điều này sẽ trả về giống như
var myCodeMirror = CodeMirror[document.body];
480 cho các chế độ đơn giản, nhưng sẽ trả về một chế độ bên trong cho các chế độ lồng nhau [chẳng hạn như
var myCodeMirror = CodeMirror[document.body];
481].
var myCodeMirror = CodeMirror[document.body];
482Truy xuất thông tin về mã thông báo mà chế độ hiện tại được tìm thấy trước vị trí đã cho [một đối tượng
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
55]. Đối tượng được trả về có các thuộc tính sau.
var myCodeMirror = CodeMirror[document.body];
484Ký tự [trên dòng đã cho] mà tại đó mã thông báo bắt đầu.
var myCodeMirror = CodeMirror[document.body];
485Ký tự kết thúc mã thông báo.
var myCodeMirror = CodeMirror[document.body];
486Chuỗi mã thông báo.
var myCodeMirror = CodeMirror[document.body];
487Loại mã thông báo chế độ được gán cho mã thông báo, chẳng hạn như
var myCodeMirror = CodeMirror[document.body];
488 hoặc
var myCodeMirror = CodeMirror[document.body];
489 [cũng có thể là null].
var myCodeMirror = CodeMirror[document.body];
490Trạng thái của chế độ ở cuối mã thông báo này. Nếu
var myCodeMirror = CodeMirror[document.body];
491 là đúng, mã thông báo sẽ được đảm bảo chính xác dựa trên các chỉnh sửa gần đây. Nếu sai hoặc không được chỉ định, mã thông báo sẽ sử dụng thông tin trạng thái được lưu trong bộ nhớ cache, sẽ nhanh hơn nhưng có thể không chính xác nếu các chỉnh sửa được thực hiện gần đây và đánh dấu chưa hoàn thành.
var myCodeMirror = CodeMirror[document.body];
492Điều này tương tự như
var myCodeMirror = CodeMirror[document.body];
493, nhưng thu thập tất cả các mã thông báo cho một dòng nhất định thành một mảng. Nó rẻ hơn nhiều so với việc gọi liên tục
var myCodeMirror = CodeMirror[document.body];
493, vốn phân tích lại phần của dòng trước mã thông báo cho mỗi cuộc gọi.
var myCodeMirror = CodeMirror[document.body];
495Đây là phiên bản [nhiều] rẻ hơn của
var myCodeMirror = CodeMirror[document.body];
493 hữu ích khi bạn chỉ cần loại mã thông báo tại một vị trí nhất định và không có thông tin nào khác. Sẽ trả về
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
0 cho các mã thông báo chưa được tạo kiểu và một chuỗi, có khả năng chứa nhiều tên kiểu được phân tách bằng dấu cách, nếu không.
var myCodeMirror = CodeMirror[document.body];
498Tìm nạp tập hợp các giá trị trợ giúp áp dụng cho vị trí nhất định. Người trợ giúp cung cấp một cách để tra cứu chức năng phù hợp với một chế độ. Đối số
var myCodeMirror = CodeMirror[document.body];
11 cung cấp không gian tên của trình trợ giúp [xem
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
700], trong đó các giá trị sẽ được tra cứu. Khi bản thân chế độ có một thuộc tính tương ứng với
var myCodeMirror = CodeMirror[document.body];
11, thuộc tính này trực tiếp xác định các khóa được sử dụng để tra cứu các giá trị của trình trợ giúp [có thể là một chuỗi đơn hoặc một mảng chuỗi]. Nếu không, thuộc tính
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
702 của chế độ và cuối cùng là tên của chế độ được sử dụng. Ví dụ: chế độ JavaScript có thuộc tính
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
703 chứa
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
704. Khi addon
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
705 được tải, nó sẽ xác định một trình trợ giúp có tên là
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
706 trong không gian tên
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
703. Điều này sau đó được sử dụng bởi addon
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
708 để tìm ra rằng nó có thể sử dụng chức năng gấp đó để gấp mã JavaScript. Khi bất kỳ trình trợ giúp 'toàn cầu' nào được xác định cho không gian tên đã cho, các vị từ của chúng được gọi trên chế độ và trình chỉnh sửa hiện tại và tất cả những trình trợ giúp tuyên bố chúng có thể áp dụng cũng sẽ được thêm vào mảng được trả về.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
709Trả về giá trị trợ giúp áp dụng đầu tiên. Xem
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
710.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
711Trả về trạng thái trình phân tích cú pháp của chế độ, nếu có, ở cuối số dòng đã cho. Nếu không có số dòng nào được đưa ra, trạng thái ở cuối tài liệu được trả về. Điều này có thể hữu ích để lưu trữ các lỗi phân tích cú pháp ở trạng thái hoặc nhận các loại thông tin theo ngữ cảnh khác cho một dòng.
var myCodeMirror = CodeMirror[document.body];
491 được định nghĩa là trong
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
713

phương pháp khác

var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
714CodeMirror thay đổi bộ đệm nội bộ và chỉ cập nhật cấu trúc DOM của nó sau khi nó thực hiện xong một số thao tác. Nếu bạn cần thực hiện nhiều thao tác trên phiên bản CodeMirror, bạn có thể gọi phương thức này bằng đối số hàm. 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ề. Điều này có thể nhanh hơn rất nhiều. Giá trị trả về từ phương thức này sẽ là giá trị trả về của hàm của bạn.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
715
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
716Trong trường hợp bình thường, hãy sử dụng phương pháp
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
717 ở trên. Nhưng nếu bạn muốn các hoạt động đệm diễn ra không đồng bộ hoặc không thể gói gọn tất cả trong hàm gọi lại, bạn có thể gọi
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
718 để yêu cầu CodeMirror bắt đầu thay đổi bộ đệm và
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
719 để thực sự hiển thị tất cả các bản cập nhật. Hãy cẩn thận. nếu bạn sử dụng API này và quên gọi
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
719, trình chỉnh sửa sẽ không bao giờ cập nhật.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
721Điều chỉnh độ thụt đầu dòng của dòng đã cho. Đối số thứ hai [mặc định là
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
722] có thể là một trong.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
723Lỗ thụt lề cơ sở trên thụt lề của dòng trước đó.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
724Sử dụng thụt lề thông minh của chế độ nếu có, hoạt động như
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
725 nếu không.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
726Tăng độ thụt lề của dòng lên một đơn vị thụt lề.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
727Giảm độ thụt đầu dòng của dòng.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
728Thêm [số dương] hoặc giảm [số âm] vết lõm theo lượng khoảng trắng đã cho.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
729Chuyển đổi giữa chế độ ghi đè và chèn thông thường [khi không đưa ra đối số] hoặc đặt chế độ ghi đè thành một trạng thái cụ thể [khi đưa ra đối số].
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
730Cho bạn biết liệu người dùng có thể chỉnh sửa nội dung của trình chỉnh sửa hay không.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
731Trả về chuỗi phân cách dòng ưa thích cho tài liệu này, theo tùy chọn cùng tên. Khi tùy chọn đó là
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
0, chuỗi
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
52 được trả về.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
734Chạy lệnh với tên đã cho trên trình chỉnh sửa.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
735Tính toán và trả về đối tượng
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
55 cho giá trị của
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
737 dựa trên số 0 có liên quan đến phần đầu văn bản của trình soạn thảo. Nếu
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
737 nằm ngoài phạm vi của văn bản thì đối tượng được trả về sẽ được cắt bớt để bắt đầu hoặc kết thúc văn bản tương ứng.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
739Mặt trái của
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
740.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
741Tập trung cho người biên tập.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
742Cho phép dịch chuỗi đã cho với tùy chọn
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
743.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
744Trả về trường đầu vào cho trình chỉnh sửa. Sẽ là vùng văn bản hoặc div có thể chỉnh sửa, tùy thuộc vào giá trị của tùy chọn
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
745.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
746Trả về nút DOM đại diện cho trình chỉnh sửa và kiểm soát kích thước của nó. Xóa cái này khỏi cây của bạn để xóa một phiên bản trình soạn thảo.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
747Trả về nút DOM chịu trách nhiệm cuộn trình chỉnh sửa.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
748Tìm nạp nút DOM có chứa trình soạn thảo

thuộc tính tĩnh

Bản thân đối tượng

var myCodeMirror = CodeMirror[document.body];
1 cung cấp một số thuộc tính hữu ích

var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
750Nó chứa một chuỗi cho biết phiên bản của thư viện. Đây là bộ ba số nguyên
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
751, trong đó
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
752 bằng 0 đối với bản phát hành và một số khác [thường là một] đối với ảnh chụp nhanh nhà phát triển.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
753Phương thức này cung cấp một cách khác để khởi tạo trình chỉnh sửa. Nó lấy một nút DOM vùng văn bản làm đối số đầu tiên và một đối tượng cấu hình tùy chọn làm đối số thứ hai. Nó sẽ thay thế vùng văn bản bằng một phiên bản CodeMirror và kết nối biểu mẫu của vùng văn bản đó [nếu có] để đảm bảo nội dung của trình soạn thảo được đưa vào vùng văn bản khi biểu mẫu được gửi. Văn bản trong vùng văn bản sẽ cung cấp nội dung cho trình soạn thảo. Một phiên bản CodeMirror được tạo theo cách này có ba phương thức bổ sung.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
754Sao chép nội dung của trình chỉnh sửa vào vùng văn bản.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
755Xóa trình chỉnh sửa và khôi phục vùng văn bản gốc [với nội dung hiện tại của trình chỉnh sửa]. Nếu bạn tự động tạo và hủy các trình chỉnh sửa được tạo bằng `fromTextArea` mà không hủy biểu mẫu chứa chúng, bạn nên đảm bảo gọi `toTextArea` để xóa trình chỉnh sửa, nếu không trình xử lý `"submit"` của nó trên biểu mẫu sẽ gây ra lỗi .
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
756Trả về vùng văn bản mà thể hiện dựa trên.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
757Một đối tượng chứa các giá trị mặc định cho tất cả các tùy chọn. Bạn có thể gán cho các thuộc tính của nó để sửa đổi các giá trị mặc định [mặc dù điều này sẽ không ảnh hưởng đến các trình chỉnh sửa đã được tạo].
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
758Nếu bạn muốn xác định các phương thức bổ sung theo API CodeMirror, bạn có thể sử dụng
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
759. Điều này sẽ làm cho giá trị đã cho [thường là một phương thức] được thêm vào tất cả các phiên bản CodeMirror được tạo từ đó trở đi.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
760Giống như
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
759, nhưng thay vào đó, phương thức sẽ được thêm vào giao diện cho các đối tượng
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
762.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
763Tương tự, có thể sử dụng
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
764 để xác định các tùy chọn mới cho CodeMirror.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
765 sẽ được gọi với phiên bản trình chỉnh sửa và giá trị mới khi trình chỉnh sửa được khởi tạo và bất cứ khi nào tùy chọn được sửa đổi thông qua
var myCodeMirror = CodeMirror[document.body];
97.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
767Nếu tiện ích mở rộng của bạn chỉ cần chạy một số mã bất cứ khi nào một phiên bản CodeMirror được khởi tạo, hãy sử dụng
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
768. Cung cấp cho nó một hàm làm đối số duy nhất của nó và từ đó trở đi, hàm đó sẽ được gọi [với đối tượng là đối số] bất cứ khi nào một phiên bản CodeMirror mới được khởi tạo.
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
769Đăng ký một giá trị trợ giúp với
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
5 đã cho trong không gian tên đã cho [
var myCodeMirror = CodeMirror[document.body];
11]. This is used to define functionality that may be looked up by mode. Sẽ tạo [nếu nó chưa tồn tại] một thuộc tính trên đối tượng
var myCodeMirror = CodeMirror[document.body];
1 cho
var myCodeMirror = CodeMirror[document.body];
11 đã cho, trỏ tới một đối tượng ánh xạ tên thành giá trị. 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 defaults to null, but can be set to
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
39 or
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
40 to make the position explicitly associate with the character before or after it.
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

bổ trợ

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. Bản demo có sẵn tại đây.
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ố. Khi được gọi, các kết quả phù hợp của truy vấn đã cho sẽ được hiển thị trên thanh cuộn dọc của trình chỉnh sửa. Phương thức trả về một đối tượng có phương thức
var myCodeMirror = CodeMirror[document.body];
13648 có thể được gọi để loại bỏ các kết quả trùng khớp. Phụ thuộc vào tiện ích bổ sung
var myCodeMirror = CodeMirror[document.body];
13649 và tệp
var myCodeMirror = CodeMirror[document.body];
13650 cung cấp định nghĩa mặc định [màu vàng trong suốt] của lớp CSS được áp dụng cho các kết quả khớp. Lưu ý rằng các kết quả khớp chỉ được căn chỉnh hoàn hảo nếu thanh cuộn của bạn không có các nút ở trên cùng và dưới cùng. Bạn có thể sử dụng addon
var myCodeMirror = CodeMirror[document.body];
13651 để đảm bảo điều này. Nếu addon này được tải, addon
var myCodeMirror = CodeMirror[document.body];
13652 sẽ tự động sử dụng nó.
var myCodeMirror = CodeMirror[document.body];
13653Xác định một tùy chọn
var myCodeMirror = CodeMirror[document.body];
13654, khi được đặt thành true hoặc một đối tượng tùy chọn, sẽ làm nổi bật các dấu ngoặc phù hợp bất cứ khi nào con trỏ ở bên cạnh chúng. 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. Nó có một vị trí bắt đầu và một đối tượng cấu hình tùy chọn. 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. Được bật theo mặc định.
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. Returns
var myCodeMirror = CodeMirror[document.body];
13 if a comment range was found and removed,
var myCodeMirror = CodeMirror[document.body];
12 otherwise. 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];
13706Trợ giúp gấp mã. 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];
13722Cung cấp tùy chọn
var myCodeMirror = CodeMirror[document.body];
13723, có thể được sử dụng để tạo máng xối với các điểm đánh dấu cho biết các khối có thể được gấp lại. 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
  • When
    var myCodeMirror = CodeMirror[document.body];
    13754 is specified, it will be the token style returned for the delimiter tokens [as well as
    var myCodeMirror = CodeMirror[document.body];
    13755 on the opening token and
    var myCodeMirror = CodeMirror[document.body];
    13756 on the closing token]
  • 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]. Hàm này lấy một phiên bản trình soạn thảo và một đối tượng tùy chọn, đồng thời trả về một đối tượng
var myCodeMirror = CodeMirror[document.body];
13763, trong đó
var myCodeMirror = CodeMirror[document.body];
13764 là một mảng các chuỗi hoặc đối tượng [phần hoàn thành], và
var myCodeMirror = CodeMirror[document.body];
45 và
var myCodeMirror = CodeMirror[document.body];
46 đưa ra phần đầu và phần cuối của mã thông báo đang được hoàn thành dưới dạng đối tượng
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
55. 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];
13775Văn bản sẽ được hiển thị trong 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]. Đối tượng tùy chọn cũng sẽ được chuyển đến chức năng gợi ý, có thể hiểu các tùy chọn bổ sung.
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];
009Like
var myCodeMirror = CodeMirror[document.body];
010 above, but the bindings will be added to the set of default bindings, instead of replacing them.
var myCodeMirror = CodeMirror[document.body];
011Show this many lines before and after the selected item. Default is 0. The following events will be fired on the completions object during completion.
var myCodeMirror = CodeMirror[document.body];
012Fired when the pop-up is shown.
var myCodeMirror = CodeMirror[document.body];
013Fired when a completion is selected. Passed the completion value [string or object] and the DOM node that represents it in the menu.
var myCodeMirror = CodeMirror[document.body];
014Fired when a completion is picked. Passed the completion value [string or object].
var myCodeMirror = CodeMirror[document.body];
015Fired when the completion is finished. The following events will be fired on the editor instance during completion.
var myCodeMirror = CodeMirror[document.body];
016Fired when the pop-up is being closed programmatically, e. g. , when the user types a character which matches the
var myCodeMirror = CodeMirror[document.body];
017 option. This addon depends on styles from
var myCodeMirror = CodeMirror[document.body];
018. Check out the demo for an example.
var myCodeMirror = CodeMirror[document.body];
019Defines a simple hinting function for JavaScript [
var myCodeMirror = CodeMirror[document.body];
020] and CoffeeScript [
var myCodeMirror = CodeMirror[document.body];
021] code. This will simply use the JavaScript environment that the editor runs in as a source of information about objects and their properties.
var myCodeMirror = CodeMirror[document.body];
022Defines
var myCodeMirror = CodeMirror[document.body];
023, which produces hints for XML tagnames, attribute names, and attribute values, guided by a
var myCodeMirror = CodeMirror[document.body];
024 option [a property of the second argument passed to the hinting function, or the third argument passed to
var myCodeMirror = CodeMirror[document.body];
025].
The schema info should be an object mapping tag names to information about these tags, with optionally a
var myCodeMirror = CodeMirror[document.body];
026 property containing a list of the names of valid top-level tags. The values of the properties should be objects with optional properties
var myCodeMirror = CodeMirror[document.body];
027 [an array of valid child element names, omit to simply allow all tags to appear] and
var myCodeMirror = CodeMirror[document.body];
028 [an object mapping attribute names to
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
0 for free-form attributes, and an array of valid values for restricted attributes].
The hint options accept an additional property.
var myCodeMirror = CodeMirror[document.body];
030Determines whether typed characters are matched anywhere in completions, not just at the beginning. Defaults to false. Demo here.
var myCodeMirror = CodeMirror[document.body];
031Provides schema info to the 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. Có hai tùy chọn tùy chọn,
var myCodeMirror = CodeMirror[document.body];
044, một đối tượng có tên bảng làm khóa và mảng tên cột tương ứng làm giá trị và
var myCodeMirror = CodeMirror[document.body];
045, một chuỗi tương ứng với tên bảng trong
var myCodeMirror = CodeMirror[document.body];
044 để tự động hoàn thành.
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]. Defines a
var myCodeMirror = CodeMirror[document.body];
062 option that can be set to an annotation source [for example
var myCodeMirror = CodeMirror[document.body];
063], to an options object [in which case the
var myCodeMirror = CodeMirror[document.body];
064 field is used as annotation source], or simply to
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. Đồng thời cung cấp cho trình soạn thảo một lớp CSS
var myCodeMirror = CodeMirror[document.body];
115 bất cứ khi nào nó không chứa bất kỳ văn bản nào. Xem bản trình diễn.
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. Để tách các chú thích, hãy gọi phương thức
var myCodeMirror = CodeMirror[document.body];
13648 của đối tượng.
var myCodeMirror = CodeMirror[document.body];
134Adds a
var myCodeMirror = CodeMirror[document.body];
135 option, which can be used to show one or more vertical rulers in the editor. The option, if defined, should be given an array of
var myCodeMirror = CodeMirror[document.body];
136 objects or numbers [which indicate a column]. The ruler will be displayed at the column indicated by the number or the
var myCodeMirror = CodeMirror[document.body];
137 property. The
var myCodeMirror = CodeMirror[document.body];
138 property can be used to assign a custom style to a ruler. Demo here.
var myCodeMirror = CodeMirror[document.body];
139Defines an
var myCodeMirror = CodeMirror[document.body];
140 method for CodeMirror instances, which places a DOM node above or below an editor, and shrinks the editor to make room for the node. The method takes as first argument as DOM node, and as second an optional options object. The
var myCodeMirror = CodeMirror[document.body];
141 object returned by this method has a
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 và
var myCodeMirror = CodeMirror[document.body];
176Nếu được cung cấp các phiên bản gốc của tài liệu, sẽ được hiển thị ở bên trái và bên phải của trình chỉnh sửa trong các phiên bản CodeMirror không thể chỉnh sửa. The merge interface will highlight changes between the editable document and the original[s]. To create a 2-way [as opposed to 3-way] merge view, provide only one of them.
var myCodeMirror = CodeMirror[document.body];
177Determines whether buttons that allow the user to revert changes are shown. Defaults to true.
var myCodeMirror = CodeMirror[document.body];
178Can be used to define custom behavior when the user reverts a changed chunk.
var myCodeMirror = CodeMirror[document.body];
179Sets the style used to connect changed chunks of code. By default, connectors are drawn. When this is set to
var myCodeMirror = CodeMirror[document.body];
180, the smaller chunk is padded to align with the bigger chunk instead.
var myCodeMirror = CodeMirror[document.body];
181When true [default is false], stretches of unchanged text will be collapsed. Khi một số được đưa ra, số này cho biết số lượng đường có thể nhìn thấy xung quanh các đoạn đó [mặc định là 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. Also returns
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
0 when no more characters are available.
var myCodeMirror = CodeMirror[document.body];
215
var myCodeMirror = CodeMirror[document.body];
13626 can be a character, a regular expression, or a function that takes a character and returns a boolean. If the next character in the stream 'matches' the given argument, it is consumed and returned. Otherwise,
var myCodeMirror = CodeMirror[document.body];
165 is returned.
var myCodeMirror = CodeMirror[document.body];
218Repeatedly calls
var myCodeMirror = CodeMirror[document.body];
219 with the given argument, until it fails. Returns true if any characters were eaten.
var myCodeMirror = CodeMirror[document.body];
220Shortcut for
var myCodeMirror = CodeMirror[document.body];
221 when matching white-space.
var myCodeMirror = CodeMirror[document.body];
222Moves the position to the end of the line.
var myCodeMirror = CodeMirror[document.body];
223Skips to the start of the next occurrence of the given string, if found on the current line [doesn't advance the stream if the string does not occur on the line]. Returns true if the string was found.
var myCodeMirror = CodeMirror[document.body];
224
var myCodeMirror = CodeMirror[document.body];
225Act like a multi-character
var myCodeMirror = CodeMirror[document.body];
219—if
var myCodeMirror = CodeMirror[document.body];
227 is true or not given—or a look-ahead that doesn't update the stream position—if it is false.
var myCodeMirror = CodeMirror[document.body];
228 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ự. Backing it up further than the start of the current token will cause things to break, so be careful.
var myCodeMirror = CodeMirror[document.body];
234Returns the column [taking into account tabs] at which the current token starts.
var myCodeMirror = CodeMirror[document.body];
235Tells you how far the current line has been indented, in spaces. Corrects for tab characters.
var myCodeMirror = CodeMirror[document.body];
236Get the string between the start of the current token and the current stream position.
var myCodeMirror = CodeMirror[document.body];
237Get the line
var myCodeMirror = CodeMirror[function[elt] {
  myTextArea.parentNode.replaceChild[elt, myTextArea];
}, {value: myTextArea.value}];
68 [>0] lines after the current one, in order to scan ahead across line boundaries. Note that you want to do this carefully, since looking far ahead will make mode state caching much less effective.
var myCodeMirror = CodeMirror[document.body];
239Modes added through
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
92 [and only such modes] can use this method to inspect the current token produced by the underlying mode

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

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

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

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

If you want your mode to provide smart indentation [through the

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

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

var myCodeMirror = CodeMirror[document.body];
247 string, which contains the text on the line that is being indented, and return an integer, the amount of spaces to indent. It should usually take the
var myCodeMirror = CodeMirror[document.body];
248 option into account. An indentation method may return
var myCodeMirror = CodeMirror[document.body, {
  value: "function myScript[]{return 100;}\n",
  mode:  "javascript"
}];
48 to indicate that it could not come up with a precise indentation

To work well with the commenting addon, a mode may define

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

Finally, a mode may define either an

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

So, to summarize, a mode must provide a

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

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

var myCodeMirror = CodeMirror[document.body];
264, where the first argument is a configuration object as passed to the mode constructor function, and the second argument is a mode specification as in the
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
84 option. To copy a state object, call
var myCodeMirror = CodeMirror[document.body];
266, where
var myCodeMirror = CodeMirror.fromTextArea[myTextArea];
84 is the mode that created the given state

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

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

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

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

It is possible, and encouraged, to associate your mode, or a certain configuration of your mode, with a MIME type. 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 should be the name of an option. 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
var myCodeMirror = CodeMirror[document.body];
305, tương ứng với
var myCodeMirror = CodeMirror[document.body];
306,
var myCodeMirror = CodeMirror[document.body];
307 và
var myCodeMirror = CodeMirror[document.body];
308 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];
319Remove the command
var myCodeMirror = CodeMirror[document.body];
320 if it is a user defined command. 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. Điều này sẽ không tạo ánh xạ tới các bản đồ chính không có trong bản đồ chính mặc định. Nếu không có ngữ cảnh nào được cung cấp thì ánh xạ sẽ được áp dụng cho từng chế độ bình thường, chèn và trực quan

Sự kiện

Chế độ VIM báo hiệu một vài sự kiện trên phiên bản trình chỉnh sửa. Để biết cách sử dụng ví dụ, hãy xem demo/vim. html#L101

var myCodeMirror = CodeMirror[document.body];
325Được kích hoạt khi nhấn phím và di chuột xuống khi lệnh đã hoàn thành hoặc không tìm thấy lệnh nào.
var myCodeMirror = CodeMirror[document.body];
326Được kích hoạt khi nhấn phím,
var myCodeMirror = CodeMirror[document.body];
327 nằm trong ký hiệu chính của Vim.
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. chế độ.
var myCodeMirror = CodeMirror[document.body];
331. Chế độ phụ trực quan.
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. Như với API cấu hình, các phương thức được hiển thị trên

var myCodeMirror = CodeMirror[document.body];
284 và có thể được gọi bất kỳ lúc nào

Chủ Đề