How to use getElementOffset method in Testcafe

Best JavaScript code snippet using testcafe

code_editor.js

Source:code_editor.js Github

copy

Full Screen

...73 codeEditorInitializer.init(options);74 equal(codeEditor.$scrollLayout[0].offsetWidth, 800);75 equal(codeEditor.$scrollLayout[0].offsetHeight, 230);76 equal(codeEditor._getEditorText(), options.text);77 var cursorOffset = getElementOffset(codeEditor.$cursor);78 equal(codeEditor.$scrollLayout.css('overflow-y'), 'hidden');79 deepEqual(cursorOffset, getNullOffset());80 });81 test('testUIWithNotFixedHeight', function () {82 options = {83 width: 600,84 height: 400,85 text: 'The quick brown fox jumps over a lazy dog\r\none,two.tree',86 fixedHeight: false87 };88 codeEditorInitializer.init(options);89 equal(codeEditor.$scrollLayout[0].offsetWidth, 600);90 ok(codeEditor.$scrollLayout[0].offsetHeight >= 400);91 equal(codeEditor._getEditorText(), options.text);92 var cursorOffset = getElementOffset(codeEditor.$cursor);93 deepEqual(cursorOffset, getNullOffset());94 });95 test('testUIWithoutText', function () {96 options = {97 width: 600,98 height: 400,99 fixedHeight: false100 };101 codeEditorInitializer.init(options);102 equal(codeEditor.$scrollLayout[0].offsetWidth, 600);103 ok(codeEditor.$scrollLayout[0].offsetHeight >= 400);104 equal(codeEditor._getEditorText(), '');105 equal(codeEditor.$lines.length, 1);106 var cursorOffset = getElementOffset(codeEditor.$cursor);107 deepEqual(cursorOffset, getNullOffset());108 });109 test('testUIWithVerticalScrollBar', function () {110 options = {111 width: 800,112 height: 18,113 text: 'The\r\nquick\r\nbrown',114 fixedHeight: true115 };116 codeEditorInitializer.init(options);117 equal(codeEditor.$scrollLayout[0].offsetWidth, 800);118 equal(codeEditor.$scrollLayout[0].offsetHeight, 18);119 var cursorOffset = getElementOffset(codeEditor.$cursor);120 equal(codeEditor.$scrollLayout.css('overflow-y'), 'scroll');121 deepEqual(cursorOffset, getNullOffset());122 });123 test('testUIWithHorizontalScrollBar', function () {124 options = {125 width: 50,126 height: 100,127 text: 'The quick brown fox jumps over a lazy dog\r\nThe quick brown fox jumps over a lazy dog',128 fixedHeight: true129 };130 codeEditorInitializer.init(options);131 equal(codeEditor.$scrollLayout[0].offsetWidth, 50);132 equal(codeEditor.$scrollLayout[0].offsetHeight, 100);133 var cursorOffset = getElementOffset(codeEditor.$cursor);134 equal(codeEditor.$scrollLayout.css('overflow-x'), 'scroll');135 deepEqual(cursorOffset, getNullOffset());136 });137 asyncTest('testUIWithFloatingWidthAndExpandDirectionRight', function () {138 options = {139 width: 200,140 height: 230,141 floatingWidth: true,142 text: ' The quick brown fox jumps over a lazy dog The quick brown fox jumps over a lazy dog',143 fixedHeight: true,144 expandDirection: 'right'145 };146 codeEditorInitializer.init(options);147 var cursorOffset = getElementOffset(codeEditor.$cursor),148 codeEditorWidth = codeEditor.$scrollLayout.width(),149 codeEditorOffset = getElementOffset(codeEditor.$scrollLayout);150 window.setTimeout(function () {151 codeEditor.$textarea[0].click();152 EventSandbox.focus(codeEditor.$textarea[0], function () {153 equal(document.activeElement, codeEditor.$textarea[0]);154 ok(codeEditor.$scrollLayout.width() > codeEditorWidth);155 deepEqual(getElementOffset(codeEditor.$scrollLayout), codeEditorOffset);156 start();157 });158 }, 0);159 });160 asyncTest('testUIWithFloatingWidthAndExpandDirectionLeft', function () {161 options = {162 width: 200,163 height: 230,164 floatingWidth: true,165 text: ' The quick brown fox jumps over a lazy dog The quick brown fox jumps over a lazy dog',166 fixedHeight: true,167 expandDirection: 'left'168 };169 codeEditorInitializer.init(options);170 var cursorOffset = getElementOffset(codeEditor.$cursor),171 codeEditorWidth = codeEditor.$scrollLayout.width(),172 codeEditorOffset = getElementOffset(codeEditor.$scrollLayout);173 window.setTimeout(function () {174 EventSandbox.focus(codeEditor.$textarea[0], function () {175 equal(document.activeElement, codeEditor.$textarea[0]);176 ok(codeEditor.$scrollLayout.width() >= codeEditorWidth);177 var newCodeEditorOffset = getElementOffset(codeEditor.$scrollLayout);178 ok(newCodeEditorOffset.left < 0);179 ok(newCodeEditorOffset.left < codeEditorOffset.left);180 equal(codeEditorOffset.top, codeEditorOffset.top);181 start();182 });183 }, 0);184 });185 /*TEST LETTER PRESS*/186 test('pressLetter', function () {187 codeEditorInitializer.init();188 var cursorOffset = getElementOffset(codeEditor.$cursor);189 currentKeyEventParser._symbolPressed('a');190 equal(codeEditor._getEditorText(), 'a');191 ok(getElementOffset(codeEditor.$cursor).left > cursorOffset.left);192 equal(getElementOffset(codeEditor.$cursor).top, cursorOffset.top);193 });194 test('pressLetterWithSelection', function () {195 codeEditorInitializer.init({196 text: 'abc'197 });198 currentKeyEventParser.shortcutHandlers['shift+right'].start();199 currentKeyEventParser.shortcutHandlers['shift+right'].start();200 var cursorOffset = getElementOffset(codeEditor.$cursor);201 currentKeyEventParser._symbolPressed('1');202 equal(codeEditor._getEditorText(), '1c');203 ok(getElementOffset(codeEditor.$cursor).left < cursorOffset.left);204 equal(getElementOffset(codeEditor.$cursor).top, cursorOffset.top)205 });206 test('pressBracket"{"', function () {207 codeEditorInitializer.init();208 currentKeyEventParser._symbolPressed('{');209 equal(codeEditor._getEditorText(), '{}');210 });211 test('notPressBracket"{"InsideText', function () {212 codeEditorInitializer.init({213 text: 'abc'214 });215 currentKeyEventParser._symbolPressed('(');216 equal(codeEditor._getEditorText(), '(abc');217 });218 test('pressBracket"}"Inside"{}"', function () {219 codeEditorInitializer.init({220 text: '{}'221 });222 currentKeyEventParser.shortcutHandlers['right'].start();223 currentKeyEventParser._symbolPressed('}');224 equal(codeEditor._getEditorText(), '{}');225 });226 test('pressQuote', function () {227 codeEditorInitializer.init();228 currentKeyEventParser._symbolPressed('"');229 equal(codeEditor._getEditorText(), '""');230 });231 test('pressQuoteInsidePairQuotes', function () {232 codeEditorInitializer.init({233 text: '""'234 });235 currentKeyEventParser.shortcutHandlers['right'].start();236 currentKeyEventParser._symbolPressed('"');237 equal(codeEditor._getEditorText(), '""');238 });239 /*TEST SHORTCUTS*/240 test('pressShortcut"Right"', function () {241 codeEditorInitializer.init({242 text: 'a'243 });244 var cursorOffset = getElementOffset(codeEditor.$cursor);245 currentKeyEventParser.shortcutHandlers['right'].start();246 ok(getElementOffset(codeEditor.$cursor).left > cursorOffset.left);247 equal(getElementOffset(codeEditor.$cursor).top, cursorOffset.top);248 });249 test('pressShortcut"Right"WithSelection', function () {250 codeEditorInitializer.init({251 text: 'abcdef\r\n123456\r\nqw'252 });253 codeEditor._setCursor(1, 4);254 var cursorOffset = getElementOffset(codeEditor.$cursor);255 currentKeyEventParser.shortcutHandlers['shift+up'].start();256 currentKeyEventParser.shortcutHandlers['right'].start();257 deepEqual(getElementOffset(codeEditor.$cursor), cursorOffset);258 ok(!codeEditor.$selectionStart.width());259 ok(!codeEditor.$selectionEnd.width());260 });261 test('pressShortcut"Left"', function () {262 codeEditorInitializer.init({263 text: 'a'264 });265 var cursorOffset = getElementOffset(codeEditor.$cursor);266 currentKeyEventParser.shortcutHandlers['right'].start();267 ok(getElementOffset(codeEditor.$cursor).left > cursorOffset.left);268 equal(getElementOffset(codeEditor.$cursor).top, cursorOffset.top);269 currentKeyEventParser.shortcutHandlers['left'].start();270 deepEqual(getElementOffset(codeEditor.$cursor), getNullOffset());271 });272 test('pressShortcut"Left"WithSelection', function () {273 codeEditorInitializer.init({274 text: 'abcdef\r\n123456\r\nqw'275 });276 codeEditor._setCursor(0, 4);277 var cursorOffset = getElementOffset(codeEditor.$cursor);278 currentKeyEventParser.shortcutHandlers['shift+down'].start();279 currentKeyEventParser.shortcutHandlers['left'].start();280 deepEqual(getElementOffset(codeEditor.$cursor), cursorOffset);281 ok(!codeEditor.$selectionStart.width());282 ok(!codeEditor.$selectionEnd.width());283 });284 test('pressShortcut"Down"', function () {285 codeEditorInitializer.init({286 text: 'a\r\nb'287 });288 var cursorOffset = getElementOffset(codeEditor.$cursor);289 currentKeyEventParser.shortcutHandlers['down'].start();290 equal(getElementOffset(codeEditor.$cursor).left, cursorOffset.left);291 ok(getElementOffset(codeEditor.$cursor).top > cursorOffset.top);292 });293 test('pressShortcut"Up"', function () {294 codeEditorInitializer.init({295 text: 'a\r\nb'296 });297 var cursorOffset = getElementOffset(codeEditor.$cursor);298 currentKeyEventParser.shortcutHandlers['down'].start();299 equal(getElementOffset(codeEditor.$cursor).left, cursorOffset.left);300 ok(getElementOffset(codeEditor.$cursor).top > cursorOffset.top);301 currentKeyEventParser.shortcutHandlers['up'].start();302 deepEqual(getElementOffset(codeEditor.$cursor), getNullOffset());303 });304 test('pressShortcut"Enter"', function () {305 codeEditorInitializer.init({306 text: 'a'307 });308 var cursorOffset = getElementOffset(codeEditor.$cursor);309 currentKeyEventParser.shortcutHandlers['enter'].start();310 equal(getElementOffset(codeEditor.$cursor).left, cursorOffset.left);311 ok(getElementOffset(codeEditor.$cursor).top > cursorOffset.top);312 equal(codeEditor.$lines.length, 2);313 equal(codeEditor._getLineText(0), '');314 });315 test('pressShortcut"Enter"InsideBrackets', function () {316 codeEditorInitializer.init({317 text: '{}'318 });319 currentKeyEventParser.shortcutHandlers['right'].start();320 var cursorOffset = getElementOffset(codeEditor.$cursor);321 currentKeyEventParser.shortcutHandlers['enter'].start();322 ok(getElementOffset(codeEditor.$cursor).top > cursorOffset.top);323 ok(getElementOffset(codeEditor.$cursor).top < getElementOffset(codeEditor.$lines[2]).top);324 equal(codeEditor.$lines.length, 3);325 equal(codeEditor._getLineText(0), '{');326 equal(codeEditor._getLineText(1), ' ');327 equal(codeEditor._getLineText(2), '}');328 });329 test('pressShortcut"Enter"AfterOpeningBracket', function () {330 codeEditorInitializer.init({331 text: '{a'332 });333 currentKeyEventParser.shortcutHandlers['right'].start();334 var cursorOffset = getElementOffset(codeEditor.$cursor);335 currentKeyEventParser.shortcutHandlers['enter'].start();336 ok(getElementOffset(codeEditor.$cursor).top > cursorOffset.top);337 equal(codeEditor.$lines.length, 2);338 equal(codeEditor._getLineText(0), '{');339 equal(codeEditor._getLineText(1), 'a');340 });341 test('pressShortcut"Enter"WithSelection', function () {342 codeEditorInitializer.init({343 text: 'abcdef\r\n123456'344 });345 codeEditor._setCursor(0, 3);346 currentKeyEventParser.shortcutHandlers['shift+down'].start();347 var cursorOffset = getElementOffset(codeEditor.$cursor);348 currentKeyEventParser.shortcutHandlers['enter'].start();349 equal(codeEditor._getEditorText(), 'abc\r\n456');350 equal(codeEditor.$lines.length, 2);351 ok(getElementOffset(codeEditor.$cursor).left < cursorOffset.left);352 equal(getElementOffset(codeEditor.$cursor).top, cursorOffset.top);353 });354 test('pressShortcut"Backspace"', function () {355 codeEditorInitializer.init({356 text: 'a'357 });358 currentKeyEventParser.shortcutHandlers['right'].start();359 currentKeyEventParser.shortcutHandlers['backspace'].start();360 var cursorOffset = getElementOffset(codeEditor.$cursor);361 equal(codeEditor._getEditorText(), '');362 deepEqual(getElementOffset(codeEditor.$cursor), getNullOffset());363 });364 test('pressShortcut"Backspace"BeforeLineFirstSymbol', function () {365 codeEditorInitializer.init({366 text: 'a\r\nb'367 });368 currentKeyEventParser.shortcutHandlers['down'].start();369 var cursorOffset = getElementOffset(codeEditor.$cursor);370 currentKeyEventParser.shortcutHandlers['backspace'].start();371 equal(codeEditor._getEditorText(), 'ab');372 equal(codeEditor.$lines.length, 1);373 ok(getElementOffset(codeEditor.$cursor).left > cursorOffset.left);374 ok(getElementOffset(codeEditor.$cursor).top < cursorOffset.top);375 });376 test('pressShortcut"Backspace"InsideBrackets', function () {377 codeEditorInitializer.init({378 text: '{}'379 });380 currentKeyEventParser.shortcutHandlers['right'].start();381 var cursorOffset = getElementOffset(codeEditor.$cursor);382 currentKeyEventParser.shortcutHandlers['backspace'].start();383 deepEqual(getElementOffset(codeEditor.$cursor), getNullOffset());384 equal(codeEditor._getEditorText(), '');385 });386 test('pressShortcut"Backspace"InsideQuotes', function () {387 codeEditorInitializer.init({388 text: '""'389 });390 currentKeyEventParser.shortcutHandlers['right'].start();391 var cursorOffset = getElementOffset(codeEditor.$cursor);392 currentKeyEventParser.shortcutHandlers['backspace'].start();393 deepEqual(getElementOffset(codeEditor.$cursor), getNullOffset());394 equal(codeEditor._getEditorText(), '');395 });396 test('pressShortcut"Backspace"WithSelection', function () {397 codeEditorInitializer.init({398 text: 'abcdef\r\n123456'399 });400 codeEditor._setCursor(0, 3);401 currentKeyEventParser.shortcutHandlers['shift+down'].start();402 var cursorOffset = getElementOffset(codeEditor.$cursor);403 currentKeyEventParser.shortcutHandlers['backspace'].start();404 equal(codeEditor._getEditorText(), 'abc456');405 equal(codeEditor.$lines.length, 1);406 equal(getElementOffset(codeEditor.$cursor).left, cursorOffset.left);407 ok(getElementOffset(codeEditor.$cursor).top < cursorOffset.top);408 });409 test('pressShortcut"Delete"', function () {410 codeEditorInitializer.init({411 text: 'a'412 });413 currentKeyEventParser.shortcutHandlers['delete'].start();414 equal(codeEditor._getEditorText(), '');415 deepEqual(getElementOffset(codeEditor.$cursor), getNullOffset());416 });417 test('pressShortcut"Delete"AfterLineLastSymbol', function () {418 codeEditorInitializer.init({419 text: 'a\r\nb'420 });421 currentKeyEventParser.shortcutHandlers['right'].start();422 var cursorOffset = getElementOffset(codeEditor.$cursor);423 currentKeyEventParser.shortcutHandlers['delete'].start();424 equal(codeEditor._getEditorText(), 'ab');425 equal(codeEditor.$lines.length, 1);426 equal(getElementOffset(codeEditor.$cursor).left, cursorOffset.left);427 equal(getElementOffset(codeEditor.$cursor).top, cursorOffset.top);428 });429 test('pressShortcut"Delete"WithSelection', function () {430 codeEditorInitializer.init({431 text: 'abcdef\r\n123456'432 });433 codeEditor._setCursor(0, 3);434 currentKeyEventParser.shortcutHandlers['shift+down'].start();435 var cursorOffset = getElementOffset(codeEditor.$cursor);436 currentKeyEventParser.shortcutHandlers['delete'].start();437 equal(codeEditor._getEditorText(), 'abc456');438 equal(codeEditor.$lines.length, 1);439 equal(getElementOffset(codeEditor.$cursor).left, cursorOffset.left);440 ok(getElementOffset(codeEditor.$cursor).top < cursorOffset.top);441 });442 test('pressShortcut"Home"', function () {443 codeEditorInitializer.init({444 text: 'abcdef'445 });446 var cursorOffset = getElementOffset(codeEditor.$cursor);447 codeEditor._setCursor(0, 5);448 ok(getElementOffset(codeEditor.$cursor).left > cursorOffset.left);449 equal(getElementOffset(codeEditor.$cursor).top, cursorOffset.top);450 currentKeyEventParser.shortcutHandlers['home'].start();451 deepEqual(getElementOffset(codeEditor.$cursor), getNullOffset());452 });453 test('pressShortcut"Home"OnLineWithIndents', function () {454 codeEditorInitializer.init({455 text: ' abcdef'456 });457 codeEditor._setCursor(0, 5);458 var cursorOffset = getElementOffset(codeEditor.$cursor);459 currentKeyEventParser.shortcutHandlers['home'].start();460 var newCursorOffset = getElementOffset(codeEditor.$cursor);461 ok(newCursorOffset.left < cursorOffset.left);462 equal(newCursorOffset.top, cursorOffset.top);463 notDeepEqual(newCursorOffset, getNullOffset());464 currentKeyEventParser.shortcutHandlers['home'].start();465 deepEqual(getElementOffset(codeEditor.$cursor), getNullOffset());466 currentKeyEventParser.shortcutHandlers['home'].start();467 deepEqual(getElementOffset(codeEditor.$cursor), newCursorOffset);468 });469 test('pressShortcut"End"', function () {470 codeEditorInitializer.init({471 text: 'abcdef\r\nb'472 });473 var cursorOffset = getElementOffset(codeEditor.$cursor);474 currentKeyEventParser.shortcutHandlers['end'].start();475 ok(getElementOffset(codeEditor.$cursor).left > cursorOffset.left);476 equal(getElementOffset(codeEditor.$cursor).top, cursorOffset.top);477 //Check via press 'Del'478 currentKeyEventParser.shortcutHandlers['delete'].start();479 equal(codeEditor._getEditorText(), 'abcdefb');480 equal(codeEditor.$lines.length, 1);481 });482 test('pressShortcut"Tab"', function () {483 codeEditorInitializer.init({484 text: 'a'485 });486 var cursorOffset = getElementOffset(codeEditor.$cursor);487 currentKeyEventParser.shortcutHandlers['tab'].start();488 ok(getElementOffset(codeEditor.$cursor).left > cursorOffset.left);489 equal(getElementOffset(codeEditor.$cursor).top, cursorOffset.top);490 equal(codeEditor._getEditorText(), ' a');491 });492 test('pressShortcut"Tab"WithSelection', function () {493 codeEditorInitializer.init({494 text: 'abcdef\r\n\r\n123456'495 });496 currentKeyEventParser.shortcutHandlers['shift+down'].start();497 currentKeyEventParser.shortcutHandlers['shift+down'].start();498 currentKeyEventParser.shortcutHandlers['shift+right'].start();499 currentKeyEventParser.shortcutHandlers['shift+right'].start();500 var cursorOffset = getElementOffset(codeEditor.$cursor),501 selectionStartWidth = codeEditor.$selectionStart.width(),502 selectionCenterHeight = codeEditor.$selectionCenter.height(),503 selectionEndWidth = codeEditor.$selectionEnd.width(),504 selectionStartOffset = getElementOffset(codeEditor.$selectionStart);505 currentKeyEventParser.shortcutHandlers['tab'].start();506 ok(codeEditor.$selectionStart.width() < selectionStartWidth);507 equal(selectionCenterHeight, codeEditor.$selectionCenter.height());508 ok(codeEditor.$selectionEnd.width() > selectionEndWidth);509 equal(codeEditor._getLineText(0), ' abcdef');510 equal(codeEditor._getLineText(1), '');511 ok(!codeEditor._getLineLength(1));512 equal(codeEditor._getLineText(2), ' 123456');513 ok(getElementOffset(codeEditor.$selectionStart).left > selectionStartOffset.left);514 equal(getElementOffset(codeEditor.$selectionStart).top, selectionStartOffset.top);515 ok(getElementOffset(codeEditor.$cursor).left > cursorOffset.left);516 equal(getElementOffset(codeEditor.$cursor).top, cursorOffset.top);517 });518 test('pressShortcut"ShiftTab"', function () {519 codeEditorInitializer.init({520 text: ' a'521 });522 codeEditor._setCursor(0, 6);523 var cursorOffset = getElementOffset(codeEditor.$cursor);524 currentKeyEventParser.shortcutHandlers['shift+tab'].start();525 var newCursorOffset = getElementOffset(codeEditor.$cursor);526 ok(newCursorOffset.left < cursorOffset.left);527 ok(newCursorOffset.left !== getNullOffset().left);528 equal(newCursorOffset.top, cursorOffset.top);529 equal(codeEditor._getEditorText(), ' a');530 cursorOffset = newCursorOffset;531 currentKeyEventParser.shortcutHandlers['shift+tab'].start();532 newCursorOffset = getElementOffset(codeEditor.$cursor);533 ok(newCursorOffset.left < cursorOffset.left);534 deepEqual(newCursorOffset, getNullOffset());535 equal(codeEditor._getEditorText(), 'a');536 });537 test('pressShortcut"Shift+Tab"WithSelection', function () {538 codeEditorInitializer.init({539 text: ' abcdef\r\n a\r\n qwerty'540 });541 codeEditor._setCursor(0, 6);542 currentKeyEventParser.shortcutHandlers['shift+down'].start();543 currentKeyEventParser.shortcutHandlers['shift+down'].start();544 var cursorOffset = getElementOffset(codeEditor.$cursor),545 selectionStartWidth = codeEditor.$selectionStart.width(),546 selectionEndWidth = codeEditor.$selectionEnd.width(),547 selectionStartOffset = getElementOffset(codeEditor.$selectionStart);548 currentKeyEventParser.shortcutHandlers['shift+tab'].start();549 ok(codeEditor.$selectionStart.width() > selectionStartWidth);550 ok(codeEditor.$selectionEnd.width() < selectionEndWidth);551 equal(codeEditor._getEditorText(), 'abcdef\r\n a\r\nqwerty');552 ok(getElementOffset(codeEditor.$selectionStart).left < selectionStartOffset.left);553 equal(getElementOffset(codeEditor.$selectionStart).top, selectionStartOffset.top);554 ok(getElementOffset(codeEditor.$cursor).left < cursorOffset.left);555 equal(getElementOffset(codeEditor.$cursor).top, cursorOffset.top);556 currentKeyEventParser.shortcutHandlers['shift+tab'].start();557 equal(codeEditor._getEditorText(), 'abcdef\r\na\r\nqwerty');558 });559 test('pressShortcut"Shift+left"', function () {560 codeEditorInitializer.init({561 text: 'abc'562 });563 codeEditor._setCursor(0, 2);564 currentKeyEventParser.shortcutHandlers['shift+left'].start();565 var selectionWidth = codeEditor.$selectionStart.width();566 ok(selectionWidth);567 currentKeyEventParser.shortcutHandlers['shift+left'].start();568 ok(selectionWidth < codeEditor.$selectionStart.width());569 deepEqual(getElementOffset(codeEditor.$cursor), getNullOffset());570 equal(codeEditor._getSelectionTextAsArray().join(''), 'ab');571 });572 test('pressShortcut"Shift+right"', function () {573 codeEditorInitializer.init({574 text: 'abc'575 });576 var cursorStartOffset = getElementOffset(codeEditor.$cursor);577 currentKeyEventParser.shortcutHandlers['shift+right'].start();578 var selectionWidth = codeEditor.$selectionStart.width();579 ok(selectionWidth);580 var cursorOffset = getElementOffset(codeEditor.$cursor);581 currentKeyEventParser.shortcutHandlers['shift+right'].start();582 var newCursorStartOffset = getElementOffset(codeEditor.$cursor);583 ok(selectionWidth < codeEditor.$selectionStart.width());584 ok(newCursorStartOffset.left > cursorOffset.left &&585 newCursorStartOffset.left > cursorStartOffset.left);586 equal(newCursorStartOffset.top, getNullOffset().top);587 equal(codeEditor._getSelectionTextAsArray().join(''), 'ab');588 });589 test('pressOnceShortcut"Shift+down"', function () {590 codeEditorInitializer.init({591 text: 'abcdef\r\n123456'592 });593 codeEditor._setCursor(0, 2);594 var cursorOffset = getElementOffset(codeEditor.$cursor);595 currentKeyEventParser.shortcutHandlers['shift+down'].start();596 ok(codeEditor.$selectionStart.width());597 var selectionEndWidth = codeEditor.$selectionEnd.width(),598 newCursorOffset = getElementOffset(codeEditor.$cursor),599 selectionStartOffset = getElementOffset(codeEditor.$selectionStart),600 selectionEndOffset = getElementOffset(codeEditor.$selectionEnd);601 ok(selectionEndWidth);602 equal(selectionStartOffset.left, cursorOffset.left);603 equal(selectionStartOffset.top, cursorOffset.top);604 ok(newCursorOffset.left === cursorOffset.left &&605 newCursorOffset.top > cursorOffset.top);606 equal(selectionEndOffset.left + selectionEndWidth, newCursorOffset.left);607 equal(selectionEndOffset.top, newCursorOffset.top);608 });609 test('pressTwiceShortcut"Shift+down"', function () {610 codeEditorInitializer.init({611 text: 'abcdef\r\n123456\r\nq'612 });613 codeEditor._setCursor(0, 2);614 var cursorStartOffset = getElementOffset(codeEditor.$cursor);615 currentKeyEventParser.shortcutHandlers['shift+down'].start();616 var selectionStartWidth = codeEditor.$selectionStart.width();617 var selectionEndWidth = codeEditor.$selectionEnd.width();618 var cursorOffset = getElementOffset(codeEditor.$cursor);619 ok(getElementOffset(codeEditor.$cursor).left === cursorStartOffset.left &&620 getElementOffset(codeEditor.$cursor).top > cursorStartOffset.top);621 currentKeyEventParser.shortcutHandlers['shift+down'].start();622 var newSelectionEndWidth = codeEditor.$selectionEnd.width(),623 newCursorOffset = getElementOffset(codeEditor.$cursor),624 selectionEndOffset = getElementOffset(codeEditor.$selectionEnd),625 selectionCenterOffset = getElementOffset(codeEditor.$selectionCenter);626 //Check SelectionStart627 equal(codeEditor.$selectionStart.width(), selectionStartWidth);628 //Check SelectionEnd629 ok(newSelectionEndWidth < selectionEndWidth);630 equal(selectionEndOffset.left + newSelectionEndWidth, newCursorOffset.left);631 equal(selectionEndOffset.top, newCursorOffset.top);632 //Check SelectionCenter633 equal(selectionCenterOffset.left, getNullOffset().left);634 equal(selectionCenterOffset.top, getElementOffset(codeEditor.$selectionStart).top + codeEditor.$selectionStart.height());635 ok(codeEditor.$selectionCenter.width());636 equal(codeEditor.$selectionCenter.height(), selectionEndOffset.top - codeEditor.$selectionStart.height());637 //Check Cursor638 ok(newCursorOffset.left < cursorOffset.left &&639 newCursorOffset.top > cursorOffset.top);640 });641 test('pressShortcut"Shift+up"', function () {642 codeEditorInitializer.init({643 text: 'abcdef\r\n123456'644 });645 codeEditor._setCursor(1, 2);646 var cursorOffset = getElementOffset(codeEditor.$cursor);647 currentKeyEventParser.shortcutHandlers['shift+up'].start();648 var selectionEndWidth = codeEditor.$selectionEnd.width(),649 selectionStartOffset = getElementOffset(codeEditor.$selectionStart),650 selectionEndOffset = getElementOffset(codeEditor.$selectionEnd),651 newCursorOffset = getElementOffset(codeEditor.$cursor);652 ok(codeEditor.$selectionStart.width());653 equal(selectionStartOffset.left, cursorOffset.left);654 deepEqual(selectionStartOffset, newCursorOffset);655 ok(selectionEndWidth);656 equal(selectionEndOffset.left + selectionEndWidth, newCursorOffset.left);657 equal(selectionEndOffset.top, newCursorOffset.top + codeEditor.$selectionStart.height());658 ok(newCursorOffset.left === cursorOffset.left &&659 newCursorOffset.top < cursorOffset.top);660 });661 test('changeSelectionDirection', function () {662 codeEditorInitializer.init({663 text: 'abcdef\r\n123456'664 });665 codeEditor._setCursor(0, 2);666 var cursorOffset = getElementOffset(codeEditor.$cursor);667 currentKeyEventParser.shortcutHandlers['shift+down'].start();668 currentKeyEventParser.shortcutHandlers['shift+right'].start();669 currentKeyEventParser.shortcutHandlers['shift+left'].start();670 currentKeyEventParser.shortcutHandlers['shift+left'].start();671 currentKeyEventParser.shortcutHandlers['shift+left'].start();672 currentKeyEventParser.shortcutHandlers['shift+up'].start();673 var newCursorOffset = getElementOffset(codeEditor.$cursor),674 selectionStartWidth = codeEditor.$selectionStart.width(),675 selectionStartOffset = getElementOffset(codeEditor.$selectionStart);676 ok(selectionStartWidth);677 ok(!codeEditor.$selectionEnd.width());678 ok(newCursorOffset.left < cursorOffset.left);679 equal(newCursorOffset.top, cursorOffset.top);680 deepEqual(newCursorOffset, selectionStartOffset);681 equal(selectionStartWidth, cursorOffset.left - newCursorOffset.left);682 });683 test('pressShortcut"Shift+home"', function () {684 codeEditorInitializer.init({685 text: 'abcdef'686 });687 currentKeyEventParser.shortcutHandlers['end'].start();688 var cursorOffset = getElementOffset(codeEditor.$cursor);689 currentKeyEventParser.shortcutHandlers['shift+home'].start();690 var selectionStartWidth = codeEditor.$selectionStart.width(),691 selectionStartOffset = getElementOffset(codeEditor.$selectionStart),692 newCursorOffset = getElementOffset(codeEditor.$cursor);693 ok(selectionStartWidth);694 equal(selectionStartWidth, cursorOffset.left - newCursorOffset.left);695 equal(selectionStartOffset.top, cursorOffset.top);696 deepEqual(selectionStartOffset, newCursorOffset);697 ok(newCursorOffset.left < cursorOffset.left &&698 newCursorOffset.top === cursorOffset.top);699 });700 test('pressShortcut"Shift+home"OnLineWithIndents', function () {701 codeEditorInitializer.init({702 text: ' abcdef\r\nabcdef'703 });704 codeEditor._setCursor(1, 5);705 currentKeyEventParser.shortcutHandlers['shift+up'].start();706 var cursorOffset = getElementOffset(codeEditor.$cursor),707 selectionStartOffset = getElementOffset(codeEditor.$selectionStart),708 selectionStartWidth = codeEditor.$selectionStart.width();709 currentKeyEventParser.shortcutHandlers['shift+home'].start();710 var newCursorOffset = getElementOffset(codeEditor.$cursor),711 newSelectionStartOffset = getElementOffset(codeEditor.$selectionStart),712 newSelectionStartWidth = codeEditor.$selectionStart.width();713 ok(newCursorOffset.left < cursorOffset.left);714 equal(newCursorOffset.top, cursorOffset.top);715 notDeepEqual(newCursorOffset, getNullOffset());716 ok(selectionStartOffset.left > newSelectionStartOffset.left);717 ok(newSelectionStartWidth > selectionStartWidth);718 currentKeyEventParser.shortcutHandlers['shift+home'].start();719 deepEqual(getElementOffset(codeEditor.$cursor), getNullOffset());720 deepEqual(getElementOffset(codeEditor.$selectionStart), getNullOffset());721 ok(codeEditor.$selectionStart.width() > newSelectionStartWidth);722 currentKeyEventParser.shortcutHandlers['shift+home'].start();723 deepEqual(getElementOffset(codeEditor.$cursor), newCursorOffset);724 deepEqual(getElementOffset(codeEditor.$selectionStart), newSelectionStartOffset);725 });726 test('pressShortcut"Shift+end"', function () {727 codeEditorInitializer.init({728 text: 'abcdef'729 });730 var cursorOffset = getElementOffset(codeEditor.$cursor);731 currentKeyEventParser.shortcutHandlers['shift+end'].start();732 var selectionStartWidth = codeEditor.$selectionStart.width(),733 selectionStartOffset = getElementOffset(codeEditor.$selectionStart),734 newCursorOffset = getElementOffset(codeEditor.$cursor);735 ok(selectionStartWidth);736 equal(selectionStartWidth, newCursorOffset.left - cursorOffset.left);737 deepEqual(selectionStartOffset, cursorOffset);738 equal(selectionStartOffset.top, newCursorOffset.top);739 ok(newCursorOffset.left > cursorOffset.left &&740 newCursorOffset.top === cursorOffset.top);741 });742 test('pressShortcut"Ctrl+left"', function () {743 codeEditorInitializer.init({744 text: 'a*cdef'745 });746 codeEditor._setCursor(0, codeEditor._getLineLength(0));747 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 6);748 currentKeyEventParser.shortcutHandlers['ctrl+left'].start();749 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 2);750 currentKeyEventParser.shortcutHandlers['ctrl+left'].start();751 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 1);752 currentKeyEventParser.shortcutHandlers['ctrl+left'].start();753 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 0);754 });755 test('pressShortcut"Ctrl+left"OnLineWithSpaceAndSymbol', function () {756 codeEditorInitializer.init({757 text: 'a *cdef'758 });759 codeEditor._setCursor(0, codeEditor._getLineLength(0));760 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 7);761 currentKeyEventParser.shortcutHandlers['ctrl+left'].start();762 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 3);763 currentKeyEventParser.shortcutHandlers['ctrl+left'].start();764 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 2);765 currentKeyEventParser.shortcutHandlers['ctrl+left'].start();766 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 0);767 });768 test('pressShortcut"Ctrl+left"OnLineWithSymbolAndSpace', function () {769 codeEditorInitializer.init({770 text: 'a* cdef'771 });772 codeEditor._setCursor(0, codeEditor._getLineLength(0));773 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 7);774 currentKeyEventParser.shortcutHandlers['ctrl+left'].start();775 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 3);776 currentKeyEventParser.shortcutHandlers['ctrl+left'].start();777 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 1);778 currentKeyEventParser.shortcutHandlers['ctrl+left'].start();779 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 0);780 });781 test('pressShortcut"Ctrl+right"', function () {782 codeEditorInitializer.init({783 text: 'a*cdef'784 });785 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 0);786 currentKeyEventParser.shortcutHandlers['ctrl+right'].start();787 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 1);788 currentKeyEventParser.shortcutHandlers['ctrl+right'].start();789 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 2);790 currentKeyEventParser.shortcutHandlers['ctrl+right'].start();791 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 6);792 });793 test('pressShortcut"Ctrl+right"OnLineWithSpaceAndSymbol', function () {794 codeEditorInitializer.init({795 text: 'a *cdef'796 });797 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 0);798 currentKeyEventParser.shortcutHandlers['ctrl+right'].start();799 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 2);800 currentKeyEventParser.shortcutHandlers['ctrl+right'].start();801 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 3);802 currentKeyEventParser.shortcutHandlers['ctrl+right'].start();803 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 7);804 });805 test('pressShortcut"Ctrl+right"OnLineWithSymbolAndSpace', function () {806 codeEditorInitializer.init({807 text: 'a* cdef'808 });809 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 0);810 currentKeyEventParser.shortcutHandlers['ctrl+right'].start();811 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 1);812 currentKeyEventParser.shortcutHandlers['ctrl+right'].start();813 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 3);814 currentKeyEventParser.shortcutHandlers['ctrl+right'].start();815 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 7);816 });817 test('pressShortcut"Ctrl + home"', function () {818 codeEditorInitializer.init({819 text: 'a\r\nba\r\nba\r\nb'820 });821 codeEditor._setCursor(2, 2);822 currentKeyEventParser.shortcutHandlers['ctrl+home'].start();823 deepEqual(getElementOffset(codeEditor.$cursor), getNullOffset());824 });825 test('pressShortcut"Ctrl + end"', function () {826 codeEditorInitializer.init({827 text: 'a\r\nba\r\nba\r\nabcdef'828 });829 codeEditor._setCursor(2, 2);830 currentKeyEventParser.shortcutHandlers['ctrl+end'].start();831 var cursorOffset = getElementOffset(codeEditor.$cursor),832 lastLineIndex = codeEditor.$lines.length - 1,833 lastLineOffset = getElementOffset(codeEditor.$lines[lastLineIndex]);834 equal(cursorOffset.top, lastLineOffset.top - getElementOffset(codeEditor.$editLayout).top);835 equal(cursorOffset.left, lastLineOffset.left + codeEditor._getLineLength(lastLineIndex) * codeEditor._getLetterWidth(lastLineIndex) - getElementOffset(codeEditor.$editLayout).left);836 });837 test('pressShortcut"Ctrl + shift + left"', function () {838 codeEditorInitializer.init({839 text: 'a*cdef'840 });841 currentKeyEventParser.shortcutHandlers['end'].start();842 var cursorStartOffset = getElementOffset(codeEditor.$cursor);843 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 6);844 currentKeyEventParser.shortcutHandlers['ctrl+shift+left'].start();845 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 2);846 equal(getElementOffset(codeEditor.$cursor).left, getElementOffset(codeEditor.$selectionStart).left);847 equal(codeEditor.$selectionStart.width(), cursorStartOffset.left - getElementOffset(codeEditor.$cursor).left);848 currentKeyEventParser.shortcutHandlers['shift+ctrl+left'].start();849 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 1);850 equal(getElementOffset(codeEditor.$cursor).left, getElementOffset(codeEditor.$selectionStart).left);851 equal(codeEditor.$selectionStart.width(), cursorStartOffset.left - getElementOffset(codeEditor.$cursor).left);852 currentKeyEventParser.shortcutHandlers['shift+ctrl+left'].start();853 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 0);854 equal(getElementOffset(codeEditor.$cursor).left, getElementOffset(codeEditor.$selectionStart).left);855 equal(codeEditor.$selectionStart.width(), cursorStartOffset.left - getElementOffset(codeEditor.$cursor).left);856 });857 test('pressShortcut"Ctrl + shift + left"OnLineWithSpaceAndSymbol', function () {858 codeEditorInitializer.init({859 text: 'a *cdef'860 });861 currentKeyEventParser.shortcutHandlers['end'].start();862 var cursorStartOffset = getElementOffset(codeEditor.$cursor);863 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 7);864 currentKeyEventParser.shortcutHandlers['ctrl+shift+left'].start();865 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 3);866 equal(getElementOffset(codeEditor.$cursor).left, getElementOffset(codeEditor.$selectionStart).left);867 equal(codeEditor.$selectionStart.width(), cursorStartOffset.left - getElementOffset(codeEditor.$cursor).left);868 currentKeyEventParser.shortcutHandlers['ctrl+shift+left'].start();869 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 2);870 equal(getElementOffset(codeEditor.$cursor).left, getElementOffset(codeEditor.$selectionStart).left);871 equal(codeEditor.$selectionStart.width(), cursorStartOffset.left - getElementOffset(codeEditor.$cursor).left);872 currentKeyEventParser.shortcutHandlers['shift+ctrl+left'].start();873 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 0);874 equal(getElementOffset(codeEditor.$cursor).left, getElementOffset(codeEditor.$selectionStart).left);875 equal(codeEditor.$selectionStart.width(), cursorStartOffset.left - getElementOffset(codeEditor.$cursor).left);876 });877 test('pressShortcut"Ctrl + shift + left"OnLineWithSymbolsAndSpace', function () {878 codeEditorInitializer.init({879 text: 'a*** cdef'880 });881 currentKeyEventParser.shortcutHandlers['end'].start();882 var cursorStartOffset = getElementOffset(codeEditor.$cursor);883 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 9);884 currentKeyEventParser.shortcutHandlers['ctrl+shift+left'].start();885 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 5);886 equal(getElementOffset(codeEditor.$cursor).left, getElementOffset(codeEditor.$selectionStart).left);887 equal(codeEditor.$selectionStart.width(), cursorStartOffset.left - getElementOffset(codeEditor.$cursor).left);888 currentKeyEventParser.shortcutHandlers['ctrl+shift+left'].start();889 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 1);890 equal(getElementOffset(codeEditor.$cursor).left, getElementOffset(codeEditor.$selectionStart).left);891 equal(codeEditor.$selectionStart.width(), cursorStartOffset.left - getElementOffset(codeEditor.$cursor).left);892 currentKeyEventParser.shortcutHandlers['ctrl+shift+left'].start();893 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 0);894 equal(getElementOffset(codeEditor.$cursor).left, getElementOffset(codeEditor.$selectionStart).left);895 equal(codeEditor.$selectionStart.width(), cursorStartOffset.left - getElementOffset(codeEditor.$cursor).left);896 });897 test('pressShortcut"Ctrl + shift + right"', function () {898 codeEditorInitializer.init({899 text: 'a*cdef'900 });901 var cursorStartOffset = getElementOffset(codeEditor.$cursor);902 currentKeyEventParser.shortcutHandlers['ctrl+shift+right'].start();903 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 1);904 equal(getElementOffset(codeEditor.$selectionStart).left, cursorStartOffset.left);905 equal(codeEditor.$selectionStart.width(), getElementOffset(codeEditor.$cursor).left - cursorStartOffset.left);906 currentKeyEventParser.shortcutHandlers['shift+ctrl+right'].start();907 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 2);908 equal(getElementOffset(codeEditor.$selectionStart).left, cursorStartOffset.left);909 equal(codeEditor.$selectionStart.width(), getElementOffset(codeEditor.$cursor).left - cursorStartOffset.left);910 currentKeyEventParser.shortcutHandlers['shift+ctrl+right'].start();911 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 6);912 equal(getElementOffset(codeEditor.$selectionStart).left, cursorStartOffset.left);913 equal(codeEditor.$selectionStart.width(), getElementOffset(codeEditor.$cursor).left - cursorStartOffset.left);914 });915 test('pressShortcut"Ctrl + shift + right"OnLineWithSpaceAndSymbol', function () {916 codeEditorInitializer.init({917 text: 'a *cdef'918 });919 var cursorStartOffset = getElementOffset(codeEditor.$cursor);920 currentKeyEventParser.shortcutHandlers['ctrl+shift+right'].start();921 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 2);922 equal(getElementOffset(codeEditor.$selectionStart).left, cursorStartOffset.left);923 equal(codeEditor.$selectionStart.width(), getElementOffset(codeEditor.$cursor).left - cursorStartOffset.left);924 currentKeyEventParser.shortcutHandlers['ctrl+shift+right'].start();925 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 3);926 equal(getElementOffset(codeEditor.$selectionStart).left, cursorStartOffset.left);927 equal(codeEditor.$selectionStart.width(), getElementOffset(codeEditor.$cursor).left - cursorStartOffset.left);928 currentKeyEventParser.shortcutHandlers['shift+ctrl+right'].start();929 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 7);930 equal(getElementOffset(codeEditor.$selectionStart).left, cursorStartOffset.left);931 equal(codeEditor.$selectionStart.width(), getElementOffset(codeEditor.$cursor).left - cursorStartOffset.left);932 });933 test('pressShortcut"Ctrl + shift + right"OnLineWithSymbolsAndSpace', function () {934 codeEditorInitializer.init({935 text: 'a*** cdef'936 });937 var cursorStartOffset = getElementOffset(codeEditor.$cursor);938 currentKeyEventParser.shortcutHandlers['ctrl+shift+right'].start();939 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 1);940 equal(getElementOffset(codeEditor.$selectionStart).left, cursorStartOffset.left);941 equal(codeEditor.$selectionStart.width(), getElementOffset(codeEditor.$cursor).left - cursorStartOffset.left);942 currentKeyEventParser.shortcutHandlers['ctrl+shift+right'].start();943 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 5);944 equal(getElementOffset(codeEditor.$selectionStart).left, cursorStartOffset.left);945 equal(codeEditor.$selectionStart.width(), getElementOffset(codeEditor.$cursor).left - cursorStartOffset.left);946 currentKeyEventParser.shortcutHandlers['ctrl+shift+right'].start();947 equal(Math.round(getElementOffset(codeEditor.$cursor).left / codeEditor._getLetterWidth(0)), 9);948 equal(getElementOffset(codeEditor.$selectionStart).left, cursorStartOffset.left);949 equal(codeEditor.$selectionStart.width(), getElementOffset(codeEditor.$cursor).left - cursorStartOffset.left);950 });951 test('pressShortcut"Ctrl + backspace"', function () {952 codeEditorInitializer.init({953 text: ' Test ctrl backspace'954 });955 codeEditor._setCursor(0, 20);956 var cursorOffset = getElementOffset(codeEditor.$cursor);957 currentKeyEventParser.shortcutHandlers['ctrl+backspace'].start();958 var newCursorOffset = getElementOffset(codeEditor.$cursor);959 ok(newCursorOffset.left < cursorOffset.left);960 equal(newCursorOffset.top, cursorOffset.top);961 equal(codeEditor._getEditorText(), ' Test ctrl ace');962 cursorOffset = newCursorOffset;963 currentKeyEventParser.shortcutHandlers['ctrl+backspace'].start();964 newCursorOffset = getElementOffset(codeEditor.$cursor);965 ok(newCursorOffset.left < cursorOffset.left);966 equal(newCursorOffset.top, cursorOffset.top);967 equal(codeEditor._getEditorText(), ' Test ace');968 cursorOffset = newCursorOffset;969 currentKeyEventParser.shortcutHandlers['ctrl+backspace'].start();970 newCursorOffset = getElementOffset(codeEditor.$cursor);971 ok(newCursorOffset.left < cursorOffset.left);972 equal(newCursorOffset.top, cursorOffset.top);973 equal(codeEditor._getEditorText(), ' ace');974 currentKeyEventParser.shortcutHandlers['ctrl+backspace'].start();975 deepEqual(getElementOffset(codeEditor.$cursor), getNullOffset());976 });977 test('pressShortcut"Ctrl + backspace"WithSelection', function () {978 codeEditorInitializer.init({979 text: 'a b c\r\n' +980 ' a b c\r\n' +981 'a b c'982 });983 codeEditor._setCursor(0, 3);984 currentKeyEventParser.shortcutHandlers['shift+down'].start();985 currentKeyEventParser.shortcutHandlers['shift+down'].start();986 var selectionStartWidth = codeEditor.$selectionStart.width(),987 selectionCenterHeight = codeEditor.$selectionCenter.height(),988 selectionEndWidth = codeEditor.$selectionEnd.width();989 ok(selectionStartWidth && selectionCenterHeight && selectionEndWidth);990 var cursorOffset = getElementOffset(codeEditor.$cursor);991 currentKeyEventParser.shortcutHandlers['ctrl+backspace'].start();992 ok(!codeEditor.$selectionStart.width());993 ok(!codeEditor.$selectionCenter.height());994 ok(!codeEditor.$selectionEnd.width());995 var newCursorOffset = getElementOffset(codeEditor.$cursor);996 ok(newCursorOffset.top < cursorOffset.top);997 equal(newCursorOffset.left, cursorOffset.left);998 equal(codeEditor.$lines.length, 1);999 equal(codeEditor._getEditorText(), 'a b c');1000 });1001 test('pressShortcut"Ctrl + backspace"WithInvertSelection', function () {1002 codeEditorInitializer.init({1003 text: 'a b c\r\n' +1004 ' a b c\r\n' +1005 'a b c'1006 });1007 codeEditor._setCursor(2, 3);1008 currentKeyEventParser.shortcutHandlers['shift+up'].start();1009 currentKeyEventParser.shortcutHandlers['shift+up'].start();1010 var selectionStartWidth = codeEditor.$selectionStart.width(),1011 selectionCenterHeight = codeEditor.$selectionCenter.height(),1012 selectionEndWidth = codeEditor.$selectionEnd.width();1013 ok(selectionStartWidth && selectionCenterHeight && selectionEndWidth);1014 var cursorOffset = getElementOffset(codeEditor.$cursor);1015 currentKeyEventParser.shortcutHandlers['ctrl+backspace'].start();1016 ok(!codeEditor.$selectionStart.width());1017 ok(!codeEditor.$selectionCenter.height());1018 ok(!codeEditor.$selectionEnd.width());1019 deepEqual(getElementOffset(codeEditor.$cursor), cursorOffset);1020 equal(codeEditor.$lines.length, 1);1021 equal(codeEditor._getEditorText(), 'a b c');1022 });1023 test('pressShortcut"Ctrl + backspace"OnLineFirstSymbol', function () {1024 codeEditorInitializer.init({1025 text: 'a b c\r\n' +1026 ' a b c'1027 });1028 codeEditor._setCursor(1, 0);1029 var cursorOffset = getElementOffset(codeEditor.$cursor);1030 currentKeyEventParser.shortcutHandlers['ctrl+backspace'].start();1031 var newCursorOffset = getElementOffset(codeEditor.$cursor);1032 ok(newCursorOffset.left > cursorOffset.left);1033 ok(newCursorOffset.top < cursorOffset.top);1034 equal(codeEditor.$lines.length, 1);1035 equal(codeEditor._getEditorText(), 'a b c a b c');1036 });1037 test('pressShortcut"Ctrl + delete"', function () {1038 codeEditorInitializer.init({1039 text: 'a\r\nThe quick brown'1040 });1041 currentKeyEventParser.shortcutHandlers['right'].start();1042 var cursorOffset = getElementOffset(codeEditor.$cursor);1043 currentKeyEventParser.shortcutHandlers['ctrl+delete'].start();1044 deepEqual(getElementOffset(codeEditor.$cursor), cursorOffset);1045 equal(codeEditor._getEditorText(), 'aThe quick brown');1046 currentKeyEventParser.shortcutHandlers['ctrl+delete'].start();1047 deepEqual(getElementOffset(codeEditor.$cursor), cursorOffset);1048 equal(codeEditor._getEditorText(), 'aquick brown');1049 currentKeyEventParser.shortcutHandlers['ctrl+delete'].start();1050 deepEqual(getElementOffset(codeEditor.$cursor), cursorOffset);1051 equal(codeEditor._getEditorText(), 'abrown');1052 });1053 test('pressShortcut"Ctrl + delete"WithSelection', function () {1054 codeEditorInitializer.init({1055 text: '1 2 3\r\n' +1056 ' 4 5 6\r\n' +1057 '7 8 9'1058 });1059 codeEditor._setCursor(0, 2);1060 currentKeyEventParser.shortcutHandlers['shift+down'].start();1061 currentKeyEventParser.shortcutHandlers['shift+down'].start();1062 var selectionStartWidth = codeEditor.$selectionStart.width(),1063 selectionCenterHeight = codeEditor.$selectionCenter.height(),1064 selectionEndWidth = codeEditor.$selectionEnd.width();1065 ok(selectionStartWidth && selectionCenterHeight && selectionEndWidth);1066 var cursorOffset = getElementOffset(codeEditor.$cursor);1067 currentKeyEventParser.shortcutHandlers['ctrl+delete'].start();1068 ok(!codeEditor.$selectionStart.width());1069 ok(!codeEditor.$selectionCenter.height());1070 ok(!codeEditor.$selectionEnd.width());1071 var newCursorOffset = getElementOffset(codeEditor.$cursor);1072 ok(newCursorOffset.top < cursorOffset.top);1073 equal(newCursorOffset.left, cursorOffset.left);1074 equal(codeEditor.$lines.length, 1);1075 equal(codeEditor._getEditorText(), '1 8 9');1076 });1077 test('pressShortcut"Ctrl + delete"WithInvertSelection', function () {1078 codeEditorInitializer.init({1079 text: 'a\r\n' +1080 ' A\r\n' +1081 'a b'1082 });1083 codeEditor._setCursor(2, 1);1084 currentKeyEventParser.shortcutHandlers['shift+left'].start();1085 currentKeyEventParser.shortcutHandlers['shift+up'].start();1086 currentKeyEventParser.shortcutHandlers['shift+up'].start();1087 var selectionStartWidth = codeEditor.$selectionStart.width(),1088 selectionCenterHeight = codeEditor.$selectionCenter.height(),1089 selectionEndWidth = codeEditor.$selectionEnd.width();1090 ok(selectionStartWidth && selectionCenterHeight && selectionEndWidth);1091 var cursorOffset = getElementOffset(codeEditor.$cursor);1092 currentKeyEventParser.shortcutHandlers['ctrl+delete'].start();1093 deepEqual(getElementOffset(codeEditor.$cursor), cursorOffset);1094 ok(!codeEditor.$selectionStart.width());1095 ok(!codeEditor.$selectionCenter.height());1096 ok(!codeEditor.$selectionEnd.width());1097 equal(codeEditor.$lines.length, 1);1098 equal(codeEditor._getEditorText(), ' b');1099 });1100 asyncTest('CopyVia"Ctrl+C"AndPasteVia"Ctrl+V"', function () {1101 codeEditorInitializer.init({1102 text: 'abcdef\r\n123456\r\nqw'1103 });1104 codeEditor._setCursor(0, 3);1105 currentKeyEventParser.shortcutHandlers['shift+down'].start();1106 currentKeyEventParser.shortcutHandlers['shift+down'].start();1107 currentKeyEventParser.shortcutHandlers['ctrl+c'].start();1108 codeEditor._setCursor(1, 4);1109 var cursorOffset = getElementOffset(codeEditor.$cursor);1110 currentKeyEventParser.shortcutHandlers['ctrl+v'].start();1111 window.setTimeout(function () {1112 var resultText = 'abcdef\r\n1234def\r\n123456\r\nqw56\r\nqw';1113 equal(codeEditor._getEditorText(), resultText);1114 notEqual(getElementOffset(codeEditor.$cursor).left, cursorOffset.left);1115 notEqual(getElementOffset(codeEditor.$cursor).top, cursorOffset.top);1116 start();1117 });1118 });1119 asyncTest('CopyVia"Ctrl+C"AndChangeSelectionTextVia"Ctrl+V"', function () {1120 codeEditorInitializer.init({1121 text: 'abcdef\r\n123456\r\nqw'1122 });1123 codeEditor._setCursor(0, 3);1124 currentKeyEventParser.shortcutHandlers['shift+down'].start();1125 currentKeyEventParser.shortcutHandlers['shift+down'].start();1126 currentKeyEventParser.shortcutHandlers['ctrl+c'].start();1127 codeEditor._setCursor(1, 4);1128 var cursorOffset = getElementOffset(codeEditor.$cursor);1129 currentKeyEventParser.shortcutHandlers['shift+up'].start();1130 currentKeyEventParser.shortcutHandlers['ctrl+v'].start();1131 window.setTimeout(function () {1132 var resultText = 'abcddef\r\n123456\r\nqw56\r\nqw';1133 equal(codeEditor._getEditorText(), resultText);1134 ok(getElementOffset(codeEditor.$cursor).left < cursorOffset.left);1135 ok(getElementOffset(codeEditor.$cursor).top > cursorOffset.top);1136 start();1137 });1138 });1139 asyncTest('CopyTextWithIndentsVia"Ctrl+C"AndPasteVia"Ctrl+V"', function () {1140 codeEditorInitializer.init({1141 text: 'abcdef\r\n 123456\r\n qw'1142 });1143 codeEditor._setCursor(0, 3);1144 currentKeyEventParser.shortcutHandlers['shift+down'].start();1145 currentKeyEventParser.shortcutHandlers['shift+down'].start();1146 currentKeyEventParser.shortcutHandlers['ctrl+c'].start();1147 codeEditor._setCursor(0, 2);1148 var cursorOffset = getElementOffset(codeEditor.$cursor);1149 currentKeyEventParser.shortcutHandlers['ctrl+v'].start();1150 window.setTimeout(function () {1151 var resultText = 'abdef\r\n 123456\r\n qcdef\r\n 123456\r\n qw';1152 equal(codeEditor._getEditorText(), resultText);1153 ok(getElementOffset(codeEditor.$cursor).left > cursorOffset.left);1154 ok(getElementOffset(codeEditor.$cursor).top > cursorOffset.top);1155 start();1156 });1157 });1158 test('CutViaSelectionAndPress"Ctrl+X"', function () {1159 codeEditorInitializer.init({1160 text: 'abcdef\r\n123456\r\nqw'1161 });1162 codeEditor._setCursor(0, 3);1163 var cursorOffset = getElementOffset(codeEditor.$cursor);1164 currentKeyEventParser.shortcutHandlers['shift+down'].start();1165 currentKeyEventParser.shortcutHandlers['ctrl+x'].start();1166 equal(codeEditor._getEditorText(), 'abc456\r\nqw');1167 equal(codeEditor.$lines.length, 2);1168 deepEqual(cursorOffset, getElementOffset(codeEditor.$cursor));1169 });1170 test('CutLineVia"Ctrl+X"', function () {1171 codeEditorInitializer.init({1172 text: 'abcdef\r\n123456\r\nqw'1173 });1174 codeEditor._setCursor(0, 3);1175 var cursorOffset = getElementOffset(codeEditor.$cursor);1176 currentKeyEventParser.shortcutHandlers['ctrl+x'].start();1177 equal(codeEditor._getEditorText(), '123456\r\nqw');1178 equal(codeEditor.$lines.length, 2);1179 deepEqual(cursorOffset, getElementOffset(codeEditor.$cursor));1180 });1181 asyncTest('CutViaSelectionAndPress"Ctrl+X"AndPasteVia"Ctrl+V"', function () {1182 codeEditorInitializer.init({1183 text: 'abcdef\r\n123456\r\nqw'1184 });1185 codeEditor._setCursor(0, 3);1186 var cursorOffset = getElementOffset(codeEditor.$cursor);1187 currentKeyEventParser.shortcutHandlers['shift+down'].start();1188 currentKeyEventParser.shortcutHandlers['ctrl+x'].start();1189 codeEditor._setCursor(1, 1);1190 currentKeyEventParser.shortcutHandlers['ctrl+v'].start();1191 window.setTimeout(function () {1192 var resultText = 'abc456\r\nqdef\r\n123w';1193 equal(codeEditor._getEditorText(), resultText);1194 ok(getElementOffset(codeEditor.$cursor).top > cursorOffset.top);1195 start();1196 });1197 });1198 asyncTest('CutLineVia"Ctrl+X"AndPasteVia"Ctrl+V"', function () {1199 codeEditorInitializer.init({1200 text: 'abcdef\r\n123456\r\nqw'1201 });1202 codeEditor._setCursor(0, 3);1203 var cursorOffset = getElementOffset(codeEditor.$cursor);1204 currentKeyEventParser.shortcutHandlers['ctrl+x'].start();1205 codeEditor._setCursor(1, 1);1206 currentKeyEventParser.shortcutHandlers['ctrl+v'].start();1207 window.setTimeout(function () {1208 var resultText = '123456\r\nqabcdef\r\nw';1209 equal(codeEditor._getEditorText(), resultText);1210 ok(getElementOffset(codeEditor.$cursor).top > cursorOffset.top);1211 start();1212 });1213 });1214 test('testMovingLineVia"Ctrl+Shift+Up"', function () {1215 codeEditorInitializer.init({1216 text: '123456\r\nabcdefg\r\n!@#$%^&*'1217 });1218 codeEditor._setCursor(2, 3);1219 var cursorOffset = getElementOffset(codeEditor.$cursor);1220 currentKeyEventParser.shortcutHandlers['ctrl+shift+up'].start();1221 equal(codeEditor._getEditorText(), '123456\r\n!@#$%^&*\r\nabcdefg');1222 var newCursorOffset = getElementOffset(codeEditor.$cursor);1223 ok(newCursorOffset.top < cursorOffset.top);1224 equal(newCursorOffset.left, cursorOffset.left);1225 cursorOffset = newCursorOffset;1226 currentKeyEventParser.shortcutHandlers['ctrl+shift+up'].start();1227 equal(codeEditor._getEditorText(), '!@#$%^&*\r\n123456\r\nabcdefg');1228 newCursorOffset = getElementOffset(codeEditor.$cursor);1229 ok(newCursorOffset.top < cursorOffset.top);1230 equal(newCursorOffset.left, cursorOffset.left);1231 currentKeyEventParser.shortcutHandlers['ctrl+shift+up'].start();1232 equal(codeEditor._getEditorText(), '!@#$%^&*\r\n123456\r\nabcdefg');1233 deepEqual(getElementOffset(codeEditor.$cursor), newCursorOffset);1234 });1235 test('testMovingLineVia"Ctrl+Shift+Down"', function () {1236 codeEditorInitializer.init({1237 text: '123456\r\nabcdefg\r\n!@#$%^&*'1238 });1239 codeEditor._setCursor(0, 3);1240 var cursorOffset = getElementOffset(codeEditor.$cursor);1241 currentKeyEventParser.shortcutHandlers['ctrl+shift+down'].start();1242 equal(codeEditor._getEditorText(), 'abcdefg\r\n123456\r\n!@#$%^&*');1243 var newCursorOffset = getElementOffset(codeEditor.$cursor);1244 ok(newCursorOffset.top > cursorOffset.top);1245 equal(newCursorOffset.left, cursorOffset.left);1246 cursorOffset = newCursorOffset;1247 currentKeyEventParser.shortcutHandlers['ctrl+shift+down'].start();1248 equal(codeEditor._getEditorText(), 'abcdefg\r\n!@#$%^&*\r\n123456');1249 newCursorOffset = getElementOffset(codeEditor.$cursor);1250 ok(newCursorOffset.top > cursorOffset.top);1251 equal(newCursorOffset.left, cursorOffset.left);1252 currentKeyEventParser.shortcutHandlers['ctrl+shift+down'].start();1253 equal(codeEditor._getEditorText(), 'abcdefg\r\n!@#$%^&*\r\n123456');1254 deepEqual(getElementOffset(codeEditor.$cursor), newCursorOffset);1255 });1256 test('testMovingLinesVia"Ctrl+Shift+Up"', function () {1257 codeEditorInitializer.init({1258 text: 'abc\r\ndef\r\n123456\r\n789\r\n654321\r\nghi'1259 });1260 codeEditor._setCursor(4, 2);1261 currentKeyEventParser.shortcutHandlers['shift+up'].start();1262 currentKeyEventParser.shortcutHandlers['shift+up'].start();1263 var cursorOffset = getElementOffset(codeEditor.$cursor);1264 currentKeyEventParser.shortcutHandlers['ctrl+shift+up'].start();1265 equal(codeEditor._getEditorText(), 'abc\r\n123456\r\n789\r\n654321\r\ndef\r\nghi');1266 var newCursorOffset = getElementOffset(codeEditor.$cursor);1267 ok(newCursorOffset.top < cursorOffset.top);1268 equal(newCursorOffset.left, cursorOffset.left);1269 cursorOffset = newCursorOffset;1270 currentKeyEventParser.shortcutHandlers['ctrl+shift+up'].start();1271 equal(codeEditor._getEditorText(), '123456\r\n789\r\n654321\r\nabc\r\ndef\r\nghi');1272 newCursorOffset = getElementOffset(codeEditor.$cursor);1273 ok(newCursorOffset.top < cursorOffset.top);1274 equal(newCursorOffset.left, cursorOffset.left);1275 cursorOffset = newCursorOffset;1276 currentKeyEventParser.shortcutHandlers['ctrl+shift+up'].start();1277 equal(codeEditor._getEditorText(), '123456\r\n789\r\n654321\r\nabc\r\ndef\r\nghi');1278 deepEqual(getElementOffset(codeEditor.$cursor), newCursorOffset);1279 });1280 test('testMovingLinesVia"Ctrl+Shift+Down"', function () {1281 codeEditorInitializer.init({1282 text: 'abc\r\n123456\r\n789\r\n654321\r\ndef\r\nghi'1283 });1284 codeEditor._setCursor(1, 2);1285 currentKeyEventParser.shortcutHandlers['shift+down'].start();1286 currentKeyEventParser.shortcutHandlers['shift+down'].start();1287 var cursorOffset = getElementOffset(codeEditor.$cursor);1288 currentKeyEventParser.shortcutHandlers['ctrl+shift+down'].start();1289 equal(codeEditor._getEditorText(), 'abc\r\ndef\r\n123456\r\n789\r\n654321\r\nghi');1290 var newCursorOffset = getElementOffset(codeEditor.$cursor);1291 ok(newCursorOffset.top > cursorOffset.top);1292 equal(newCursorOffset.left, cursorOffset.left);1293 cursorOffset = newCursorOffset;1294 currentKeyEventParser.shortcutHandlers['ctrl+shift+down'].start();1295 equal(codeEditor._getEditorText(), 'abc\r\ndef\r\nghi\r\n123456\r\n789\r\n654321');1296 newCursorOffset = getElementOffset(codeEditor.$cursor);1297 ok(newCursorOffset.top > cursorOffset.top);1298 equal(newCursorOffset.left, cursorOffset.left);1299 cursorOffset = newCursorOffset;1300 currentKeyEventParser.shortcutHandlers['ctrl+shift+down'].start();1301 equal(codeEditor._getEditorText(), 'abc\r\ndef\r\nghi\r\n123456\r\n789\r\n654321');1302 deepEqual(getElementOffset(codeEditor.$cursor), newCursorOffset);1303 });1304 /*TEST UNDO/REDO*/1305 test('testCancelLetterPressVia"Ctrl+z"And"Ctrl+Shift+z"', function () {1306 codeEditorInitializer.init();1307 currentKeyEventParser._symbolPressed('a');1308 var cursorOffset = getElementOffset(codeEditor.$cursor);1309 currentKeyEventParser.shortcutHandlers['ctrl+z'].start();1310 equal(codeEditor._getEditorText(), '');1311 deepEqual(getElementOffset(codeEditor.$cursor), getNullOffset());1312 currentKeyEventParser.shortcutHandlers['ctrl+shift+z'].start();1313 equal(codeEditor._getEditorText(), 'a');1314 deepEqual(getElementOffset(codeEditor.$cursor), cursorOffset);1315 });1316 test('testCancelEnterPressVia"Ctrl+z"And"Ctrl+Shift+z"', function () {1317 codeEditorInitializer.init({1318 text: 'a'1319 });1320 currentKeyEventParser.shortcutHandlers['right'].start();1321 var cursorOffset = getElementOffset(codeEditor.$cursor);1322 currentKeyEventParser.shortcutHandlers['enter'].start();1323 var newCursorOffset = getElementOffset(codeEditor.$cursor);1324 currentKeyEventParser.shortcutHandlers['ctrl+z'].start();1325 equal(codeEditor._getEditorText(), 'a');1326 equal(codeEditor.$lines.length, 1);1327 deepEqual(getElementOffset(codeEditor.$cursor), cursorOffset);1328 currentKeyEventParser.shortcutHandlers['shift+ctrl+z'].start();1329 equal(codeEditor._getEditorText(), 'a\r\n');1330 equal(codeEditor.$lines.length, 2);1331 deepEqual(getElementOffset(codeEditor.$cursor), newCursorOffset);1332 });1333 test('testCancelSetCursorPositionPressVia"Ctrl+z"And"Ctrl+Shift+z"', function () {1334 codeEditorInitializer.init({1335 text: 'abc\r\na'1336 });1337 var cursorOffset = getElementOffset(codeEditor.$cursor);1338 currentKeyEventParser.shortcutHandlers['right'].start();1339 currentKeyEventParser.shortcutHandlers['down'].start();1340 var newCursorOffset = getElementOffset(codeEditor.$cursor);1341 currentKeyEventParser.shortcutHandlers['ctrl+z'].start();1342 deepEqual(getElementOffset(codeEditor.$cursor), cursorOffset);1343 currentKeyEventParser.shortcutHandlers['shift+ctrl+z'].start();1344 deepEqual(getElementOffset(codeEditor.$cursor), newCursorOffset);1345 });1346 test('testCancel"Ctrl+Delete"WithSelectionVia"Ctrl+z"And"Ctrl+Shift+z"', function () {1347 codeEditorInitializer.init({1348 text: 'abc\r\n123'1349 });1350 currentKeyEventParser.shortcutHandlers['right'].start();1351 currentKeyEventParser.shortcutHandlers['shift+down'].start();1352 var cursorOffset = getElementOffset(codeEditor.$cursor),1353 selectionStartWidth = codeEditor.$selectionStart.width(),1354 selectionStartOffset = getElementOffset(codeEditor.$selectionStart),1355 selectionEndWidth = codeEditor.$selectionEnd.width(),1356 selectionEndOffset = getElementOffset(codeEditor.$selectionEnd);1357 currentKeyEventParser.shortcutHandlers['ctrl+delete'].start();1358 var newCursorOffset = getElementOffset(codeEditor.$cursor);1359 currentKeyEventParser.shortcutHandlers['ctrl+z'].start();1360 deepEqual(getElementOffset(codeEditor.$cursor), cursorOffset);1361 equal(codeEditor.$selectionStart.width(), selectionStartWidth);1362 equal(codeEditor.$selectionEnd.width(), selectionEndWidth);1363 deepEqual(getElementOffset(codeEditor.$selectionStart), selectionStartOffset);1364 deepEqual(getElementOffset(codeEditor.$selectionEnd), selectionEndOffset);1365 equal(codeEditor._getEditorText(), 'abc\r\n123');1366 currentKeyEventParser.shortcutHandlers['shift+ctrl+z'].start();1367 deepEqual(getElementOffset(codeEditor.$cursor), newCursorOffset);1368 ok(!codeEditor.$selectionStart.width());1369 ok(!codeEditor.$selectionEnd.width());1370 });1371 asyncTest('testCancelPasteVia"Ctrl+z"And"Ctrl+Shift+z"', function () {1372 codeEditorInitializer.init({1373 text: 'abc'1374 });1375 currentKeyEventParser.shortcutHandlers['shift+right'].start();1376 currentKeyEventParser.shortcutHandlers['ctrl+c'].start();1377 currentKeyEventParser.shortcutHandlers['right'].start();1378 var cursorOffset = getElementOffset(codeEditor.$cursor);1379 currentKeyEventParser.shortcutHandlers['ctrl+v'].start();1380 window.setTimeout(function () {1381 var newCursorOffset = getElementOffset(codeEditor.$cursor);1382 equal(codeEditor._getEditorText(), 'abac');1383 currentKeyEventParser.shortcutHandlers['ctrl+z'].start();1384 deepEqual(getElementOffset(codeEditor.$cursor), cursorOffset);1385 equal(codeEditor._getEditorText(), 'abc');1386 currentKeyEventParser.shortcutHandlers['shift+ctrl+z'].start();1387 deepEqual(getElementOffset(codeEditor.$cursor), newCursorOffset);1388 equal(codeEditor._getEditorText(), 'abac');1389 start();1390 });1391 });1392 test('testCancelTabPressVia"Ctrl+z"And"Ctrl+Shift+z"', function () {1393 codeEditorInitializer.init({1394 text: 'abc\r\na'1395 });1396 currentKeyEventParser.shortcutHandlers['right'].start();1397 currentKeyEventParser.shortcutHandlers['shift+down'].start();1398 var cursorOffset = getElementOffset(codeEditor.$cursor),1399 selectionStartWidth = codeEditor.$selectionStart.width(),1400 selectionStartOffset = getElementOffset(codeEditor.$selectionStart),1401 selectionEndWidth = codeEditor.$selectionEnd.width(),1402 selectionEndOffset = getElementOffset(codeEditor.$selectionEnd);1403 currentKeyEventParser.shortcutHandlers['tab'].start();1404 var newCursorOffset = getElementOffset(codeEditor.$cursor),1405 newSelectionStartWidth = codeEditor.$selectionStart.width(),1406 newSelectionStartOffset = getElementOffset(codeEditor.$selectionStart),1407 newSelectionEndWidth = codeEditor.$selectionEnd.width(),1408 newSelectionEndOffset = getElementOffset(codeEditor.$selectionEnd);1409 equal(codeEditor._getEditorText(), ' abc\r\n a');1410 currentKeyEventParser.shortcutHandlers['ctrl+z'].start();1411 deepEqual(getElementOffset(codeEditor.$cursor), cursorOffset);1412 equal(codeEditor.$selectionStart.width(), selectionStartWidth);1413 equal(codeEditor.$selectionEnd.width(), selectionEndWidth);1414 deepEqual(getElementOffset(codeEditor.$selectionStart), selectionStartOffset);1415 deepEqual(getElementOffset(codeEditor.$selectionEnd), selectionEndOffset);1416 equal(codeEditor._getEditorText(), 'abc\r\na');1417 currentKeyEventParser.shortcutHandlers['ctrl+shift+z'].start();1418 deepEqual(getElementOffset(codeEditor.$cursor), newCursorOffset);1419 equal(codeEditor.$selectionStart.width(), newSelectionStartWidth);1420 equal(codeEditor.$selectionEnd.width(), newSelectionEndWidth);1421 deepEqual(getElementOffset(codeEditor.$selectionStart), newSelectionStartOffset);1422 deepEqual(getElementOffset(codeEditor.$selectionEnd), newSelectionEndOffset);1423 });1424 test('testCancelStackVia"Ctrl+z"And"Ctrl+Shift+z"', function () {1425 codeEditorInitializer.init();1426 currentKeyEventParser._symbolPressed('a');1427 currentKeyEventParser._symbolPressed('b');1428 currentKeyEventParser._symbolPressed('c');1429 currentKeyEventParser.shortcutHandlers['ctrl+z'].start();1430 equal(codeEditor._getEditorText(), 'ab');1431 currentKeyEventParser.shortcutHandlers['ctrl+z'].start();1432 equal(codeEditor._getEditorText(), 'a');1433 currentKeyEventParser.shortcutHandlers['ctrl+shift+z'].start();1434 equal(codeEditor._getEditorText(), 'ab');1435 currentKeyEventParser._symbolPressed('1');1436 equal(codeEditor._getEditorText(), 'ab1');...

Full Screen

Full Screen

jquery.colorPicker.js

Source:jquery.colorPicker.js Github

copy

Full Screen

...52 });53 //调节饱和度和亮度54 var $sv = $colorPicker.querySelector(".sv");55 function onsvmove(event) {56 var elemOffset = Util.getElementOffset($sv.querySelector(".value"));57 var top = event.pageY - elemOffset.top;58 if (top < -5) {59 top = -5;60 }61 if (top > elemOffset.height - 5) {62 top = elemOffset.height - 5;63 }64 $sv.querySelector(".point").style.top = top + 'px';65 var left = event.pageX - elemOffset.left;66 if (left < -5) {67 left = -5;68 }69 if (left > elemOffset.width - 5) {70 left = elemOffset.width - 5;71 }72 $sv.querySelector(".point").style.left = left + 'px';73 picker.refresh('hsv');74 }75 $sv.querySelector(".value,.point").addEventListener("mousedown", function (event) {76 function mouseup() {77 document.removeEventListener("mousemove", onsvmove);78 document.removeEventListener("mouseup", mouseup);79 }80 onsvmove(event);81 document.addEventListener("mousemove", onsvmove);82 document.addEventListener("mouseup", mouseup);83 });84 //色相调节区85 var $h = $colorPicker.querySelector(".h");86 function onhmove(event) {87 var offset = Util.getElementOffset($h.querySelector(".value"));88 var top = event.pageY - offset.top;89 if (top < 0) {90 top = 0;91 }92 if (top > offset.height - 1) {93 top = offset.height - 1;94 }95 $h.querySelector(".point").style.top = top + 'px';96 picker.refresh('hsv');97 }98 $h.querySelector(".value,.point").addEventListener("mousedown", function (event) {99 function mouseup() {100 document.removeEventListener("mousemove", onhmove);101 document.removeEventListener("mouseup", mouseup);102 }103 onhmove(event);104 document.addEventListener("mousemove", onhmove);105 document.addEventListener("mouseup", mouseup);106 });107 //透明度调节区108 var $alpha = $colorPicker.querySelector(".alpha");109 function onalphamove(event) {110 var offset = Util.getElementOffset($alpha.querySelector(".value"));111 var top = event.pageY - offset.top;112 if (top < 0) {113 top = 0;114 }115 if (top > offset.height - 1) {116 top = offset.height - 1;117 }118 $alpha.querySelector(".point").style.top = top + 'px';119 picker.refresh('alpha');120 }121 $alpha.querySelector(".value,.point").addEventListener("mousedown", function (event) {122 function mouseup() {123 document.removeEventListener("mousemove", onalphamove);124 document.removeEventListener("mouseup", mouseup);125 }126 onalphamove(event);127 document.addEventListener("mousemove", onalphamove);128 document.addEventListener("mouseup", mouseup);129 });130 //调节值显示区 131 Array.prototype.map.call($colorPicker.querySelectorAll(".values input"), function (elem) {132 elem.addEventListener("change", function () {133 picker.refresh(this.name);134 });135 })136 //添加到页面137 document.body.appendChild($colorPicker);138 //显示139 if (config.show) {140 picker.show();141 }142 return picker;143 },144 'getValues': function (type) {145 type = type || "hsv";146 var picker = this;147 var h, s, v;148 var rgb;149 var hex;150 var alpha = (picker.$colorPicker.querySelector(".alpha").querySelector(".point").offsetTop - picker.$colorPicker.querySelector(".alpha").offsetTop) / 180;151 switch (type) {152 // case "h":153 // h = Number.parseFloat(picker.$colorPicker.querySelector(".values").querySelector("input[name='h']").value);154 // h = isNaN(h) ? picker.$colorPicker.querySelector(".values").querySelector("input[name='h']").getAttribute("value") : h;155 // s = Util.getElementOffset(picker.$colorPicker.querySelector(".sv").querySelector(".point").left - Util.getElementOffset(picker.$colorPicker.querySelector(".sv")).left) / 180;156 // v = 1 - Util.getElementOffset(picker.$colorPicker.querySelector(".sv").querySelector(".point").top - Util.getElementOffset(picker.$colorPicker.querySelector(".sv")).top) / 180;157 // break;158 // case "s":159 // h = (picker.$colorPicker.querySelector(".h").querySelector(".point").offsetTop - picker.$colorPicker.querySelector(".h").offsetTop) * 2;160 // s = Number.parseFloat(picker.$colorPicker.querySelector(".values").querySelector("input[name='s']").value);161 // s = isNaN(s) ? picker.$colorPicker.querySelector(".values").querySelector("input[name='s']").getAttribute("value") : s;162 // v = 1 - Util.getElementOffset(picker.$colorPicker.querySelector(".sv").querySelector(".point").top - picker.$colorPicker.querySelector(".sv").offsetTop) / 180;163 // break;164 // case "v":165 // h = (picker.$colorPicker.querySelector(".h").querySelector(".point").offsetTop - picker.$colorPicker.querySelector(".h").offsetTop) * 2;166 // s = Util.getElementOffset(picker.$colorPicker.querySelector(".sv").querySelector(".point").left - Util.getElementOffset(picker.$colorPicker.querySelector(".sv")).left) / 180;167 // v = Number.parseFloat(picker.$colorPicker.querySelector(".values").querySelector("input[name='v']").value);168 // v = isNaN(v) ? picker.$colorPicker.querySelector(".values").querySelector("input[name='v']").getAttribute("value") : v;169 // break;170 case "rgb":171 var rgb = Util.getRGBAforStr(picker.$colorPicker.querySelector(".values").querySelector("input[name='rgb']").value);172 if (rgb.r > 255 || rgb.r < 0 || rgb.g > 255 || rgb.g < 0 || rgb.b > 255 || rgb.b < 0) {173 rgb = picker.$colorPicker.querySelector(".values").querySelector("input[name='rgb']").getAttribute("value");174 }175 var hsv = colorPicker.rgb2hsv(rgb);176 h = hsv.h;177 s = hsv.s;178 v = hsv.v;179 alpha = rgb.a;180 break;181 // case "hex":182 // var hex = picker.$colorPicker.querySelector(".values").querySelector("input[name='hex']").value.match(/[a-f0-9]{6}/i);183 // if (!hex) {184 // picker.$colorPicker.querySelector(".values").querySelector("input[name='hex']").value = picker.$colorPicker.querySelector(".values").querySelector("input[name='hex']").getAttribute('data-value');185 // return;186 // }187 // hex = hex[0]188 // console.log(hex);189 // var rgb = colorPicker.hex2rgb(hex);190 // var hsv = colorPicker.rgb2hsv(rgb);191 // h = hsv.h;192 // s = hsv.s;193 // v = hsv.v;194 // break;195 case 'hsv':196 default:197 h = (Util.getElementOffset(picker.$colorPicker.querySelector(".h").querySelector(".point")).top - Util.getElementOffset(picker.$colorPicker.querySelector(".h")).top) * 2;198 s = (Util.getElementOffset(picker.$colorPicker.querySelector(".sv").querySelector(".point")).left + 5 - Util.getElementOffset(picker.$colorPicker.querySelector(".sv")).left) / 180;199 v = 1 - (Util.getElementOffset(picker.$colorPicker.querySelector(".sv").querySelector(".point")).top + 5 - Util.getElementOffset(picker.$colorPicker.querySelector(".sv")).top) / 180;200 break;201 }202 //微调精度,203 // h = h >= 358 ? 360 : h;204 // s = s >= 0.94 ? 1 : s;205 // v = v >= 0.94 ? 1 : v;206 // alpha = alpha >= 0.99 ? 1 : alpha;207 //限定值域208 h = h < 0 ? 0 : h;209 s = s < 0 ? 0 : s;210 v = v < 0 ? 0 : v;211 alpha = alpha < 0 ? 0 : alpha;212 rgb = rgb ? rgb : colorPicker.hsv2rgb({ h: h, s: s, v: v });213 hex = hex ? hex : colorPicker.rgb2hex(rgb);...

Full Screen

Full Screen

xmldoc.js

Source:xmldoc.js Github

copy

Full Screen

...131 var prev = null;132 if (node.nodeType == 1) {133 // after = true is only valid for elements134 if (!after)135 return this.getElementOffset(/** @type {Element} */ (node));136 } else {137 // offsetInNode is only valid for text nodes138 extraOffset = offsetInNode;139 prev = node.previousSibling;140 if (!prev) {141 node = node.parentNode;142 extraOffset += 1;143 return this.getElementOffset(/** @type {Element} */ (node)) + extraOffset;144 }145 node = prev;146 }147 while (true) {148 while (node.lastChild) {149 node = node.lastChild;150 }151 if (node.nodeType == 1) {152 // empty element153 break;154 }155 extraOffset += node.textContent.length;156 prev = node.previousSibling;157 if (!prev) {158 node = node.parentNode;159 break;160 }161 node = prev;162 }163 extraOffset += 1;164 return this.getElementOffset(/** @type {Element} */ (node)) + extraOffset;165};166/**167 * @return {number}168 */169adapt.xmldoc.XMLDocHolder.prototype.getTotalOffset = function() {170 if (this.totalOffset < 0) {171 this.totalOffset = this.getNodeOffset(this.root, 0, true);172 }173 return this.totalOffset;174};175/**176 * @param {number} offset177 * @return {Node} last node such that its offset is less or equal to the given178 */179adapt.xmldoc.XMLDocHolder.prototype.getNodeByOffset = function(offset) {180 var elementOffset;181 // First, find the last element in the document, such that182 // this.getElementOffset(element) <= offset; if offest matches183 // exactly, just return it.184 var self = this;185 var element = this.root;186 while(true) {187 elementOffset = this.getElementOffset(element);188 if (elementOffset >= offset)189 return element;190 var children = element.children; // Element children191 if (!children)192 break;193 var index = adapt.base.binarySearch(children.length, function(index) {194 var child = children[index];195 var childOffset = self.getElementOffset(child);196 return childOffset > offset;197 });198 if (index == 0) {199 break;200 }201 if (goog.DEBUG) {202 if (index < children.length) {203 var elemOffset = self.getElementOffset(children[index]);204 if (elemOffset <= offset)205 throw new Error("Consistency check failed!");206 }207 }208 element = children[index-1];209 }210 // Now we have element with offset less than desired. Find following (non-element)211 // node with the right offset.212 var nodeOffset = elementOffset + 1;213 var node = element;214 var next = node.firstChild || node.nextSibling;215 var lastGood = null;216 while (true) {217 if (next) {...

Full Screen

Full Screen

floating-labels.js

Source:floating-labels.js Github

copy

Full Screen

...34 this.onOffPanel();35 }36 adjustWidthAndPosition() {37 this.clone.style.width = this.panel.offsetWidth + 'px';38 this.clone.style.left = Utils.getElementOffset(this.panel).left;39 }40 onOffPanel() {41 if(window.innerWidth <= this.mobileThreshold) {42 this.onFloat();43 return;44 }45 46 this.hide();47 }48 onFloat() {49 this.panelOffset = Utils.getElementOffset(this.panel).top;50 this.maxOffset = Utils.getElementOffset(this.lastItem).top - Utils.outerHeight(this.clone);51 window.addEventListener('scroll', this.onScroll);52 this.onScroll();53 }54 hide() {55 this.clone.style.visibility = 'hidden';56 window.removeEventListener('scroll', this.onScroll);57 }58 handleScroll() {59 let scrollValue = this.getScrollTop();60 if(scrollValue < this.panelOffset) { // above the topmost panel61 this.clone.style.visibility = 'hidden';62 } else if( scrollValue > this.maxOffset + Utils.outerHeight(this.clone)) { // below last item63 this.clone.style.visibility = 'hidden';64 } else {...

Full Screen

Full Screen

FamEventArgsFactory.js

Source:FamEventArgsFactory.js Github

copy

Full Screen

...28 return family.BREAK;29 }30 result.childrenItems.push(combinedContextsTask.getConfig(itemid));31 });32 panelOffset = getElementOffset(data.layout.mousePanel);33 offset = getElementOffset(data.layout.element);34 itemPosition = alignDiagramTask.getItemPosition(newTreeItemId);35 result.position = new Rect(itemPosition.actualPosition)36 .translate(panelOffset.left, panelOffset.top)37 .translate(-offset.left, -offset.top);38 }39 if (name != null) {40 result.name = name;41 }42 return result;...

Full Screen

Full Screen

OrgEventArgsFactory.js

Source:OrgEventArgsFactory.js Github

copy

Full Screen

...18 result.context = newItemConfig;19 if (newItemConfig.parent !== null) {20 result.parentItem = combinedContextsTask.getConfig(newItemConfig.parent);21 }22 panelOffset = getElementOffset(data.layout.mousePanel);23 offset = getElementOffset(data.layout.element);24 itemPosition = alignDiagramTask.getItemPosition(newTreeItemId),25 result.position = new Rect(itemPosition.actualPosition)26 .translate(panelOffset.left, panelOffset.top)27 .translate(-offset.left, -offset.top);28 }29 if (name != null) {30 result.name = name;31 }32 return result;...

Full Screen

Full Screen

isScrolledIntoView.js

Source:isScrolledIntoView.js Github

copy

Full Screen

...3 const docViewTop =4 (document.documentElement && document.documentElement.scrollTop) ||5 document.body.scrollTop;6 const docViewBottom = docViewTop + window.innerHeight;7 const elemTop = getElementOffset(element).top;8 const elemBottom = elemTop + element.clientHeight;9 return { elemBottom, docViewBottom, elemTop, docViewTop };10}11export function isScrolledIntoCenterView(element) {12 const { elemBottom, docViewBottom, elemTop } = getElementPosition(element);13 return elemTop + (elemBottom - elemTop) / 2 <= docViewBottom;14}15export function isScrolledIntoView(element) {16 const { elemBottom, docViewBottom, elemTop, docViewTop } = getElementPosition(17 element,18 );19 return elemBottom <= docViewBottom && elemTop >= docViewTop;20}21export function isScrolledOutOfView(element) {22 const docViewTop =23 (document.documentElement && document.documentElement.scrollTop) ||24 document.body.scrollTop;25 const elemTop = getElementOffset(element).top;26 const elemBottom = elemTop + element.clientHeight;27 return elemBottom < docViewTop;...

Full Screen

Full Screen

util.js

Source:util.js Github

copy

Full Screen

...17function scaleAsString(scale) {18 return scale.domain() + "-" + scale.range();19}20// http://stackoverflow.com/a/2885725521function getElementOffset(element) {22 var de = document.documentElement;23 var box = element.getBoundingClientRect();24 var top = box.top + window.pageYOffset - de.clientTop;25 var left = box.left + window.pageXOffset - de.clientLeft;26 return { top: top, left: left };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5 const articleHeader = await Selector('.result-content').find('h1');6 const headerLocation = await articleHeader.getElementOffset();7 const headerSize = await articleHeader.getElementSize();8 const headerBottomRightCorner = {9 };10});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 const getElementOffset = Selector(() => {4 return {5 };6 });7 .click(getElementOffset);8});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2import { getElementOffset } from 'testcafe-browser-tools';3test('My Test', async t => {4 const element = Selector('#slider');5 const { left, right, top, bottom } = await getElementOffset(element);6 console.log(left, right, top, bottom);7});8import { Selector } from 'testcafe';9import { getElementPosition } from 'testcafe-browser-tools';10test('My Test', async t => {11 const element = Selector('#slider');12 const { x, y } = await getElementPosition(element);13 console.log(x, y);14});15import { Selector } from 'testcafe';16import { getElementSize } from 'testcafe-browser-tools';17test('My Test', async t => {18 const element = Selector('#slider');19 const { width, height } = await getElementSize(element);20 console.log(width, height);21});22import { Selector } from 'testcafe';23import { getElementScreenshot } from 'testcafe-browser-tools';24test('My Test', async t => {25 const element = Selector('#slider');26 const screenshot = await getElementScreenshot(element);27 console.log(screenshot);28});29import { Selector } from 'testcafe';30import { hideElement } from 'testcafe-browser-tools';31test('My Test', async t => {32 const element = Selector('#slider');33 await hideElement(element);34});35import { Selector

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector, ClientFunction } from 'testcafe';2test('My Test', async t => {3 const getElementOffset = ClientFunction(() => {4 return {5 x: document.getElementById('slider').getBoundingClientRect().left,6 y: document.getElementById('slider').getBoundingClientRect().top7 };8 });9 const slider = Selector('#slider');10 const sliderOffset = await getElementOffset(slider);11 console.log(sliderOffset.x, sliderOffset.y);12});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector, ClientFunction } from 'testcafe';2const getElementOffset = ClientFunction(selector => {3 const el = document.querySelector(selector);4 const rect = el.getBoundingClientRect();5 return {6 };7});8test('My first test', async t => {9 .click(Selector('a').withText('Example 1'))10 .click(Selector('a').withText('Example 2'))11 .click(Selector('a').withText('Example 3'))12 .click(Selector('a').withText('Example 4'))13 .click(Selector('a').withText('Example 5'))14 .click(Selector('a').withText('Example 6'))15 .click(Selector('a').withText('Example 7'))16 .click(Selector('a').withText('Example 8'))17 .click(Selector('a').withText('Example 9'))18 .click(Selector('a').withText('Example 10'))19 .click(Selector('a').withText('Example 11'))20 .click(Selector('a').withText('Example 12'))21 .click(Selector('a').withText('Example 13'))22 .click(Selector('a').withText('Example 14'))23 .click(Selector('a').withText('Example 15'))24 .click(Selector('a').withText('Example 16'))25 .click(Selector('a').withText('Example 17'))26 .click(Selector('a').withText('Example 18'))27 .click(Selector('a').withText('Example 19'))28 .click(Selector('a').withText('Example 20'))29 .click(Selector('a').withText('Example 21'))30 .click(Selector('a').withText('Example 22'))31 .click(Selector('a').withText('Example 23'))32 .click(Selector('a').withText('Example 24'))33 .click(Selector('a').withText('Example 25'))34 .click(Selector('a

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 const getLocation = ClientFunction(() => {4 const element = document.querySelector('#populate');5 return {6 };7 });8 .click(Selector('#populate'))9 .expect(getLocation()).eql({ x: 8, y: 96 });10});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector as $, t } from 'testcafe';2test('My first test', async t => {3 const getElementOffset = Selector(el => {4 const rect = el.getBoundingClientRect();5 return {6 };7 });8 const button = await $(getElementOffset).with({ boundTestRun: t });9 .click(button)10 .expect(button.exists).ok();11});12import { Selector as $, t } from 'testcafe';13test('My first test', async t => {14 const getElementOffset = Selector(el => {15 const rect = el.getBoundingClientRect();16 return {17 };18 });19 .click(getElementOffset)20 .expect(getElementOffset.exists).ok();21});22import {Selector} from 'testcafe';23export const getOffset = Selector(el => {24 const rect = el.getBoundingClientRect();25 return {26 };27});28export const getOffset = Selector(el => {29 const rect = el.getBoundingClientRect();30 return {31 };32}).with({boundTestRun: testController});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2import { getElementOffset } from 'testcafe-browser-tools';3const selector = Selector('#elementId');4test('Get element offset', async t => {5 const elementOffset = await getElementOffset(selector);6 console.log(elementOffset);7});8import { Selector } from 'testcafe';9import { getActiveElement } from 'testcafe-browser-tools';10const selector = Selector('#elementId');11test('Get active element', async t => {12 const activeElement = await getActiveElement();13 console.log(activeElement);14});15import { Selector } from 'testcafe';16import { getActiveElementInIFrame } from 'testcafe-browser-tools';17const selector = Selector('#elementId');18test('Get active element in iframe', async t => {19 const activeElement = await getActiveElementInIFrame(selector);20 console.log(activeElement);21});22import { Selector } from 'testcafe';23import { isElementFocusable } from 'testcafe-browser-tools';24const selector = Selector('#elementId');25test('Check if element is focusable', async t => {26 const isFocusable = await isElementFocusable(selector);27 console.log(isFocusable);28});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Selector } = require('testcafe');2const getOffset = Selector((selector, property) => {3 const element = document.querySelector(selector);4 const rect = element.getBoundingClientRect();5 return rect[property];6});7const { Selector, ClientFunction } = require('testcafe');8const getElementOffset = ClientFunction((selector, property) => {9 const element = document.querySelector(selector);10 const rect = element.getBoundingClientRect();11 return rect[property];12});13const getOffset = Selector((selector, property) => {14 const element = document.querySelector(selector);15 const rect = element.getBoundingClientRect();16 return rect[property];17});18const getElementOffset = ClientFunction((selector, property) => {19 const element = document.querySelector(selector);20 const rect = element.getBoundingClientRect();21 return rect[property];22});23const getOffset = Selector((selector, property) => {24 const element = document.querySelector(selector);25 const rect = element.getBoundingClientRect();26 return rect[property];27});28const getElementOffset = ClientFunction((selector, property) => {29 const element = document.querySelector(selector);30 const rect = element.getBoundingClientRect();31 return rect[property];32});33const getOffset = Selector((selector, property) => {34 const element = document.querySelector(selector);35 const rect = element.getBoundingClientRect();36 return rect[property];37});38const getElementOffset = ClientFunction((selector, property) => {39 const element = document.querySelector(selector);40 const rect = element.getBoundingClientRect();41 return rect[property];42});43const getOffset = Selector((selector, property) => {44 const element = document.querySelector(selector);45 const rect = element.getBoundingClientRect();46 return rect[property];47});48const getElementOffset = ClientFunction((selector, property) => {49 const element = document.querySelector(selector);50 const rect = element.getBoundingClientRect();51 return rect[property];52});53ts('Gt aiv ement', asyn => {54const seleaorivSEelecto = await ('#ActnveE';me55cosol.log(aivElemen)56} from 'testcafe';57mport { gAveElemetInIFrame-browser-tools58const selector = Selector('#elementId');59Seltconsrlfmlo (activ'estcafe);60});61lmport { Sslr}from'testcafe'62import {cisElementFocusableo}nfroms'testcafe-browser-tools'selector = Selector('#elementId');63te('Check ifeement s ocuabl', async t => {64test('Get activeisFocusable);65});66Rmtueni `trun` if heampecif'e, elem nt is vicibl {67 const activeElement = await getActiveElementInIFrame(selector);68});69import { Selector } from 'testcafe';70import { isElementFocusable } from 'testcafe-browser-tools';71const selector = Selector('#elementId');72test('Check if element is focusable', async t => {73 const isFocusable = await isElementFocusable(selector);74 console.log(isFocusable);75});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Selector } = require('testcafe');2const getOffset = Selector((selector, property) => {3 const element = document.querySelector(selector);4 const rect = element.getBoundingClientRect();5 return rect[property];6});7const { Selector, ClientFunction } = require('testcafe');8const getElementOffset = ClientFunction((selector, property) => {9 const element = document.querySelector(selector);10 const rect = element.getBoundingClientRect();11 return rect[property];12});13const getOffset = Selector((selector, property) => {14 const element = document.querySelector(selector);15 const rect = element.getBoundingClientRect();16 return rect[property];17});18const getElementOffset = ClientFunction((selector, property) => {19 const element = document.querySelector(selector);20 const rect = element.getBoundingClientRect();21 return rect[property];22});23const getOffset = Selector((selector, property) => {24 const element = document.querySelector(selector);25 const rect = element.getBoundingClientRect();26 return rect[property];27});28const getElementOffset = ClientFunction((selector, property) => {29 const element = document.querySelector(selector);30 const rect = element.getBoundingClientRect();31 return rect[property];32});33const getOffset = Selector((selector, property) => {34 const element = document.querySelector(selector);35 const rect = element.getBoundingClientRect();36 return rect[property];37});38const getElementOffset = ClientFunction((selector, property) => {39 const element = document.querySelector(selector);40 const rect = element.getBoundingClientRect();41 return rect[property];42});43const getOffset = Selector((selector, property) => {44 const element = document.querySelector(selector);45 const rect = element.getBoundingClientRect();46 return rect[property];47});48const getElementOffset = ClientFunction((selector, property) => {49 const element = document.querySelector(selector);50 const rect = element.getBoundingClientRect();51 return rect[property];52});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testcafe automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful