Quill中文文档
  • 简介
  • 文档(Document)
    • 快速开始(QuickStart)
    • 下载(Download)
    • 配置项(Configuration)
    • 格式化(Formats)
    • API
      • content
      • formatting
      • selection
      • editor
      • events
      • model
      • extension
    • Delta
    • 模块(Modules)
      • 工具栏(Toolbar)
      • 键盘(Keyboard)
      • 历史(History)
      • 剪贴板(Clipboard)
      • 格式化(Formula)
      • 语法高亮(Syntax Highlighter)
    • 主题(Themes)
  • 指南(Guides)
    • 为什么要用Quill?(Why Quill)
    • 怎么自定义Quill
    • 将Quill添加到你的构建系统
    • 构建自定义模块
    • 通过Parchment克隆Medium
    • 设计Delta的格式
    • 与其他富文本编辑器对比
    • 升级到1.0
  • 其他相关库(Other)
    • Parchment
    • 自定义总结
  • 更新日志
Powered by GitBook
On this page
  • getBounds
  • getSelection
  • setSelection
  1. 文档(Document)
  2. API

selection

getBounds

检索给定位置的像素位置(相对于编辑器容器)和选区的尺寸。用户的当前选择不需要在该索引处。用于计算工具提示的放置位置。

Methods

getBounds(index: Number, length: Number = 0):
  { left: Number, top: Number, height: Number, width: Number }

Examples

quill.setText('Hello\nWorld\n');
quill.getBounds(7);  // 返回值 { height: 15, width: 0, left: 27, top: 31 }

getSelection

检索用户的选择范围,可选地首先关注编辑器。除此之外,如果编辑没有焦点,可能会返回一个null。

Methods

getSelection(focus = false): { index: Number, length: Number }

Examples

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

将用户的选择设置为给定的范围,这个主要用在编辑器上。提供null作为选择范围将模糊编辑器。来源可能是‘user’、‘api’或者‘silent’。

Methods

setSelection(index: Number, length: Number, source: String = 'api')
setSelection(range: { index: Number, length: Number },
             souce: String = 'api')

Examples

quill.setSelection(0, 5);
PreviousformattingNexteditor

Last updated 5 years ago