@ckeditor/ckeditor5-enter
Advanced tools
Comparing version 35.3.2 to 35.4.0
{ | ||
"name": "@ckeditor/ckeditor5-enter", | ||
"version": "35.3.2", | ||
"version": "35.4.0", | ||
"description": "Enter feature for CKEditor 5.", | ||
@@ -15,13 +15,13 @@ "keywords": [ | ||
"dependencies": { | ||
"@ckeditor/ckeditor5-core": "^35.3.2", | ||
"@ckeditor/ckeditor5-engine": "^35.3.2" | ||
"@ckeditor/ckeditor5-core": "^35.4.0", | ||
"@ckeditor/ckeditor5-engine": "^35.4.0" | ||
}, | ||
"devDependencies": { | ||
"@ckeditor/ckeditor5-basic-styles": "^35.3.2", | ||
"@ckeditor/ckeditor5-editor-classic": "^35.3.2", | ||
"@ckeditor/ckeditor5-heading": "^35.3.2", | ||
"@ckeditor/ckeditor5-link": "^35.3.2", | ||
"@ckeditor/ckeditor5-paragraph": "^35.3.2", | ||
"@ckeditor/ckeditor5-typing": "^35.3.2", | ||
"@ckeditor/ckeditor5-undo": "^35.3.2", | ||
"@ckeditor/ckeditor5-basic-styles": "^35.4.0", | ||
"@ckeditor/ckeditor5-editor-classic": "^35.4.0", | ||
"@ckeditor/ckeditor5-heading": "^35.4.0", | ||
"@ckeditor/ckeditor5-link": "^35.4.0", | ||
"@ckeditor/ckeditor5-paragraph": "^35.4.0", | ||
"@ckeditor/ckeditor5-typing": "^35.4.0", | ||
"@ckeditor/ckeditor5-undo": "^35.4.0", | ||
"typescript": "^4.8.4", | ||
@@ -28,0 +28,0 @@ "webpack": "^5.58.1", |
@@ -8,7 +8,7 @@ /** | ||
*/ | ||
import Plugin from '@ckeditor/ckeditor5-core/src/plugin'; | ||
import { Plugin } from '@ckeditor/ckeditor5-core'; | ||
import EnterCommand from './entercommand'; | ||
import EnterObserver from './enterobserver'; | ||
/** | ||
* This plugin handles the <kbd>Enter</kbd> key (hard line break) in the editor. | ||
* This plugin handles the <kbd>Enter</kbd> keystroke (hard line break) in the editor. | ||
* | ||
@@ -15,0 +15,0 @@ * See also the {@link module:enter/shiftenter~ShiftEnter} plugin. |
@@ -8,6 +8,6 @@ /** | ||
*/ | ||
import Command from '@ckeditor/ckeditor5-core/src/command'; | ||
import { Command } from '@ckeditor/ckeditor5-core'; | ||
import { getCopyOnEnterAttributes } from './utils'; | ||
/** | ||
* Enter command. It is used by the {@link module:enter/enter~Enter Enter feature} to handle the <kbd>Enter</kbd> key. | ||
* Enter command. It is used by the {@link module:enter/enter~Enter Enter feature} to handle the <kbd>Enter</kbd> keystroke. | ||
* | ||
@@ -21,56 +21,71 @@ * @extends module:core/command~Command | ||
execute() { | ||
const model = this.editor.model; | ||
const doc = model.document; | ||
model.change(writer => { | ||
enterBlock(this.editor.model, writer, doc.selection, model.schema); | ||
this.editor.model.change(writer => { | ||
this.enterBlock(writer); | ||
this.fire('afterExecute', { writer }); | ||
}); | ||
} | ||
} | ||
// Creates a new block in the way that the <kbd>Enter</kbd> key is expected to work. | ||
// | ||
// @param {module:engine/model~Model} model | ||
// @param {module:engine/model/writer~Writer} writer | ||
// @param {module:engine/model/selection~Selection|module:engine/model/documentselection~DocumentSelection} selection | ||
// Selection on which the action should be performed. | ||
// @param {module:engine/model/schema~Schema} schema | ||
function enterBlock(model, writer, selection, schema) { | ||
const isSelectionEmpty = selection.isCollapsed; | ||
const range = selection.getFirstRange(); | ||
const startElement = range.start.parent; | ||
const endElement = range.end.parent; | ||
// Don't touch the roots and other limit elements. | ||
if (schema.isLimit(startElement) || schema.isLimit(endElement)) { | ||
// Delete the selected content but only if inside a single limit element. | ||
// Abort, when crossing limit elements boundary (e.g. <limit1>x[x</limit1>donttouchme<limit2>y]y</limit2>). | ||
// This is an edge case and it's hard to tell what should actually happen because such a selection | ||
// is not entirely valid. | ||
if (!isSelectionEmpty && startElement == endElement) { | ||
model.deleteContent(selection); | ||
/** | ||
* Splits a block where the document selection is placed, in the way how the <kbd>Enter</kbd> key is expected to work: | ||
* | ||
* <p>Foo[]bar</p> -> <p>Foo</p><p>[]bar</p> | ||
* <p>Foobar[]</p> -> <p>Foobar</p><p>[]</p> | ||
* <p>Fo[ob]ar</p> -> <p>Fo</p><p>[]ar</p> | ||
* | ||
* In some cases, the split will not happen: | ||
* | ||
* // The selection parent is a limit element: | ||
* <figcaption>A[bc]d</figcaption> -> <figcaption>A[]d</figcaption> | ||
* | ||
* // The selection spans over multiple elements: | ||
* <h>x[x</h><p>y]y<p> -> <h>x</h><p>[]y</p> | ||
* | ||
* @param writer Writer to use when performing the enter action. | ||
* @returns `true` if a block was split, `false` otherwise. | ||
*/ | ||
enterBlock(writer) { | ||
const model = this.editor.model; | ||
const selection = model.document.selection; | ||
const schema = model.schema; | ||
const isSelectionEmpty = selection.isCollapsed; | ||
const range = selection.getFirstRange(); | ||
const startElement = range.start.parent; | ||
const endElement = range.end.parent; | ||
// Don't touch the roots and other limit elements. | ||
if (schema.isLimit(startElement) || schema.isLimit(endElement)) { | ||
// Delete the selected content but only if inside a single limit element. | ||
// Abort, when crossing limit elements boundary (e.g. <limit1>x[x</limit1>donttouchme<limit2>y]y</limit2>). | ||
// This is an edge case and it's hard to tell what should actually happen because such a selection | ||
// is not entirely valid. | ||
if (!isSelectionEmpty && startElement == endElement) { | ||
model.deleteContent(selection); | ||
} | ||
return false; | ||
} | ||
return; | ||
} | ||
if (isSelectionEmpty) { | ||
const attributesToCopy = getCopyOnEnterAttributes(writer.model.schema, selection.getAttributes()); | ||
splitBlock(writer, range.start); | ||
writer.setSelectionAttribute(attributesToCopy); | ||
} | ||
else { | ||
const leaveUnmerged = !(range.start.isAtStart && range.end.isAtEnd); | ||
const isContainedWithinOneElement = (startElement == endElement); | ||
model.deleteContent(selection, { leaveUnmerged }); | ||
if (leaveUnmerged) { | ||
// Partially selected elements. | ||
// | ||
// <h>x[xx]x</h> -> <h>x^x</h> -> <h>x</h><h>^x</h> | ||
if (isContainedWithinOneElement) { | ||
splitBlock(writer, selection.focus); | ||
if (isSelectionEmpty) { | ||
const attributesToCopy = getCopyOnEnterAttributes(writer.model.schema, selection.getAttributes()); | ||
splitBlock(writer, range.start); | ||
writer.setSelectionAttribute(attributesToCopy); | ||
return true; | ||
} | ||
else { | ||
const leaveUnmerged = !(range.start.isAtStart && range.end.isAtEnd); | ||
const isContainedWithinOneElement = (startElement == endElement); | ||
model.deleteContent(selection, { leaveUnmerged }); | ||
if (leaveUnmerged) { | ||
// Partially selected elements. | ||
// | ||
// <h>x[xx]x</h> -> <h>x^x</h> -> <h>x</h><h>^x</h> | ||
if (isContainedWithinOneElement) { | ||
splitBlock(writer, selection.focus); | ||
return true; | ||
} | ||
// Selection over multiple elements. | ||
// | ||
// <h>x[x</h><p>y]y<p> -> <h>x^</h><p>y</p> -> <h>x</h><p>^y</p> | ||
else { | ||
writer.setSelection(endElement, 0); | ||
} | ||
} | ||
// Selection over multiple elements. | ||
// | ||
// <h>x[x</h><p>y]y<p> -> <h>x^</h><p>y</p> -> <h>x</h><p>^y</p> | ||
else { | ||
writer.setSelection(endElement, 0); | ||
} | ||
} | ||
return false; | ||
} | ||
@@ -77,0 +92,0 @@ } |
@@ -8,5 +8,3 @@ /** | ||
*/ | ||
import Observer from '@ckeditor/ckeditor5-engine/src/view/observer/observer'; | ||
import DomEventData from '@ckeditor/ckeditor5-engine/src/view/observer/domeventdata'; | ||
import BubblingEventInfo from '@ckeditor/ckeditor5-engine/src/view/observer/bubblingeventinfo'; | ||
import { Observer, DomEventData, BubblingEventInfo } from '@ckeditor/ckeditor5-engine'; | ||
const ENTER_EVENT_TYPES = { | ||
@@ -13,0 +11,0 @@ insertParagraph: { isSoft: false }, |
@@ -10,3 +10,3 @@ /** | ||
import EnterObserver from './enterobserver'; | ||
import Plugin from '@ckeditor/ckeditor5-core/src/plugin'; | ||
import { Plugin } from '@ckeditor/ckeditor5-core'; | ||
/** | ||
@@ -13,0 +13,0 @@ * This plugin handles the <kbd>Shift</kbd>+<kbd>Enter</kbd> keystroke (soft line break) in the editor. |
@@ -8,3 +8,3 @@ /** | ||
*/ | ||
import Command from '@ckeditor/ckeditor5-core/src/command'; | ||
import { Command } from '@ckeditor/ckeditor5-core'; | ||
import { getCopyOnEnterAttributes } from './utils'; | ||
@@ -11,0 +11,0 @@ /** |
@@ -6,3 +6,3 @@ /** | ||
/** | ||
* Returns attributes that should be preserved on the enter key. | ||
* Returns attributes that should be preserved on the enter keystroke. | ||
* | ||
@@ -9,0 +9,0 @@ * Filtering is realized based on `copyOnEnter` attribute property. Read more about attribute properties |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26456
408