|
@@ -87,6 +87,7 @@ export default class WidgetTypeAround extends Plugin {
|
|
|
this._enableInsertingParagraphsOnTypingKeystroke();
|
|
this._enableInsertingParagraphsOnTypingKeystroke();
|
|
|
this._enableTypeAroundFakeCaretActivationUsingKeyboardArrows();
|
|
this._enableTypeAroundFakeCaretActivationUsingKeyboardArrows();
|
|
|
this._enableDeleteIntegration();
|
|
this._enableDeleteIntegration();
|
|
|
|
|
+ this._enableInsertContentIntegration();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -109,16 +110,9 @@ export default class WidgetTypeAround extends Plugin {
|
|
|
_insertParagraph( widgetModelElement, position ) {
|
|
_insertParagraph( widgetModelElement, position ) {
|
|
|
const editor = this.editor;
|
|
const editor = this.editor;
|
|
|
const editingView = editor.editing.view;
|
|
const editingView = editor.editing.view;
|
|
|
- let modelPosition;
|
|
|
|
|
-
|
|
|
|
|
- if ( position === 'before' ) {
|
|
|
|
|
- modelPosition = editor.model.createPositionBefore( widgetModelElement );
|
|
|
|
|
- } else {
|
|
|
|
|
- modelPosition = editor.model.createPositionAfter( widgetModelElement );
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
editor.execute( 'insertParagraph', {
|
|
editor.execute( 'insertParagraph', {
|
|
|
- position: modelPosition
|
|
|
|
|
|
|
+ position: editor.model.createPositionAt( widgetModelElement, position )
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
editingView.focus();
|
|
editingView.focus();
|
|
@@ -362,9 +356,8 @@ export default class WidgetTypeAround extends Plugin {
|
|
|
const model = editor.model;
|
|
const model = editor.model;
|
|
|
const modelSelection = model.document.selection;
|
|
const modelSelection = model.document.selection;
|
|
|
const typeAroundSelectionAttribute = modelSelection.getAttribute( TYPE_AROUND_SELECTION_ATTRIBUTE );
|
|
const typeAroundSelectionAttribute = modelSelection.getAttribute( TYPE_AROUND_SELECTION_ATTRIBUTE );
|
|
|
- let shouldStopAndPreventDefault = false;
|
|
|
|
|
|
|
|
|
|
- model.change( writer => {
|
|
|
|
|
|
|
+ return model.change( writer => {
|
|
|
// If the selection already has the attribute...
|
|
// If the selection already has the attribute...
|
|
|
if ( typeAroundSelectionAttribute ) {
|
|
if ( typeAroundSelectionAttribute ) {
|
|
|
const isLeavingWidget = typeAroundSelectionAttribute === ( isForward ? 'after' : 'before' );
|
|
const isLeavingWidget = typeAroundSelectionAttribute === ( isForward ? 'after' : 'before' );
|
|
@@ -380,7 +373,7 @@ export default class WidgetTypeAround extends Plugin {
|
|
|
if ( !isLeavingWidget ) {
|
|
if ( !isLeavingWidget ) {
|
|
|
writer.removeSelectionAttribute( TYPE_AROUND_SELECTION_ATTRIBUTE );
|
|
writer.removeSelectionAttribute( TYPE_AROUND_SELECTION_ATTRIBUTE );
|
|
|
|
|
|
|
|
- shouldStopAndPreventDefault = true;
|
|
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
// If the selection didn't have the attribute, let's set it now according to the direction of the arrow
|
|
// If the selection didn't have the attribute, let's set it now according to the direction of the arrow
|
|
@@ -388,11 +381,11 @@ export default class WidgetTypeAround extends Plugin {
|
|
|
else {
|
|
else {
|
|
|
writer.setSelectionAttribute( TYPE_AROUND_SELECTION_ATTRIBUTE, isForward ? 'after' : 'before' );
|
|
writer.setSelectionAttribute( TYPE_AROUND_SELECTION_ATTRIBUTE, isForward ? 'after' : 'before' );
|
|
|
|
|
|
|
|
- shouldStopAndPreventDefault = true;
|
|
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
- } );
|
|
|
|
|
|
|
|
|
|
- return shouldStopAndPreventDefault;
|
|
|
|
|
|
|
+ return false;
|
|
|
|
|
+ } );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -628,6 +621,50 @@ export default class WidgetTypeAround extends Plugin {
|
|
|
evt.stop();
|
|
evt.stop();
|
|
|
}, { priority: priorities.get( 'high' ) + 1 } );
|
|
}, { priority: priorities.get( 'high' ) + 1 } );
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Attaches the "insertContent" model event listener that allows the user to paste a content near the widget
|
|
|
|
|
+ * when the "fake caret" was first activated using the arrow keys.
|
|
|
|
|
+ *
|
|
|
|
|
+ * The content is inserted according to the "widget-type-around" selection attribute (see {@link #_handleArrowKeyPress}).
|
|
|
|
|
+ *
|
|
|
|
|
+ * @private
|
|
|
|
|
+ */
|
|
|
|
|
+ _enableInsertContentIntegration() {
|
|
|
|
|
+ const editor = this.editor;
|
|
|
|
|
+ const model = this.editor.model;
|
|
|
|
|
+ const documentSelection = model.document.selection;
|
|
|
|
|
+
|
|
|
|
|
+ this.listenTo( editor.model, 'insertContent', ( evt, [ content, selectable ] ) => {
|
|
|
|
|
+ const typeAroundSelectionAttributeValue = documentSelection.getAttribute( TYPE_AROUND_SELECTION_ATTRIBUTE );
|
|
|
|
|
+
|
|
|
|
|
+ if ( !typeAroundSelectionAttributeValue ) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ( selectable && !selectable.is( 'documentSelection' ) ) {
|
|
|
|
|
+ model.change( writer => {
|
|
|
|
|
+ writer.removeSelectionAttribute( TYPE_AROUND_SELECTION_ATTRIBUTE );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ evt.stop();
|
|
|
|
|
+
|
|
|
|
|
+ return model.change( writer => {
|
|
|
|
|
+ const selectedElement = documentSelection.getSelectedElement();
|
|
|
|
|
+ const position = model.createPositionAt( selectedElement, typeAroundSelectionAttributeValue );
|
|
|
|
|
+ const selection = writer.createSelection( position );
|
|
|
|
|
+
|
|
|
|
|
+ const result = model.insertContent( content, selection );
|
|
|
|
|
+
|
|
|
|
|
+ writer.setSelection( selection );
|
|
|
|
|
+
|
|
|
|
|
+ return result;
|
|
|
|
|
+ } );
|
|
|
|
|
+ }, { priority: 'high' } );
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Injects the type around UI into a view widget instance.
|
|
// Injects the type around UI into a view widget instance.
|