ace -- api
The main class required to set up an Ace instance in the browser.
在浏览器中设置一个ace实例所需要的主要类。
Methods
Creates a new EditSession
, and returns the associated Document
.
创建一个新的 EditSession, 并返回相关联的Document
参数
1. text (Document | string)
必须,如果text 是 Document, 则它将 EditSession与它关联起来。否则, 使用初始的text创建一个新的Document。
2. mode (TextMode)
必须,文档使用的初始语言mode。
- edit(String | DOMElement el)
Embeds the Ace editor into the DOM, at the element provided by el
.
将Ace编辑器嵌入到在el提供的DOM元素中,
参数
1. el (String | DOMElement)
必须。元素id或者 一个 DOM 元素本身。
require(String moduleName)
Provides access to require in packed noconflict mode
提供打包后的无冲突的mode 的引用
参数
moduleName (string)
必须。
Anchor
Defines the floating pointer in the document. Whenever text is inserted or deleted before the cursor, the position of the cursor is updated.
定义文档中的浮动指针。每当在光标之前插入或删除文本时,光标的位置就会被更新。
Constructors
Events
- Anchor.on("change", function(Object e))
Fires whenever the anchor position changes. Both of these objects have a row
and column
property corresponding to the position. Events that can trigger this function include setPosition()
每当anchor的位置发生变化是触发。 这两个对象都具有与位置对应的row和column的属性。可以触发此函数的事件包括 setPosition()
参数:
1. e (object)
必须。包含anchor位置的信息的对象。它有两个属性:
old: 描述原来 Anchor位置的对象。
value: 描述新 Anchor位置的对象。
Methods
-
- detach()
When called, the 'change'
event listener is removed.
当被调用时, ‘change’事件监听器被删除。
-
- getDocument() -----> Document
Returns the current document.
返回当前文档。
- getPosition() -----> Object
Returns an object identifying the row
and column
position of the current anchor.
返回一个对象,该对象标识当前 anchor的 row 和column的位置。
- onChange() Undocumented
Sets the anchor position to the specified row and column. If noClip
is true
, the position is not clipped.
将anchor的位置设置为指定的 row 和 column。 如果 noClip 为 true, 则不剪断位置,
参数
1. row (Number)
必须。将anchor移动到 row index
2. column (Number)
必须。将anchor 移动到 column index
3. noCLip (Boolean)
必须。标识是否希望建材该位置。
BackgroundTokenizer
Tokenizes the current Document
in the background, and caches the tokenized rows for future use.
在后台标记当前 Document, 并缓存当前标记的 rows以供将来使用。
If a certain row is changed, everything below that row is re-tokenized.
如果某行被更改,则该行下面的所有内容都被重新标记。
Constructors
Events
- BackgroundTokenizer.on("update", function(Object e))
Fires whenever the background tokeniziers between a range of rows are going to be updated.
每当一个行之间的后台记录器将被更新时触发。
参数:
1. e (Object)
必须。一个包含两个属性的对象, first 和 last, 指示正在更新的区域的行。
Methods
- getState(Number row)
Returns the state of tokenization at the end of a row.
返回行结束时的标记化状态。
参数
1. row (NUmber)
必须。获取状态的行。
- getTokens(Number row)
Gives list of tokens of the row. (tokens are cached)
给出行的tokens列表 (tokens被缓存)
参数
1. row (Number)
必须。获取token的行。
- setDocument(Document doc)
Sets a new document to associate with this object.
设置与此对象关联的新文档
参数
1. doc (Document)
必须。与之关联的新文档。
- setTokenizer(Tokenizer tokenizer)
Sets a new tokenizer for this object.
为这个对象设置一个新的记录器。
参数
1. tokenizer (Tokenizer)
必须。新的tokenizer使用
- start(Number startRow)
Starts tokenizing at the row indicated.
开始标记所指示的行
参数
1. startRow (Number)
必须。要开始的行。
- stop()
Stops tokenizing.
停止 标记
Document
Contains the text of the document. Document can be attached to several EditSession
s.
包含文本的文档。Document可以附加到多个 EditSessin中。
At its core, Document
s are just an array of strings, with each row in the document matching up to the array index.
在其核心,Document指示一个字符串数组。文档中的每一行与数组索引匹配。
Constructors
Events
- Document.on("change", function(Object e))
Fires whenever the document changes.
文档更改时触发。
Several methods trigger different "change"
events. Below is a list of each action type, followed by each property that's also available:
几种方法触发不同的 change 事件。 下面是每个动作类型的列表,后面还有每个可用的属性:
-
"insertLines"
(emitted byDocument.insertLines()
) 通过 Document.insertLines() 触发range
: theRange
of the change within the document 文档Range更改。lines
: the lines in the document that are changing 文档中行正在改变"insertText"
(emitted byDocument.insertNewLine()
) 通过 Document.insertNewLine() 触发range
: theRange
of the change within the documenttext
: the text that's being added 正在添加文本"removeLines"
(emitted byDocument.insertLines()
) 通过 Document.insertLines()触发range
: theRange
of the change within the documentlines
: the lines in the document that were removed 文档中行移除nl
: the new line character (as defined byDocument.getNewLineCharacter()
) 新行字符 (通过 Document.getNewLineCharater() 定义)"removeText"
(emitted byDocument.removeInLine()
andDocument.removeNewLine()
)range
: theRange
of the change within the documenttext
: the text that's being removed
参数
1. e (Object)
必须。包含至少一个名为 action 的属性。 action 指示触发更改的操作。每个action也有一组额外的属性。
Methods
- applyDeltas(Object deltas)
Applies all the changes previously accumulated. These can be either 'includeText'
, 'insertLines'
, 'removeText'
, and 'removeLines'
.
应用以前积累的所有更改。这些可以是 includeText,....
参数
1. deltas (Object)
必须。
- getAllLines()
Returns all lines in the document as string array. Warning: The caller should not modify this array!
将文档中的所有行作为字符串数组返回。 注意: 调用方不应该修改这个数组。
- getLength()
Returns the number of rows in the document.
返回文档的行数。
- getLine(Number row)
Returns a verbatim copy of the given line as it is in the document
返回文档中给定行的逐字拷贝。
- getNewLineCharacter() String
Returns the newline character that's being used, depending on the value of newLineMode
.
返回正在使用的换行符,这取决与newLineMode的值。
- getNewLineMode() String
Returns the type of newlines being used; either windows
, unix
, or auto
返回正在使用的换行类型。 可以是 windows, unix, 或者 auto。
- getTextRange(Range range)
Given a range within the document, this function returns all the text within that range as a single string.
在给定文档范围中,该函数将该范围内的所有文本作为单个字符串返回。
- getValue()
Returns all the lines in the document as a single string, split by the new line character.
将文档中的所有行作为单个字符串返回,由换行符分隔。
Converts an index position in a document to a {row, column}
object.
将文档中索引位置替换成 {row, column}对象。
Index refers to the "absolute position" of a character in the document. For example:
索引指的是文件中字符的绝对位置。比如
var x = 0; // 10 characters, plus one for newline
var y = -1;
Here, y
is an index 15: 11 characters for the first row, and 5 characters until y
in the second.
这里,y 是第一行的索引15:11字符, 第二行的5个字符直到 y。
- isNewLine(String text)
Returns true
if text
is a newline character (either \r\n
, \r
, or \n
).
- removeNewLine(Number row)
Removes the new line between row
and the row immediately following it. This method also triggers the 'change'
event.
- revertDeltas(Object deltas)
Reverts any changes previously applied. These can be either 'includeText'
, 'insertLines'
, 'removeText'
, and 'removeLines'
.
还原先前应用的任何更改。这些更改可以是 includeText .....
- setNewLineMode(String newLineMode)
Sets the new line mode.
- setValue(String text)
Replaces all the lines in the current Document
with the value of text
.
将当前Document中所有行替换为 text的值
EditSession
Constructors
Events
- EditSession.on("change", function(Object e))
Emitted when the document changes.
当文档改变时触发。
- EditSession.on("changeAnnotation", function())
Emitted when an annotation changes, like through EditSession.setAnnotations()
.
当注释改变时触发,比如通过 EditSession.setAnnotations()
- EditSession.on("changeBackMarker", function())
Emitted when a back marker changes.
当后置标记发生变化时触发。
- EditSession.on("changeBreakpoint", function())
Emitted when the gutter changes, either by setting or removing breakpoints, or when the gutter decorations change.
当gutters发生变化,或者通过设置或移除断点或者当gutters装饰发生变化时触发。
- EditSession.on("changeFold", function())
Emitted when a code fold is added or removed.
当代码折叠添加或者移除时触发。
- EditSession.on("changeFrontMarker", function())
Emitted when a front marker changes.
当 前标记改变时触发。
- EditSession.on("changeMode", function())
Emitted when the current mode changes.
当 当前mode改变时触发。
- EditSession.on("changeOverwrite", function())
Emitted when the ability to overwrite text changes, via EditSession.setOverwrite()
.
当通过 EditSession.setOverWrite() 更改覆盖文本的能力时触发。
- EditSession.on("changeScrollLeft", function(Number scrollLeft))
Emitted when the scroll left changes.
当滚动条左改变时触发。
- EditSession.on("changeScrollTop", function(Number scrollTop))
Emitted when the scroll top changes.
- EditSession.on("changeTabSize", function())
Emitted when the tab size changes, via EditSession.setTabSize()
.
通过 EditSession.setTabSize() 改变 tab 大小时触发。
- EditSession.on("changeWrapLimit", function())
Emitted when the wrapping limit changes.
当包装限制改变时触发。
- EditSession.on("changeWrapMode", function())
Emitted when the wrap mode changes.
当包裹mode改变时触发。
- EditSession.on("tokenizerUpdate", function(Object e))
Emitted when a background tokenizer asynchronously processes new rows.
当后台记录器异步处理新行时触发。参数e包含一个data属性的对象,该对象包含关于更改行的信息。
Methods
Adds a new marker to the given Range
. If inFront
is true
, a front marker is defined, and the 'changeFrontMarker'
event fires; otherwise, the 'changeBackMarker'
event fires.
在给定的Range中添加新的标记。 如果 inFront为true,则定义一个前端 标记, 并且触发 changeFrontMarker事件,否则,触发changeBackMarker事件。
- clearAnnotations()
Clears all the annotations for this session. This function also triggers the 'changeAnnotation'
event.
清除此会话的所有注释。该函数会触发 changeAnnotation事件。
- clearBreakpoint(Number row)
Removes a breakpoint on the row number given by rows
. This function also emits the 'changeBreakpoint'
event.
移除给定rows上所有的断点。该函数会触发 changeBreakpoint事件。
- clearBreakpoints()
Removes all breakpoints on the rows. This function also emites the 'changeBreakpoint'
event.
- getAnnotations() Object
Returns the annotations for the EditSession
.
返回 EditSession的注释。
- getBreakpoints() Number
Returns an array of numbers, indicating which rows have breakpoints.
返回一个数字数组,指示哪些行具有断点。
- getDocument() Document
Returns the Document
associated with this session.
返回与此会话关联的Document
- getLength() Number
Returns the number of rows in the document.
返回文档中的行数。
- getMode() TextMode
Returns the current text mode.
- getNewLineMode() String
Returns the current new line mode.
- getOverwrite()
Returns true
if overwrites are enabled; false
otherwise.
如果启用重写,则返回 true,否则返回false。
- getScreenLength() Number
Returns the length of the screen.
获取从屏幕的长度。
- getScreenWidth() Number
Returns the width of the screen.
- getScrollLeft() Number
Returns the value of the distance between the left of the editor and the leftmost part of the visible content.
返回编辑器左侧与可见内容的最左边部分之间的距离值。
- getScrollTop() Number
Returns the value of the distance between the top of the editor and the topmost part of the visible content.
- getSelection()
Returns selection object.
- getState(Number row)
Returns the state of tokenization at the end of a row.
返回结束行时的标记化状态。
- getTabSize()
Returns the current tab size.
- getTabString()
Returns the current value for tabs. If the user is using soft tabs, this will be a series of spaces (defined by getTabSize()
); otherwise it's simply '\t'
.
- getTokens(Number row)
Starts tokenizing at the row indicated. Returns a list of objects of the tokenized rows.
开始标记所指示的行。返回标记化行的对象列表。
- getUndoManager()
Returns the current undo manager.
返回当前撤销管理器。
- getUseSoftTabs() Boolean
Returns true
if soft tabs are being used, false
otherwise.
如果soft tab 正在使用返回true, 否则返回false
- getUseWorker()
Returns true
if workers are being used.
如果正在使用workers, 返回true。
- getUseWrapMode() Boolean
Returns true
if wrap mode is being used; false
otherwise.
- getWrapLimit() Number
Returns the value of wrap limit.
返回 wrap限制值。
- getWrapLimitRange() Object
Returns an object that defines the minimum and maximum of the wrap limit; it looks something like this: { min: wrapLimitRange_min, max: wrapLimitRange_max }
返回定义包限制的最小值和最大值的对象,
- highlight() Undocumented
- highlightLines() Undocumented
Indents all the rows, from startRow
to endRow
(inclusive), by prefixing each row with the token in indentString
. If indentString
contains the '\t'
character, it's replaced by whatever is defined by getTabString()
将从startRow到 endRow之间的所有行缩进,通过在indentString中用token预先装订每行。如果缩进字符串包含 '\t' 字符, 则有 getTabString()定的任何内容替换它。
- isTabStop(Object position)
Returns true
if the character at the position is a soft tab.
- onChange() Undocumented
- onChangeFold() Undocumented
- onReloadTokenizer(Object e)
Reloads all the tokens on the current session. This function calls BackgroundTokenizer.start ()
to all the rows; it also emits the 'tokenizerUpdate'
event.
- outdentRows(Range range)
Outdents all the rows defined by the start
and end
properties of range
.
- redo()Undocumented
- removeMarker(Number markerId)
Removes the marker with the specified ID. If this marker was in front, the 'changeFrontMarker'
event is emitted. If the marker was in the back, the 'changeBackMarker'
event is emitted.
- reset()Undocumented
- resetCaches()Undocumented
- screenToDocumentColumn() Undocumented
- screenToDocumentRow() Undocumented
- setAnnotations(Array annotations)
Sets annotations for the EditSession
. This functions emits the 'changeAnnotation'
event.
- setBreakpoints(Array rows)
Sets a breakpoint on every row number given by rows
. This function also emites the 'changeBreakpoint'
event.
- setDocument(Document doc)
Sets the EditSession
to point to a new Document
. If a BackgroundTokenizer
exists, it also points to doc
.
- setMode() Undocumented
- setNewLineMode(String newLineMode)
Sets the new line mode.
- setOverwrite(Boolean overwrite)
Pass in true
to enable overwrites in your session, or false
to disable.
- setScrollLeft(Object scrollLeft)
Sets the value of the distance between the left of the editor and the leftmost part of the visible content.
- setScrollTop(Number scrollTop)
This function sets the scroll top value. It also emits the 'changeScrollTop'
event.
- setTabSize(Number tabSize)
Set the number of spaces that define a soft tab; for example, passing in 4
transforms the soft tabs to be equivalent to four spaces. This function also emits the changeTabSize
event.
- setUndoManager(UndoManager undoManager)
Sets the undo manager.
- setUndoSelect(Boolean enable)
Enables or disables highlighting of the range where an undo occured.
- setUseSoftTabs(Boolean useSoftTabs)
Pass true
to enable the use of soft tabs. Soft tabs means you're using spaces instead of the tab character ('\t'
).
- setUseWorker(Boolean useWorker)
Identifies if you want to use a worker for the EditSession
.
- setUseWrapMode(Boolean useWrapMode)
Sets whether or not line wrapping is enabled. If useWrapMode
is different than the current value, the 'changeWrapMode'
event is emitted.
- setValue(String text)
Sets the session text.
- toggleOverwrite()
Sets the value of overwrite to the opposite of whatever it currently is.
- undo() Undocumented