本文整理汇总了TypeScript中tinymce/core/caret/CaretWalker.CaretWalker函数的典型用法代码示例。如果您正苦于以下问题:TypeScript CaretWalker函数的具体用法?TypeScript CaretWalker怎么用?TypeScript CaretWalker使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CaretWalker函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: CaretWalker
const getPositionsUntil = (predicate: CheckerPredicate, direction: HDirection, scope: HTMLElement, start: CaretPosition): LineInfo => {
const caretWalker = CaretWalker(scope);
let currentPos = start, nextPos: CaretPosition;
const positions: CaretPosition[] = [];
while (currentPos) {
nextPos = walk(direction, caretWalker, currentPos);
if (!nextPos) {
break;
}
if (NodeType.isBr(nextPos.getNode(false))) {
if (direction === HDirection.Forwards) {
return { positions: flip(direction, positions).concat([nextPos]), breakType: BreakType.Br, breakAt: Option.some(nextPos) };
} else {
return { positions: flip(direction, positions), breakType: BreakType.Br, breakAt: Option.some(nextPos) };
}
}
if (!nextPos.isVisible()) {
currentPos = nextPos;
continue;
}
if (predicate(currentPos, nextPos)) {
const breakType = getBreakType(scope, direction, currentPos, nextPos);
return { positions: flip(direction, positions), breakType, breakAt: Option.some(nextPos) };
}
positions.push(nextPos);
currentPos = nextPos;
}
return { positions: flip(direction, positions), breakType: BreakType.Eol, breakAt: Option.none() };
};
开发者ID:danielpunkass,项目名称:tinymce,代码行数:36,代码来源:LineReader.ts
示例2: ViewBlock
UnitTest.asynctest('browser.tinymce.core.CaretWalkerTest', (success, failure) => {
const suite = LegacyUnit.createSuite();
const viewBlock = ViewBlock();
if (!Env.ceFalse) {
return;
}
const getRoot = function () {
return viewBlock.get();
};
const getChildNode = (childIndex: number) => {
return getRoot().childNodes[childIndex];
};
const setupHtml = function (html) {
viewBlock.update(html);
};
const findElm = function (selector) {
return DomQuery(selector, getRoot())[0];
};
const findElmPos = function (selector, offset) {
return CaretPosition(DomQuery(selector, getRoot())[0], offset);
};
const findTextPos = function (selector, offset) {
return CaretPosition(DomQuery(selector, getRoot())[0].firstChild, offset);
};
const logicalCaret = CaretWalker(getRoot());
suite.test('inside empty root', function () {
setupHtml('');
CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 0)), null);
CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 0)), null);
});
suite.test('on null', function () {
setupHtml('');
CaretAsserts.assertCaretPosition(logicalCaret.next(null), null);
CaretAsserts.assertCaretPosition(logicalCaret.prev(null), null);
});
suite.test('within text node in root', function () {
setupHtml('abc');
CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot().firstChild, 0)), CaretPosition(getRoot().firstChild, 1));
CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot().firstChild, 1)), CaretPosition(getRoot().firstChild, 2));
CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot().firstChild, 2)), CaretPosition(getRoot().firstChild, 3));
CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot().firstChild, 3)), null);
CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot().firstChild, 3)), CaretPosition(getRoot().firstChild, 2));
CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot().firstChild, 2)), CaretPosition(getRoot().firstChild, 1));
CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot().firstChild, 1)), CaretPosition(getRoot().firstChild, 0));
CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot().firstChild, 0)), null);
});
suite.test('within text node in element', function () {
setupHtml('<p>abc</p>');
CaretAsserts.assertCaretPosition(logicalCaret.next(findTextPos('p', 0)), findTextPos('p', 1));
CaretAsserts.assertCaretPosition(logicalCaret.next(findTextPos('p', 1)), findTextPos('p', 2));
CaretAsserts.assertCaretPosition(logicalCaret.next(findTextPos('p', 2)), findTextPos('p', 3));
CaretAsserts.assertCaretPosition(logicalCaret.next(findTextPos('p', 3)), null);
CaretAsserts.assertCaretPosition(logicalCaret.prev(findTextPos('p', 3)), findTextPos('p', 2));
CaretAsserts.assertCaretPosition(logicalCaret.prev(findTextPos('p', 2)), findTextPos('p', 1));
CaretAsserts.assertCaretPosition(logicalCaret.prev(findTextPos('p', 1)), findTextPos('p', 0));
CaretAsserts.assertCaretPosition(logicalCaret.prev(findTextPos('p', 0)), null);
});
suite.test('from index text node over comment', function () {
setupHtml('abcd<!-- x -->abcd');
CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 0)), CaretPosition(getRoot().firstChild, 0));
CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 1)), CaretPosition(getRoot().lastChild, 0));
CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 2)), CaretPosition(getRoot().firstChild, 4));
CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 3)), CaretPosition(getRoot().lastChild, 4));
});
suite.test('from text to text across elements', function () {
setupHtml('<p>abc</p><p>abc</p>');
CaretAsserts.assertCaretPosition(logicalCaret.next(findTextPos('p:first', 3)), findTextPos('p:last', 0));
CaretAsserts.assertCaretPosition(logicalCaret.prev(findTextPos('p:last', 0)), findTextPos('p:first', 3));
});
suite.test('from text to text across elements with siblings', function () {
setupHtml('<p>abc<b><!-- x --></b></p><p><b><!-- x --></b></p><p><b><!-- x --></b>abc</p>');
CaretAsserts.assertCaretPosition(logicalCaret.next(findTextPos('p:first', 3)), CaretPosition(findElm('p:last').lastChild, 0));
CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(findElm('p:last').lastChild, 0)), findTextPos('p:first', 3));
});
suite.test('from input to text', function () {
setupHtml('123<input>456');
CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 2)), CaretPosition(getRoot().lastChild, 0));
CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 1)), CaretPosition(getRoot().firstChild, 3));
});
suite.test('from input to input across elements', function () {
setupHtml('<p><input></p><p><input></p>');
CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(findElm('p:first'), 1)), CaretPosition(findElm('p:last'), 0));
CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(findElm('p:last'), 0)), CaretPosition(findElm('p:first'), 1));
//.........这里部分代码省略.........
开发者ID:mdgbayly,项目名称:tinymce,代码行数:101,代码来源:CaretWalkerTest.ts
注:本文中的tinymce/core/caret/CaretWalker.CaretWalker函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论