|
8 | 8 | */ |
9 | 9 |
|
10 | 10 | import Config from '@ckeditor/ckeditor5-utils/src/config'; |
| 11 | +import EditingController from '@ckeditor/ckeditor5-engine/src/controller/editingcontroller'; |
11 | 12 | import PluginCollection from '../plugincollection'; |
12 | 13 | import CommandCollection from '../commandcollection'; |
13 | 14 | import Locale from '@ckeditor/ckeditor5-utils/src/locale'; |
14 | 15 | import DataController from '@ckeditor/ckeditor5-engine/src/controller/datacontroller'; |
15 | 16 | import Model from '@ckeditor/ckeditor5-engine/src/model/model'; |
| 17 | +import EditingKeystrokeHandler from '../editingkeystrokehandler'; |
16 | 18 |
|
17 | 19 | import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin'; |
18 | 20 | import mix from '@ckeditor/ckeditor5-utils/src/mix'; |
19 | 21 |
|
20 | 22 | /** |
21 | | - * Class representing a basic editor. It contains a base architecture, without much additional logic. |
| 23 | + * Class representing the base of the editor. It is the API all plugins can expect to get when using editor property. |
| 24 | + * Editors implementation (like Classic Editor or Inline Editor) should extend this class. They can add their own |
| 25 | + * methods and properties. |
22 | 26 | * |
23 | 27 | * See also {@link module:core/editor/standardeditor~StandardEditor}. |
24 | 28 | * |
@@ -73,53 +77,57 @@ export default class Editor { |
73 | 77 | */ |
74 | 78 | this.t = this.locale.t; |
75 | 79 |
|
| 80 | + /** |
| 81 | + * Defines whether this editor is in read-only mode. |
| 82 | + * |
| 83 | + * In read-only mode the editor {@link #commands commands} are disabled so it is not possible |
| 84 | + * to modify document using them. |
| 85 | + * |
| 86 | + * @observable |
| 87 | + * @member {Boolean} #isReadOnly |
| 88 | + */ |
| 89 | + this.set( 'isReadOnly', false ); |
| 90 | + |
76 | 91 | /** |
77 | 92 | * The editor's model. |
78 | 93 | * |
79 | 94 | * The center of the editor's abstract data model. |
80 | 95 | * |
81 | | - * Besides the model, the editor usually contains two controllers – |
82 | | - * {@link #data data controller} and {@link #editing editing controller}. |
83 | | - * The former is used e.g. when setting or retrieving editor data and contains a useful |
84 | | - * set of methods for operating on the content. The latter controls user input and rendering |
85 | | - * the content for editing. |
86 | | - * |
87 | 96 | * @readonly |
88 | 97 | * @member {module:engine/model/model~Model} |
89 | 98 | */ |
90 | 99 | this.model = new Model(); |
91 | 100 |
|
| 101 | + // Creates main root. |
| 102 | + this.model.document.createRoot(); |
| 103 | + |
92 | 104 | /** |
93 | 105 | * The {@link module:engine/controller/datacontroller~DataController data controller}. |
| 106 | + * Used e.g. for setting or retrieving editor data. |
94 | 107 | * |
95 | 108 | * @readonly |
96 | 109 | * @member {module:engine/controller/datacontroller~DataController} |
97 | 110 | */ |
98 | 111 | this.data = new DataController( this.model ); |
99 | 112 |
|
100 | 113 | /** |
101 | | - * Defines whether this editor is in read-only mode. |
102 | | - * |
103 | | - * In read-only mode the editor {@link #commands commands} are disabled so it is not possible |
104 | | - * to modify document using them. |
| 114 | + * The {@link module:engine/controller/editingcontroller~EditingController editing controller}. |
| 115 | + * Controls user input and rendering the content for editing. |
105 | 116 | * |
106 | | - * @observable |
107 | | - * @member {Boolean} #isReadOnly |
| 117 | + * @readonly |
| 118 | + * @member {module:engine/controller/editingcontroller~EditingController} |
108 | 119 | */ |
109 | | - this.set( 'isReadOnly', false ); |
| 120 | + this.editing = new EditingController( this.model ); |
| 121 | + this.editing.view.bind( 'isReadOnly' ).to( this ); |
110 | 122 |
|
111 | 123 | /** |
112 | | - * The {@link module:engine/controller/editingcontroller~EditingController editing controller}. |
113 | | - * |
114 | | - * This property is set by more specialized editor classes (such as {@link module:core/editor/standardeditor~StandardEditor}), |
115 | | - * however, it's required for features to work as their engine-related parts will try to connect converters. |
116 | | - * |
117 | | - * When defining a virtual editor class, like one working in Node.js, it's possible to plug a virtual |
118 | | - * editing controller which only instantiates necessary properties, but without any observers and listeners. |
| 124 | + * Instance of the {@link module:core/editingkeystrokehandler~EditingKeystrokeHandler}. |
119 | 125 | * |
120 | 126 | * @readonly |
121 | | - * @member {module:engine/controller/editingcontroller~EditingController} #editing |
| 127 | + * @member {module:core/editingkeystrokehandler~EditingKeystrokeHandler} |
122 | 128 | */ |
| 129 | + this.keystrokes = new EditingKeystrokeHandler( this ); |
| 130 | + this.keystrokes.listenTo( this.editing.view ); |
123 | 131 | } |
124 | 132 |
|
125 | 133 | /** |
@@ -173,6 +181,8 @@ export default class Editor { |
173 | 181 | .then( () => { |
174 | 182 | this.model.destroy(); |
175 | 183 | this.data.destroy(); |
| 184 | + this.editing.destroy(); |
| 185 | + this.keystrokes.destroy(); |
176 | 186 | } ); |
177 | 187 | } |
178 | 188 |
|
|
0 commit comments