function CKEditor5TestTrait::selectTextInsideElement

Same name and namespace in other branches
  1. 11.x core/modules/ckeditor5/tests/src/Traits/CKEditor5TestTrait.php \Drupal\Tests\ckeditor5\Traits\CKEditor5TestTrait::selectTextInsideElement()
  2. 10 core/modules/ckeditor5/tests/src/Traits/CKEditor5TestTrait.php \Drupal\Tests\ckeditor5\Traits\CKEditor5TestTrait::selectTextInsideElement()

Selects text inside an element.

Parameters

string $selector: A CSS selector for the element which contents should be selected.

File

core/modules/ckeditor5/tests/src/Traits/CKEditor5TestTrait.php, line 143

Class

CKEditor5TestTrait
Provides methods to test CKEditor 5.

Namespace

Drupal\Tests\ckeditor5\Traits

Code

protected function selectTextInsideElement(string $selector) : void {
  $javascript = <<<JS
  (function() {
    const el = document.querySelector(".ck-editor__main {<span class="php-variable">$selector</span>}");
    const range = document.createRange();
    range.selectNodeContents(el);
    const sel = window.getSelection();
    sel.removeAllRanges();
    sel.addRange(range);
  })();
  JS;
  $this->getSession()
    ->evaluateScript($javascript);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.