• 全国 [切换]
  • 二维码
    财发网

    手机WAP版

    手机也能找商机,信息同步6大终端平台!

    微信小程序

    微信公众号

    当前位置: 首页 » 行业新闻 » 热点新闻 » 正文

    Commentary on Lexical iOS (2)

    放大字体  缩小字体 发布日期:2024-12-24 09:50:18   浏览次数:1  发布人:3c33****  IP:124.223.189***  评论:0
    导读

    Lexical iOS is a rich-text editor on iOS parallel to the its javascript counterpart, Lexical Javascript. Lexical iOS is based on TextKit 1.Now we focus on the design of selection. 1 Concepts A select

    Lexical iOS is a rich-text editor on iOS parallel to the its javascript counterpart, Lexical Javascript. Lexical iOS is based on TextKit 1.

    Now we focus on the design of selection.

    1 Concepts

    A selection specifies a part of a document. We have three variants:

    • A range selection specifies a segment in a document.
    • A node selection specifies a set of nodes in a document.
    • A grid selection specifies a sub-rectangle in a grid.

    1.1 Representation

    Range Selection. A range selection is represented by a pair of selection points. A selection point specifies a location in the document, which is either a position in a text node or a position in an element node. The segment specified by the range selection is the part of document between its end points, called anchor and focus.

    Node Selection. A node selection is explicitly represented by a set of nodes, actually, by a set of node keys which can be used to identify the set of nodes.

    Grid Selection. A grid selection is represented by a grid node together with an anchor node and a focus node in it.

    The range selection is the most essential of the three variants. We will focus on it in the following.

    2 Implementation of Range Selection

    2.1 Clarification on the selected part

    Consider a range selection selection with the anchor at the first child of an element element, and the focus at the location past the last child of the same element. Then what should selection.getNodes() return? The list of the children, or all the nodes of the subtrees rooted at these children. We choose the latter in Lexical iOS.

    It is clear that we intend to select the subtrees. The ambiguity lies in that a node can be interpreted as a node in itself or as the root of a subtree. Either way is fine as long as we are clear which interpretation we are up to, and implement the operations consistently.

    2.2 baseSelection: the protocol

    Method Semantic
    dirty
    clone() -
    extract()
    getNodes()
    getTextContent() Returns a plain text representation of the content of the selection.
    insertRawText(_:) Deal with \n and insert.
    isSelection(_:) Checks for selection equality.
    insertNodes(nodes:selectStart:)
    deleteCharacter(isBackwards:) -
    deleteWord(isBackwards:) -
    deleteLine(isBackwards:) -
    insertParagraph() -
    insertLineBreak(selectStart:) soft line break
    insertText(_:)

    2.3 Point: the selection point

    Field Semantic
    key: NodeKey
    type: SelectionType
    offset: Int
    selection: baseSelection? The selection that contains this point.

    2.4 RangeSelection: the range selection

    2.4.1 Fields

    Constituents

    Field Semantic
    anchor -
    focus -

    Properties

    Field Semantic
    dirty -
    format -
    style -

    2.4.2 Methods

    Implementation of baseSelection protocol:

    Method Implementation
    dirty member field
    clone() -
    extract() Obtain getNodes() and cut at the ends.
    getNodes() Return all nodes that are selected as a whole or partially.
    getTextContent() Just concatenate.
    insertRawText(_:) Split by \n and insert the results.
    isSelection(_:) -
    insertNodes(nodes:selectStart:) ~200 Lines.
    deleteCharacter(isBackwards:) ~100 Lines.
    deleteWord(isBackwards:) Invoke modify(alter:isBackward:granularity:).
    deleteLine(isBackwards:) Invoke modify(alter:isBackward:granularity:).
    insertParagraph() ~100 Lines.
    insertLineBreak(selectStart:) -
    insertText(_:) ~300 Lines.

    Miscellaneous:

    Method Semantic Note
    hasFormat(type:) -
    isBackward() -
    isCollapsed() -
    getCharacterOffsets(selection:) Returns the character offsets of the two ends
    setTextNodeRange(...) -
    applyNativeSelection(_:) -
    applySelectionRange(_:affinity:)
    init?(nativeSelection:)
    formatText(formatType:) ~150 Lines.
     
    (文/匿名(若涉版权问题请联系我们核实发布者) / 非法信息举报 / 删稿)
    打赏
    免责声明
    • 
    本文为昵称为 3c33**** 发布的作品,本文仅代表发布者个人观点,本站未对其内容进行核实,请读者仅做参考,如若文中涉及有违公德、触犯法律的内容,一经发现,立即删除,发布者需自行承担相应责任。涉及到版权或其他问题,请及时联系我们154208694@qq.com删除,我们积极做(权利人与发布者之间的调停者)中立处理。郑重说明:不 违规举报 视为放弃权利,本站不承担任何责任!
    有个别老鼠屎以营利为目的遇到侵权情况但不联系本站或自己发布违规信息然后直接向本站索取高额赔偿等情况,本站一概以诈骗报警处理,曾经有1例诈骗分子已经绳之以法,本站本着公平公正的原则,若遇 违规举报 我们100%在3个工作日内处理!
    0相关评论
     

    (c)2008-现在 c8f.com All Rights Reserved.