@ckeditor/ckeditor5-fullscreen 45.0.0-alpha.7 → 45.0.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-fullscreen",
3
- "version": "45.0.0-alpha.7",
3
+ "version": "45.0.0-alpha.9",
4
4
  "description": "Fullscreen mode feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -13,18 +13,18 @@
13
13
  "type": "module",
14
14
  "main": "src/index.js",
15
15
  "dependencies": {
16
- "@ckeditor/ckeditor5-comments": "45.0.0-alpha.7",
17
- "@ckeditor/ckeditor5-core": "45.0.0-alpha.7",
18
- "@ckeditor/ckeditor5-document-outline": "45.0.0-alpha.7",
19
- "@ckeditor/ckeditor5-editor-classic": "45.0.0-alpha.7",
20
- "@ckeditor/ckeditor5-editor-decoupled": "45.0.0-alpha.7",
21
- "@ckeditor/ckeditor5-icons": "45.0.0-alpha.7",
22
- "@ckeditor/ckeditor5-pagination": "45.0.0-alpha.7",
23
- "@ckeditor/ckeditor5-real-time-collaboration": "45.0.0-alpha.7",
24
- "@ckeditor/ckeditor5-revision-history": "45.0.0-alpha.7",
25
- "@ckeditor/ckeditor5-ui": "45.0.0-alpha.7",
26
- "@ckeditor/ckeditor5-utils": "45.0.0-alpha.7",
27
- "ckeditor5": "45.0.0-alpha.7"
16
+ "@ckeditor/ckeditor5-comments": "45.0.0-alpha.9",
17
+ "@ckeditor/ckeditor5-core": "45.0.0-alpha.9",
18
+ "@ckeditor/ckeditor5-document-outline": "45.0.0-alpha.9",
19
+ "@ckeditor/ckeditor5-editor-classic": "45.0.0-alpha.9",
20
+ "@ckeditor/ckeditor5-editor-decoupled": "45.0.0-alpha.9",
21
+ "@ckeditor/ckeditor5-icons": "45.0.0-alpha.9",
22
+ "@ckeditor/ckeditor5-pagination": "45.0.0-alpha.9",
23
+ "@ckeditor/ckeditor5-real-time-collaboration": "45.0.0-alpha.9",
24
+ "@ckeditor/ckeditor5-revision-history": "45.0.0-alpha.9",
25
+ "@ckeditor/ckeditor5-ui": "45.0.0-alpha.9",
26
+ "@ckeditor/ckeditor5-utils": "45.0.0-alpha.9",
27
+ "ckeditor5": "45.0.0-alpha.9"
28
28
  },
29
29
  "author": "CKSource (http://cksource.com/)",
30
30
  "license": "SEE LICENSE IN LICENSE.md",
@@ -43,12 +43,15 @@ export default class FullscreenEditing extends Plugin {
43
43
  // Set the Ctrl+Shift+F keystroke.
44
44
  this.editor.keystrokes.set('Ctrl+Shift+F', (evt, cancel) => {
45
45
  this.editor.execute('toggleFullscreen');
46
- // On non-Chromium browsers, the editor view is not blurred properly after moving the editable,
47
- // even though the `document.activeElement` is changed. Hence we need to blur the view manually.
46
+ // On non-Chromium browsers, the editor view and toolbar are not blurred properly after moving the editable,
47
+ // even though the `document.activeElement` is changed. Hence we need to blur them manually.
48
48
  // Fixes https://github.com/ckeditor/ckeditor5/issues/18250 and https://github.com/ckeditor/ckeditor5/issues/18247.
49
49
  if (!env.isBlink) {
50
50
  this.editor.editing.view.document.isFocused = false;
51
+ this.editor.ui.view.toolbar.focusTracker.focusedElement = null;
51
52
  }
53
+ // The order of scroll and focus is not important here.
54
+ this.editor.editing.view.scrollToTheSelection();
52
55
  this.editor.editing.view.focus();
53
56
  cancel();
54
57
  });
@@ -8,6 +8,7 @@
8
8
  import { Plugin } from 'ckeditor5/src/core.js';
9
9
  import { ButtonView, MenuBarMenuListItemButtonView } from 'ckeditor5/src/ui.js';
10
10
  import { IconFullscreenEnter, IconFullscreenLeave } from 'ckeditor5/src/icons.js';
11
+ import { env } from 'ckeditor5/src/utils.js';
11
12
  import FullscreenEditing from './fullscreenediting.js';
12
13
  import '../theme/fullscreen.css';
13
14
  const COMMAND_NAME = 'toggleFullscreen';
@@ -69,6 +70,14 @@ export default class FullscreenUI extends Plugin {
69
70
  }
70
71
  this.listenTo(view, 'execute', () => {
71
72
  editor.execute(COMMAND_NAME);
73
+ // On non-Chromium browsers, toolbar is not blurred properly after moving the editable,
74
+ // even though the `document.activeElement` is changed. Hence we need to blur the view manually.
75
+ // Fixes https://github.com/ckeditor/ckeditor5/issues/18250 and https://github.com/ckeditor/ckeditor5/issues/18247.
76
+ if (!env.isBlink) {
77
+ this.editor.ui.view.toolbar.focusTracker.focusedElement = null;
78
+ }
79
+ // The order of scroll and focus is not important here.
80
+ editor.editing.view.scrollToTheSelection();
72
81
  editor.editing.view.focus();
73
82
  });
74
83
  return view;
@@ -41,6 +41,10 @@ export default class AbstractEditorHandler {
41
41
  * that were hidden before entering the fullscreen mode.
42
42
  */
43
43
  private _hiddenElements;
44
+ /**
45
+ * A map matching the ancestors of the editable element with their scroll positions before entering fullscreen mode.
46
+ */
47
+ private _savedAncestorsScrollPositions;
44
48
  /**
45
49
  * A callback that shows the revision viewer, stored to restore the original one after exiting the fullscreen mode.
46
50
  */
@@ -143,4 +147,8 @@ export default class AbstractEditorHandler {
143
147
  * Only dialogs with the position set to "editor-top-side" should have their position changed.
144
148
  */
145
149
  private _setNewDialogPosition;
150
+ /**
151
+ * Saves the scroll positions of all ancestors of the given element.
152
+ */
153
+ private _saveAncestorsScrollPositions;
146
154
  }
@@ -48,6 +48,10 @@ export default class AbstractEditorHandler {
48
48
  * that were hidden before entering the fullscreen mode.
49
49
  */
50
50
  _hiddenElements = new Map();
51
+ /**
52
+ * A map matching the ancestors of the editable element with their scroll positions before entering fullscreen mode.
53
+ */
54
+ _savedAncestorsScrollPositions = new Map();
51
55
  /**
52
56
  * A callback that shows the revision viewer, stored to restore the original one after exiting the fullscreen mode.
53
57
  */
@@ -134,6 +138,7 @@ export default class AbstractEditorHandler {
134
138
  * Enables the fullscreen mode. It executes the editor-specific enable handler and then the configured callback.
135
139
  */
136
140
  enable() {
141
+ this._saveAncestorsScrollPositions(this._editor.ui.getEditableElement());
137
142
  this._defaultOnEnter();
138
143
  // Block scroll if the fullscreen container is the body element. Otherwise the document has to stay scrollable.
139
144
  if (this._editor.config.get('fullscreen.container') === this._document.body) {
@@ -231,6 +236,13 @@ export default class AbstractEditorHandler {
231
236
  if (this._placeholderMap.size === 0) {
232
237
  this._destroyContainer();
233
238
  }
239
+ // Restore scroll positions of all ancestors. It may include the closest editable wrapper causing the editor to change
240
+ // the visible content, which is not what we want. Thus, after executing the command, we use
241
+ // `editor.editing.view.scrollToTheSelection()` to scroll the editor viewport to the current selection.
242
+ for (const [ancestor, value] of this._savedAncestorsScrollPositions) {
243
+ ancestor.scrollTo(value.scrollLeft, value.scrollTop);
244
+ }
245
+ this._savedAncestorsScrollPositions.clear();
234
246
  // Pagination has to be restored after leaving fullscreen mode to ensure proper rendering.
235
247
  // Code coverage is provided in the commercial package repository as integration unit tests.
236
248
  /* istanbul ignore next -- @preserve */
@@ -506,4 +518,34 @@ export default class AbstractEditorHandler {
506
518
  dialogView.moveTo(fullscreenViewContainerRect.left + fullscreenViewContainerRect.width - dialogRect.width - DIALOG_OFFSET + scrollOffset, editorContainerRect.top);
507
519
  }
508
520
  }
521
+ /**
522
+ * Saves the scroll positions of all ancestors of the given element.
523
+ */
524
+ _saveAncestorsScrollPositions(domElement) {
525
+ let element = domElement.parentElement;
526
+ if (!element) {
527
+ return;
528
+ }
529
+ while (element) {
530
+ const overflowY = element.style.overflowY || global.window.getComputedStyle(element).overflowY;
531
+ const overflowX = element.style.overflowX || global.window.getComputedStyle(element).overflowX;
532
+ // Out of 5 possible keyword values: visible, hidden, clip, scroll and auto - only the last two allow for scrolling.
533
+ if (overflowY === 'auto' ||
534
+ overflowY === 'scroll' ||
535
+ overflowX === 'auto' ||
536
+ overflowX === 'scroll') {
537
+ this._savedAncestorsScrollPositions.set(element, {
538
+ scrollLeft: element.scrollLeft,
539
+ scrollTop: element.scrollTop
540
+ });
541
+ }
542
+ else if (element.tagName === 'HTML') {
543
+ this._savedAncestorsScrollPositions.set(element, {
544
+ scrollLeft: element.scrollLeft,
545
+ scrollTop: element.scrollTop
546
+ });
547
+ }
548
+ element = element.parentElement;
549
+ }
550
+ }
509
551
  }