UNPKG

usfm-editor

Version:
85 lines (71 loc) 2.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SelectionTransforms = void 0; var _slate = require("slate"); var _MyEditor = require("./MyEditor"); const SelectionTransforms = { selectDOMNodeStart, selectNextSiblingNonEmptyText, moveToStartOfFirstLeaf, moveToEndOfLastLeaf }; exports.SelectionTransforms = SelectionTransforms; function selectDOMNodeStart(editor, domNode) { const path = _MyEditor.MyEditor.getPathFromDOMNode(editor, domNode); _slate.Transforms.select(editor, { path: path, offset: 0 }); } function selectNextSiblingNonEmptyText(editor) { if (!editor.selection || !_slate.Range.isCollapsed(editor.selection)) return; const [textNode, _path] = _slate.Editor.node(editor, editor.selection); if (_slate.Text.isText(textNode) && textNode.text == "") { const thisPath = editor.selection.anchor.path; const [_nextNode, nextPath] = _slate.Editor.next(editor) || [null, null]; if (nextPath && _slate.Path.equals(_slate.Path.parent(thisPath), _slate.Path.parent(nextPath))) { _slate.Transforms.select(editor, { path: nextPath, offset: 0 }); } } } function moveToStartOfFirstLeaf(editor, path, options) { const [_leaf, leafPath] = _slate.Editor.leaf(editor, path, { edge: "start" }); if (options !== null && options !== void 0 && options.edge) { _slate.Transforms.setPoint(editor, { path: leafPath, offset: 0 }, { edge: options.edge }); } else { _slate.Transforms.select(editor, { path: leafPath, offset: 0 }); } } function moveToEndOfLastLeaf(editor, path, options) { const [leaf, leafPath] = _slate.Editor.leaf(editor, path, { edge: "end" }); if (options !== null && options !== void 0 && options.edge) { _slate.Transforms.setPoint(editor, { path: leafPath, offset: leaf.text.length }, { edge: options.edge }); } else { _slate.Transforms.select(editor, { path: leafPath, offset: leaf.text.length }); } }