[TOC]
## getBounds
<!--
Retrieves the pixel position (relative to the editor container) and dimensions of a selection at a given location. The user's current selection need not be at that index. Useful for calculating where to place tooltips.
-->
返回給定選區相對于編輯器容器的的像素位置和尺寸。用戶的當前選區不需要在索引下。用于計算提示框的位置。
**方法**
```javascript
getBounds(index: Number, length: Number = 0):
{ left: Number, top: Number, height: Number, width: Number }
```
**示例**
```javascript
quill.setText('Hello\nWorld\n');
quill.getBounds(7); // Returns { height: 15, width: 0, left: 27, top: 31 }
```
## getSelection
<!--
Retrieves the user's selection range, optionally to focus the editor first. Otherwise `null` may be returned if editor does not have focus.
-->
計算用戶選擇的范圍,可選是否要求焦點在編輯器上(如果focus為true,且焦點會一直在編輯器內,且不改變選區)。如果焦點不在編輯器上,將會返回null。
**方法**
```javascript
getSelection(focus = false): { index: Number, length: Number }
```
**示例**
```javascript
var range = quill.getSelection();
if (range) {
if (range.length == 0) {
console.log('User cursor is at index', range.index);
} else {
var text = quill.getText(range.index, range.length);
console.log('User has highlighted: ', text);
}
} else {
console.log('User cursor is not in editor');
}
```
## setSelection
<!--
Sets user selection to given range, which will also focus the editor. Providing `null` as the selection range will blur the editor. [Source](/docs/api/#events) may be `"user"`, `"api"`, or `"silent"`.
-->
給定范圍設置用戶的選區,同時焦點在編輯器上。作為選區傳入 `null`,將會使編輯器失去焦點。[Source](事件events.md) 可能是 `"user"`, `"api"`,或者 `"silent"`.
**方法**
```javascript
setSelection(index: Number, length: Number, source: String = 'api')
setSelection(range: { index: Number, length: Number },
souce: String = 'api')
```
**示例**
```javascript
quill.setSelection(0, 5);
```
- 前言
- 快速開始(quick_start)
- 下載(download)
- 配置(configuration)
- 格式(formats)
- API
- 內容(contents)
- 格式化(formatting)
- 選區(selection)
- 編輯器(editor)
- 事件(events)
- 模型(model)
- 擴展(extension)
- 增量(Delta)
- 模塊(modules)
- 工具欄(toolbar)
- 鍵盤(keyboard)
- 歷史記錄(history)
- 粘貼板(clipboard)
- 語法高亮(syntax)
- 主題(themes)
- 更多教程
- 為什么選擇Quill?
- 如何定制Quill?
- 設計Delta格式(未翻譯)
- 構建一個自定義模塊
- 將Quill加入你的編譯管線(未翻譯)
- Cloning Medium with Parchment
- 和其它富文本編輯器的對比(未翻譯)
- Designing the Delta Format
- 擴展模塊
- vue-quill-editor
- quill-image-extend-module
- quill-image-resize-module
- quill-image-drop-module
- quill-better-table
- quilljs-table
- 更多模塊