OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
reader
/
_backup
/
tinymce
/
tinymce
/
src
/
core
/
main
/
ts
/
selection
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
02/20/2020 05:44:43 AM
rwxr-xr-x
📄
CaretRangeFromPoint.ts
2.6 KB
02/20/2020 05:44:11 AM
rw-r--r--
📄
DetailsElement.ts
1.19 KB
02/20/2020 05:44:11 AM
rw-r--r--
📄
ElementSelection.ts
4.83 KB
02/20/2020 05:44:12 AM
rw-r--r--
📄
EventProcessRanges.ts
593 bytes
02/20/2020 05:44:12 AM
rw-r--r--
📄
FragmentReader.ts
3.82 KB
02/20/2020 05:44:13 AM
rw-r--r--
📄
GetSelectionContent.ts
2.12 KB
02/20/2020 05:44:15 AM
rw-r--r--
📄
MultiClickSelection.ts
1.64 KB
02/20/2020 05:44:16 AM
rw-r--r--
📄
MultiRange.ts
955 bytes
02/20/2020 05:44:17 AM
rw-r--r--
📄
NormalizeRange.ts
10.02 KB
02/20/2020 05:44:17 AM
rw-r--r--
📄
RangeCompare.ts
580 bytes
02/20/2020 05:44:18 AM
rw-r--r--
📄
RangeInsertNode.ts
1.52 KB
02/20/2020 05:44:18 AM
rw-r--r--
📄
RangeNodes.ts
946 bytes
02/20/2020 05:44:19 AM
rw-r--r--
📄
RangeNormalizer.ts
1.69 KB
02/20/2020 05:44:19 AM
rw-r--r--
📄
RangeWalk.ts
4.38 KB
02/20/2020 05:44:20 AM
rw-r--r--
📄
SelectionBookmark.ts
3.36 KB
02/20/2020 05:44:20 AM
rw-r--r--
📄
SelectionRestore.ts
1.98 KB
02/20/2020 05:44:21 AM
rw-r--r--
📄
SelectionUtils.ts
3.65 KB
02/20/2020 05:44:21 AM
rw-r--r--
📄
SetSelectionContent.ts
2.44 KB
02/20/2020 05:44:22 AM
rw-r--r--
📄
SimpleTableModel.ts
4.08 KB
02/20/2020 05:44:22 AM
rw-r--r--
📄
SplitRange.ts
1.94 KB
02/20/2020 05:44:23 AM
rw-r--r--
📄
TableCellSelection.ts
1.25 KB
02/20/2020 05:44:24 AM
rw-r--r--
📄
WordSelection.ts
1.47 KB
02/20/2020 05:44:24 AM
rw-r--r--
Editing: SelectionBookmark.ts
Close
/** * Copyright (c) Tiny Technologies, Inc. All rights reserved. * Licensed under the LGPL or a commercial license. * For LGPL see License.txt in the project root for license information. * For commercial licenses see https://www.tiny.cloud/ */ import { document } from '@ephox/dom-globals'; import { Fun, Option } from '@ephox/katamari'; import { PlatformDetection } from '@ephox/sand'; import { Compare, Element, Node, Text, Traverse, Selection } from '@ephox/sugar'; import Editor from '../api/Editor'; const browser = PlatformDetection.detect().browser; const clamp = function (offset, element) { const max = Node.isText(element) ? Text.get(element).length : Traverse.children(element).length + 1; if (offset > max) { return max; } else if (offset < 0) { return 0; } return offset; }; const normalizeRng = function (rng) { return Selection.range( rng.start(), clamp(rng.soffset(), rng.start()), rng.finish(), clamp(rng.foffset(), rng.finish()) ); }; const isOrContains = function (root, elm) { return Compare.contains(root, elm) || Compare.eq(root, elm); }; const isRngInRoot = function (root) { return function (rng) { return isOrContains(root, rng.start()) && isOrContains(root, rng.finish()); }; }; const shouldStore = function (editor: Editor) { return editor.inline === true || browser.isIE(); }; const nativeRangeToSelectionRange = function (r) { return Selection.range(Element.fromDom(r.startContainer), r.startOffset, Element.fromDom(r.endContainer), r.endOffset); }; const readRange = function (win) { const selection = win.getSelection(); const rng = !selection || selection.rangeCount === 0 ? Option.none() : Option.from(selection.getRangeAt(0)); return rng.map(nativeRangeToSelectionRange); }; const getBookmark = function (root) { const win = Traverse.defaultView(root); return readRange(win.dom()) .filter(isRngInRoot(root)); }; const validate = function (root, bookmark) { return Option.from(bookmark) .filter(isRngInRoot(root)) .map(normalizeRng); }; const bookmarkToNativeRng = function (bookmark) { const rng = document.createRange(); try { // Might throw IndexSizeError rng.setStart(bookmark.start().dom(), bookmark.soffset()); rng.setEnd(bookmark.finish().dom(), bookmark.foffset()); return Option.some(rng); } catch (_) { return Option.none(); } }; const store = function (editor: Editor) { const newBookmark = shouldStore(editor) ? getBookmark(Element.fromDom(editor.getBody())) : Option.none(); editor.bookmark = newBookmark.isSome() ? newBookmark : editor.bookmark; }; const storeNative = function (editor: Editor, rng) { const root = Element.fromDom(editor.getBody()); const range = shouldStore(editor) ? Option.from(rng) : Option.none(); const newBookmark = range.map(nativeRangeToSelectionRange) .filter(isRngInRoot(root)); editor.bookmark = newBookmark.isSome() ? newBookmark : editor.bookmark; }; const getRng = function (editor: Editor) { const bookmark = editor.bookmark ? editor.bookmark : Option.none(); return bookmark .bind(Fun.curry(validate, Element.fromDom(editor.getBody()))) .bind(bookmarkToNativeRng); }; const restore = function (editor: Editor) { getRng(editor).each(function (rng) { editor.selection.setRng(rng); }); }; export default { store, storeNative, readRange, restore, getRng, getBookmark, validate };