@ckeditor/ckeditor5-enter 40.0.0 → 40.2.0
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/CHANGELOG.md +25 -25
- package/LICENSE.md +2 -2
- package/package.json +4 -4
- package/src/augmentation.d.ts +15 -15
- package/src/augmentation.js +5 -5
- package/src/enter.d.ts +22 -22
- package/src/enter.js +45 -45
- package/src/entercommand.d.ts +52 -52
- package/src/entercommand.js +96 -96
- package/src/enterobserver.d.ts +44 -44
- package/src/enterobserver.js +61 -61
- package/src/index.d.ts +13 -13
- package/src/index.js +10 -10
- package/src/shiftenter.d.ts +19 -19
- package/src/shiftenter.js +63 -63
- package/src/shiftentercommand.d.ts +34 -34
- package/src/shiftentercommand.js +118 -118
- package/src/utils.d.ts +18 -18
- package/src/utils.js +20 -20
package/src/entercommand.js
CHANGED
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module enter/entercommand
|
|
7
|
-
*/
|
|
8
|
-
import { Command } from '@ckeditor/ckeditor5-core';
|
|
9
|
-
import { getCopyOnEnterAttributes } from './utils';
|
|
10
|
-
/**
|
|
11
|
-
* Enter command used by the {@link module:enter/enter~Enter Enter feature} to handle the <kbd>Enter</kbd> keystroke.
|
|
12
|
-
*/
|
|
13
|
-
export default class EnterCommand extends Command {
|
|
14
|
-
/**
|
|
15
|
-
* @inheritDoc
|
|
16
|
-
*/
|
|
17
|
-
execute() {
|
|
18
|
-
this.editor.model.change(writer => {
|
|
19
|
-
this.enterBlock(writer);
|
|
20
|
-
this.fire('afterExecute', { writer });
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Splits a block where the document selection is placed, in the way how the <kbd>Enter</kbd> key is expected to work:
|
|
25
|
-
*
|
|
26
|
-
* ```
|
|
27
|
-
* <p>Foo[]bar</p> -> <p>Foo</p><p>[]bar</p>
|
|
28
|
-
* <p>Foobar[]</p> -> <p>Foobar</p><p>[]</p>
|
|
29
|
-
* <p>Fo[ob]ar</p> -> <p>Fo</p><p>[]ar</p>
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* In some cases, the split will not happen:
|
|
33
|
-
*
|
|
34
|
-
* ```
|
|
35
|
-
* // The selection parent is a limit element:
|
|
36
|
-
* <figcaption>A[bc]d</figcaption> -> <figcaption>A[]d</figcaption>
|
|
37
|
-
*
|
|
38
|
-
* // The selection spans over multiple elements:
|
|
39
|
-
* <h>x[x</h><p>y]y<p> -> <h>x</h><p>[]y</p>
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
|
-
* @param writer Writer to use when performing the enter action.
|
|
43
|
-
* @returns Boolean indicating if the block was split.
|
|
44
|
-
*/
|
|
45
|
-
enterBlock(writer) {
|
|
46
|
-
const model = this.editor.model;
|
|
47
|
-
const selection = model.document.selection;
|
|
48
|
-
const schema = model.schema;
|
|
49
|
-
const isSelectionEmpty = selection.isCollapsed;
|
|
50
|
-
const range = selection.getFirstRange();
|
|
51
|
-
const startElement = range.start.parent;
|
|
52
|
-
const endElement = range.end.parent;
|
|
53
|
-
// Don't touch the roots and other limit elements.
|
|
54
|
-
if (schema.isLimit(startElement) || schema.isLimit(endElement)) {
|
|
55
|
-
// Delete the selected content but only if inside a single limit element.
|
|
56
|
-
// Abort, when crossing limit elements boundary (e.g. <limit1>x[x</limit1>donttouchme<limit2>y]y</limit2>).
|
|
57
|
-
// This is an edge case and it's hard to tell what should actually happen because such a selection
|
|
58
|
-
// is not entirely valid.
|
|
59
|
-
if (!isSelectionEmpty && startElement == endElement) {
|
|
60
|
-
model.deleteContent(selection);
|
|
61
|
-
}
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
if (isSelectionEmpty) {
|
|
65
|
-
const attributesToCopy = getCopyOnEnterAttributes(writer.model.schema, selection.getAttributes());
|
|
66
|
-
splitBlock(writer, range.start);
|
|
67
|
-
writer.setSelectionAttribute(attributesToCopy);
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
const leaveUnmerged = !(range.start.isAtStart && range.end.isAtEnd);
|
|
72
|
-
const isContainedWithinOneElement = (startElement == endElement);
|
|
73
|
-
model.deleteContent(selection, { leaveUnmerged });
|
|
74
|
-
if (leaveUnmerged) {
|
|
75
|
-
// Partially selected elements.
|
|
76
|
-
//
|
|
77
|
-
// <h>x[xx]x</h> -> <h>x^x</h> -> <h>x</h><h>^x</h>
|
|
78
|
-
if (isContainedWithinOneElement) {
|
|
79
|
-
splitBlock(writer, selection.focus);
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
// Selection over multiple elements.
|
|
83
|
-
//
|
|
84
|
-
// <h>x[x</h><p>y]y<p> -> <h>x^</h><p>y</p> -> <h>x</h><p>^y</p>
|
|
85
|
-
else {
|
|
86
|
-
writer.setSelection(endElement, 0);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function splitBlock(writer, splitPos) {
|
|
94
|
-
writer.split(splitPos);
|
|
95
|
-
writer.setSelection(splitPos.parent.nextSibling, 0);
|
|
96
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module enter/entercommand
|
|
7
|
+
*/
|
|
8
|
+
import { Command } from '@ckeditor/ckeditor5-core';
|
|
9
|
+
import { getCopyOnEnterAttributes } from './utils';
|
|
10
|
+
/**
|
|
11
|
+
* Enter command used by the {@link module:enter/enter~Enter Enter feature} to handle the <kbd>Enter</kbd> keystroke.
|
|
12
|
+
*/
|
|
13
|
+
export default class EnterCommand extends Command {
|
|
14
|
+
/**
|
|
15
|
+
* @inheritDoc
|
|
16
|
+
*/
|
|
17
|
+
execute() {
|
|
18
|
+
this.editor.model.change(writer => {
|
|
19
|
+
this.enterBlock(writer);
|
|
20
|
+
this.fire('afterExecute', { writer });
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Splits a block where the document selection is placed, in the way how the <kbd>Enter</kbd> key is expected to work:
|
|
25
|
+
*
|
|
26
|
+
* ```
|
|
27
|
+
* <p>Foo[]bar</p> -> <p>Foo</p><p>[]bar</p>
|
|
28
|
+
* <p>Foobar[]</p> -> <p>Foobar</p><p>[]</p>
|
|
29
|
+
* <p>Fo[ob]ar</p> -> <p>Fo</p><p>[]ar</p>
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* In some cases, the split will not happen:
|
|
33
|
+
*
|
|
34
|
+
* ```
|
|
35
|
+
* // The selection parent is a limit element:
|
|
36
|
+
* <figcaption>A[bc]d</figcaption> -> <figcaption>A[]d</figcaption>
|
|
37
|
+
*
|
|
38
|
+
* // The selection spans over multiple elements:
|
|
39
|
+
* <h>x[x</h><p>y]y<p> -> <h>x</h><p>[]y</p>
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @param writer Writer to use when performing the enter action.
|
|
43
|
+
* @returns Boolean indicating if the block was split.
|
|
44
|
+
*/
|
|
45
|
+
enterBlock(writer) {
|
|
46
|
+
const model = this.editor.model;
|
|
47
|
+
const selection = model.document.selection;
|
|
48
|
+
const schema = model.schema;
|
|
49
|
+
const isSelectionEmpty = selection.isCollapsed;
|
|
50
|
+
const range = selection.getFirstRange();
|
|
51
|
+
const startElement = range.start.parent;
|
|
52
|
+
const endElement = range.end.parent;
|
|
53
|
+
// Don't touch the roots and other limit elements.
|
|
54
|
+
if (schema.isLimit(startElement) || schema.isLimit(endElement)) {
|
|
55
|
+
// Delete the selected content but only if inside a single limit element.
|
|
56
|
+
// Abort, when crossing limit elements boundary (e.g. <limit1>x[x</limit1>donttouchme<limit2>y]y</limit2>).
|
|
57
|
+
// This is an edge case and it's hard to tell what should actually happen because such a selection
|
|
58
|
+
// is not entirely valid.
|
|
59
|
+
if (!isSelectionEmpty && startElement == endElement) {
|
|
60
|
+
model.deleteContent(selection);
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
if (isSelectionEmpty) {
|
|
65
|
+
const attributesToCopy = getCopyOnEnterAttributes(writer.model.schema, selection.getAttributes());
|
|
66
|
+
splitBlock(writer, range.start);
|
|
67
|
+
writer.setSelectionAttribute(attributesToCopy);
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const leaveUnmerged = !(range.start.isAtStart && range.end.isAtEnd);
|
|
72
|
+
const isContainedWithinOneElement = (startElement == endElement);
|
|
73
|
+
model.deleteContent(selection, { leaveUnmerged });
|
|
74
|
+
if (leaveUnmerged) {
|
|
75
|
+
// Partially selected elements.
|
|
76
|
+
//
|
|
77
|
+
// <h>x[xx]x</h> -> <h>x^x</h> -> <h>x</h><h>^x</h>
|
|
78
|
+
if (isContainedWithinOneElement) {
|
|
79
|
+
splitBlock(writer, selection.focus);
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
// Selection over multiple elements.
|
|
83
|
+
//
|
|
84
|
+
// <h>x[x</h><p>y]y<p> -> <h>x^</h><p>y</p> -> <h>x</h><p>^y</p>
|
|
85
|
+
else {
|
|
86
|
+
writer.setSelection(endElement, 0);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function splitBlock(writer, splitPos) {
|
|
94
|
+
writer.split(splitPos);
|
|
95
|
+
writer.setSelection(splitPos.parent.nextSibling, 0);
|
|
96
|
+
}
|
package/src/enterobserver.d.ts
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module enter/enterobserver
|
|
7
|
-
*/
|
|
8
|
-
import { Observer, DomEventData, type View, type BubblingEvent } from '@ckeditor/ckeditor5-engine';
|
|
9
|
-
/**
|
|
10
|
-
* Enter observer introduces the {@link module:engine/view/document~Document#event:enter `Document#enter`} event.
|
|
11
|
-
*/
|
|
12
|
-
export default class EnterObserver extends Observer {
|
|
13
|
-
/**
|
|
14
|
-
* @inheritDoc
|
|
15
|
-
*/
|
|
16
|
-
constructor(view: View);
|
|
17
|
-
/**
|
|
18
|
-
* @inheritDoc
|
|
19
|
-
*/
|
|
20
|
-
observe(): void;
|
|
21
|
-
/**
|
|
22
|
-
* @inheritDoc
|
|
23
|
-
*/
|
|
24
|
-
stopObserving(): void;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Fired when the user presses the <kbd>Enter</kbd> key.
|
|
28
|
-
*
|
|
29
|
-
* Note: This event is fired by the {@link module:enter/enterobserver~EnterObserver observer}
|
|
30
|
-
* (usually registered by the {@link module:enter/enter~Enter Enter feature} and
|
|
31
|
-
* {@link module:enter/shiftenter~ShiftEnter ShiftEnter feature}).
|
|
32
|
-
*
|
|
33
|
-
* @eventName module:engine/view/document~Document#enter
|
|
34
|
-
*/
|
|
35
|
-
export type ViewDocumentEnterEvent = BubblingEvent<{
|
|
36
|
-
name: 'enter';
|
|
37
|
-
args: [EnterEventData];
|
|
38
|
-
}>;
|
|
39
|
-
export interface EnterEventData extends DomEventData<InputEvent> {
|
|
40
|
-
/**
|
|
41
|
-
* Whether it is a soft enter (<kbd>Shift</kbd>+<kbd>Enter</kbd>) or a hard enter (<kbd>Enter</kbd>).
|
|
42
|
-
*/
|
|
43
|
-
isSoft: boolean;
|
|
44
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module enter/enterobserver
|
|
7
|
+
*/
|
|
8
|
+
import { Observer, DomEventData, type View, type BubblingEvent } from '@ckeditor/ckeditor5-engine';
|
|
9
|
+
/**
|
|
10
|
+
* Enter observer introduces the {@link module:engine/view/document~Document#event:enter `Document#enter`} event.
|
|
11
|
+
*/
|
|
12
|
+
export default class EnterObserver extends Observer {
|
|
13
|
+
/**
|
|
14
|
+
* @inheritDoc
|
|
15
|
+
*/
|
|
16
|
+
constructor(view: View);
|
|
17
|
+
/**
|
|
18
|
+
* @inheritDoc
|
|
19
|
+
*/
|
|
20
|
+
observe(): void;
|
|
21
|
+
/**
|
|
22
|
+
* @inheritDoc
|
|
23
|
+
*/
|
|
24
|
+
stopObserving(): void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Fired when the user presses the <kbd>Enter</kbd> key.
|
|
28
|
+
*
|
|
29
|
+
* Note: This event is fired by the {@link module:enter/enterobserver~EnterObserver observer}
|
|
30
|
+
* (usually registered by the {@link module:enter/enter~Enter Enter feature} and
|
|
31
|
+
* {@link module:enter/shiftenter~ShiftEnter ShiftEnter feature}).
|
|
32
|
+
*
|
|
33
|
+
* @eventName module:engine/view/document~Document#enter
|
|
34
|
+
*/
|
|
35
|
+
export type ViewDocumentEnterEvent = BubblingEvent<{
|
|
36
|
+
name: 'enter';
|
|
37
|
+
args: [EnterEventData];
|
|
38
|
+
}>;
|
|
39
|
+
export interface EnterEventData extends DomEventData<InputEvent> {
|
|
40
|
+
/**
|
|
41
|
+
* Whether it is a soft enter (<kbd>Shift</kbd>+<kbd>Enter</kbd>) or a hard enter (<kbd>Enter</kbd>).
|
|
42
|
+
*/
|
|
43
|
+
isSoft: boolean;
|
|
44
|
+
}
|
package/src/enterobserver.js
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module enter/enterobserver
|
|
7
|
-
*/
|
|
8
|
-
import { Observer, DomEventData, BubblingEventInfo } from '@ckeditor/ckeditor5-engine';
|
|
9
|
-
import { env } from '@ckeditor/ckeditor5-utils';
|
|
10
|
-
const ENTER_EVENT_TYPES = {
|
|
11
|
-
insertParagraph: { isSoft: false },
|
|
12
|
-
insertLineBreak: { isSoft: true }
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Enter observer introduces the {@link module:engine/view/document~Document#event:enter `Document#enter`} event.
|
|
16
|
-
*/
|
|
17
|
-
export default class EnterObserver extends Observer {
|
|
18
|
-
/**
|
|
19
|
-
* @inheritDoc
|
|
20
|
-
*/
|
|
21
|
-
constructor(view) {
|
|
22
|
-
super(view);
|
|
23
|
-
const doc = this.document;
|
|
24
|
-
let shiftPressed = false;
|
|
25
|
-
doc.on('keydown', (evt, data) => {
|
|
26
|
-
shiftPressed = data.shiftKey;
|
|
27
|
-
});
|
|
28
|
-
doc.on('beforeinput', (evt, data) => {
|
|
29
|
-
if (!this.isEnabled) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
let inputType = data.inputType;
|
|
33
|
-
// See https://github.com/ckeditor/ckeditor5/issues/13321.
|
|
34
|
-
if (env.isSafari && shiftPressed && inputType == 'insertParagraph') {
|
|
35
|
-
inputType = 'insertLineBreak';
|
|
36
|
-
}
|
|
37
|
-
const domEvent = data.domEvent;
|
|
38
|
-
const enterEventSpec = ENTER_EVENT_TYPES[inputType];
|
|
39
|
-
if (!enterEventSpec) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const event = new BubblingEventInfo(doc, 'enter', data.targetRanges[0]);
|
|
43
|
-
doc.fire(event, new DomEventData(view, domEvent, {
|
|
44
|
-
isSoft: enterEventSpec.isSoft
|
|
45
|
-
}));
|
|
46
|
-
// Stop `beforeinput` event if `enter` event was stopped.
|
|
47
|
-
// https://github.com/ckeditor/ckeditor5/issues/753
|
|
48
|
-
if (event.stop.called) {
|
|
49
|
-
evt.stop();
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* @inheritDoc
|
|
55
|
-
*/
|
|
56
|
-
observe() { }
|
|
57
|
-
/**
|
|
58
|
-
* @inheritDoc
|
|
59
|
-
*/
|
|
60
|
-
stopObserving() { }
|
|
61
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module enter/enterobserver
|
|
7
|
+
*/
|
|
8
|
+
import { Observer, DomEventData, BubblingEventInfo } from '@ckeditor/ckeditor5-engine';
|
|
9
|
+
import { env } from '@ckeditor/ckeditor5-utils';
|
|
10
|
+
const ENTER_EVENT_TYPES = {
|
|
11
|
+
insertParagraph: { isSoft: false },
|
|
12
|
+
insertLineBreak: { isSoft: true }
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Enter observer introduces the {@link module:engine/view/document~Document#event:enter `Document#enter`} event.
|
|
16
|
+
*/
|
|
17
|
+
export default class EnterObserver extends Observer {
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
constructor(view) {
|
|
22
|
+
super(view);
|
|
23
|
+
const doc = this.document;
|
|
24
|
+
let shiftPressed = false;
|
|
25
|
+
doc.on('keydown', (evt, data) => {
|
|
26
|
+
shiftPressed = data.shiftKey;
|
|
27
|
+
});
|
|
28
|
+
doc.on('beforeinput', (evt, data) => {
|
|
29
|
+
if (!this.isEnabled) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
let inputType = data.inputType;
|
|
33
|
+
// See https://github.com/ckeditor/ckeditor5/issues/13321.
|
|
34
|
+
if (env.isSafari && shiftPressed && inputType == 'insertParagraph') {
|
|
35
|
+
inputType = 'insertLineBreak';
|
|
36
|
+
}
|
|
37
|
+
const domEvent = data.domEvent;
|
|
38
|
+
const enterEventSpec = ENTER_EVENT_TYPES[inputType];
|
|
39
|
+
if (!enterEventSpec) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const event = new BubblingEventInfo(doc, 'enter', data.targetRanges[0]);
|
|
43
|
+
doc.fire(event, new DomEventData(view, domEvent, {
|
|
44
|
+
isSoft: enterEventSpec.isSoft
|
|
45
|
+
}));
|
|
46
|
+
// Stop `beforeinput` event if `enter` event was stopped.
|
|
47
|
+
// https://github.com/ckeditor/ckeditor5/issues/753
|
|
48
|
+
if (event.stop.called) {
|
|
49
|
+
evt.stop();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @inheritDoc
|
|
55
|
+
*/
|
|
56
|
+
observe() { }
|
|
57
|
+
/**
|
|
58
|
+
* @inheritDoc
|
|
59
|
+
*/
|
|
60
|
+
stopObserving() { }
|
|
61
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module enter
|
|
7
|
-
*/
|
|
8
|
-
export { default as Enter } from './enter';
|
|
9
|
-
export { default as ShiftEnter } from './shiftenter';
|
|
10
|
-
export type { ViewDocumentEnterEvent } from './enterobserver';
|
|
11
|
-
export type { default as EnterCommand, EnterCommandAfterExecuteEvent } from './entercommand';
|
|
12
|
-
export type { default as ShiftEnterCommand } from './shiftentercommand';
|
|
13
|
-
import './augmentation';
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module enter
|
|
7
|
+
*/
|
|
8
|
+
export { default as Enter } from './enter';
|
|
9
|
+
export { default as ShiftEnter } from './shiftenter';
|
|
10
|
+
export type { ViewDocumentEnterEvent } from './enterobserver';
|
|
11
|
+
export type { default as EnterCommand, EnterCommandAfterExecuteEvent } from './entercommand';
|
|
12
|
+
export type { default as ShiftEnterCommand } from './shiftentercommand';
|
|
13
|
+
import './augmentation';
|
package/src/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module enter
|
|
7
|
-
*/
|
|
8
|
-
export { default as Enter } from './enter';
|
|
9
|
-
export { default as ShiftEnter } from './shiftenter';
|
|
10
|
-
import './augmentation';
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module enter
|
|
7
|
+
*/
|
|
8
|
+
export { default as Enter } from './enter';
|
|
9
|
+
export { default as ShiftEnter } from './shiftenter';
|
|
10
|
+
import './augmentation';
|
package/src/shiftenter.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
6
|
-
/**
|
|
7
|
-
* This plugin handles the <kbd>Shift</kbd>+<kbd>Enter</kbd> keystroke (soft line break) in the editor.
|
|
8
|
-
*
|
|
9
|
-
* See also the {@link module:enter/enter~Enter} plugin.
|
|
10
|
-
*
|
|
11
|
-
* For more information about this feature see the {@glink api/enter package page}.
|
|
12
|
-
*/
|
|
13
|
-
export default class ShiftEnter extends Plugin {
|
|
14
|
-
/**
|
|
15
|
-
* @inheritDoc
|
|
16
|
-
*/
|
|
17
|
-
static get pluginName(): "ShiftEnter";
|
|
18
|
-
init(): void;
|
|
19
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
6
|
+
/**
|
|
7
|
+
* This plugin handles the <kbd>Shift</kbd>+<kbd>Enter</kbd> keystroke (soft line break) in the editor.
|
|
8
|
+
*
|
|
9
|
+
* See also the {@link module:enter/enter~Enter} plugin.
|
|
10
|
+
*
|
|
11
|
+
* For more information about this feature see the {@glink api/enter package page}.
|
|
12
|
+
*/
|
|
13
|
+
export default class ShiftEnter extends Plugin {
|
|
14
|
+
/**
|
|
15
|
+
* @inheritDoc
|
|
16
|
+
*/
|
|
17
|
+
static get pluginName(): "ShiftEnter";
|
|
18
|
+
init(): void;
|
|
19
|
+
}
|
package/src/shiftenter.js
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module enter/shiftenter
|
|
7
|
-
*/
|
|
8
|
-
import ShiftEnterCommand from './shiftentercommand';
|
|
9
|
-
import EnterObserver from './enterobserver';
|
|
10
|
-
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
11
|
-
/**
|
|
12
|
-
* This plugin handles the <kbd>Shift</kbd>+<kbd>Enter</kbd> keystroke (soft line break) in the editor.
|
|
13
|
-
*
|
|
14
|
-
* See also the {@link module:enter/enter~Enter} plugin.
|
|
15
|
-
*
|
|
16
|
-
* For more information about this feature see the {@glink api/enter package page}.
|
|
17
|
-
*/
|
|
18
|
-
export default class ShiftEnter extends Plugin {
|
|
19
|
-
/**
|
|
20
|
-
* @inheritDoc
|
|
21
|
-
*/
|
|
22
|
-
static get pluginName() {
|
|
23
|
-
return 'ShiftEnter';
|
|
24
|
-
}
|
|
25
|
-
init() {
|
|
26
|
-
const editor = this.editor;
|
|
27
|
-
const schema = editor.model.schema;
|
|
28
|
-
const conversion = editor.conversion;
|
|
29
|
-
const view = editor.editing.view;
|
|
30
|
-
const viewDocument = view.document;
|
|
31
|
-
// Configure the schema.
|
|
32
|
-
schema.register('softBreak', {
|
|
33
|
-
allowWhere: '$text',
|
|
34
|
-
isInline: true
|
|
35
|
-
});
|
|
36
|
-
// Configure converters.
|
|
37
|
-
conversion.for('upcast')
|
|
38
|
-
.elementToElement({
|
|
39
|
-
model: 'softBreak',
|
|
40
|
-
view: 'br'
|
|
41
|
-
});
|
|
42
|
-
conversion.for('downcast')
|
|
43
|
-
.elementToElement({
|
|
44
|
-
model: 'softBreak',
|
|
45
|
-
view: (modelElement, { writer }) => writer.createEmptyElement('br')
|
|
46
|
-
});
|
|
47
|
-
view.addObserver(EnterObserver);
|
|
48
|
-
editor.commands.add('shiftEnter', new ShiftEnterCommand(editor));
|
|
49
|
-
this.listenTo(viewDocument, 'enter', (evt, data) => {
|
|
50
|
-
// When not in composition, we handle the action, so prevent the default one.
|
|
51
|
-
// When in composition, it's the browser who modify the DOM (renderer is disabled).
|
|
52
|
-
if (!viewDocument.isComposing) {
|
|
53
|
-
data.preventDefault();
|
|
54
|
-
}
|
|
55
|
-
// The hard enter key is handled by the Enter plugin.
|
|
56
|
-
if (!data.isSoft) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
editor.execute('shiftEnter');
|
|
60
|
-
view.scrollToTheSelection();
|
|
61
|
-
}, { priority: 'low' });
|
|
62
|
-
}
|
|
63
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module enter/shiftenter
|
|
7
|
+
*/
|
|
8
|
+
import ShiftEnterCommand from './shiftentercommand';
|
|
9
|
+
import EnterObserver from './enterobserver';
|
|
10
|
+
import { Plugin } from '@ckeditor/ckeditor5-core';
|
|
11
|
+
/**
|
|
12
|
+
* This plugin handles the <kbd>Shift</kbd>+<kbd>Enter</kbd> keystroke (soft line break) in the editor.
|
|
13
|
+
*
|
|
14
|
+
* See also the {@link module:enter/enter~Enter} plugin.
|
|
15
|
+
*
|
|
16
|
+
* For more information about this feature see the {@glink api/enter package page}.
|
|
17
|
+
*/
|
|
18
|
+
export default class ShiftEnter extends Plugin {
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
static get pluginName() {
|
|
23
|
+
return 'ShiftEnter';
|
|
24
|
+
}
|
|
25
|
+
init() {
|
|
26
|
+
const editor = this.editor;
|
|
27
|
+
const schema = editor.model.schema;
|
|
28
|
+
const conversion = editor.conversion;
|
|
29
|
+
const view = editor.editing.view;
|
|
30
|
+
const viewDocument = view.document;
|
|
31
|
+
// Configure the schema.
|
|
32
|
+
schema.register('softBreak', {
|
|
33
|
+
allowWhere: '$text',
|
|
34
|
+
isInline: true
|
|
35
|
+
});
|
|
36
|
+
// Configure converters.
|
|
37
|
+
conversion.for('upcast')
|
|
38
|
+
.elementToElement({
|
|
39
|
+
model: 'softBreak',
|
|
40
|
+
view: 'br'
|
|
41
|
+
});
|
|
42
|
+
conversion.for('downcast')
|
|
43
|
+
.elementToElement({
|
|
44
|
+
model: 'softBreak',
|
|
45
|
+
view: (modelElement, { writer }) => writer.createEmptyElement('br')
|
|
46
|
+
});
|
|
47
|
+
view.addObserver(EnterObserver);
|
|
48
|
+
editor.commands.add('shiftEnter', new ShiftEnterCommand(editor));
|
|
49
|
+
this.listenTo(viewDocument, 'enter', (evt, data) => {
|
|
50
|
+
// When not in composition, we handle the action, so prevent the default one.
|
|
51
|
+
// When in composition, it's the browser who modify the DOM (renderer is disabled).
|
|
52
|
+
if (!viewDocument.isComposing) {
|
|
53
|
+
data.preventDefault();
|
|
54
|
+
}
|
|
55
|
+
// The hard enter key is handled by the Enter plugin.
|
|
56
|
+
if (!data.isSoft) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
editor.execute('shiftEnter');
|
|
60
|
+
view.scrollToTheSelection();
|
|
61
|
+
}, { priority: 'low' });
|
|
62
|
+
}
|
|
63
|
+
}
|