Methods
addMarkupToRange(range, markup)
Given a markerRange (for example editor.range
) mark all markers
inside it as a given markup. The markup must be provided as a post
abstract node.
Usage:
let range = editor.range;
let strongMarkup = editor.builder.createMarkup('strong');
editor.run((postEditor) => {
postEditor.addMarkupToRange(range, strongMarkup);
});
// Will result some markers possibly being split, and the markup
// being applied to all markers between the split.
Parameters:
Name | Type | Description |
---|---|---|
range |
Range | |
markup |
Markup | A markup post abstract node |
- Source:
deleteAtPosition(position, directionopt, optionsopt) → {Position}
Delete 1 unit
(can be 'char' or 'word') in the given direction
at the given
position
. In almost all cases this will be equivalent to deleting the range formed
by expanding the position 1 unit in the given direction. The exception is when deleting
backward from the beginning of a list item, which reverts the list item into a markup section
instead of joining it with its previous list item (if any).
Usage:
let position = section.tailPosition();
// Section has text of "Howdy!"
editor.run((postEditor) => {
postEditor.deleteAtPosition(position);
});
// section has text of "Howdy"
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
position |
Position | The position to delete at |
||||||||||||
direction |
Direction |
<optional> |
DIRECTION.BACKWARD | direction The direction to delete in |
||||||||||
options |
Object |
<optional> |
Properties
|
- Source:
Returns:
- Type
- Position
deleteFrom(position, direction) → {Position}
Parameters:
Name | Type | Description |
---|---|---|
position |
Position | object with {section, offset} the marker and offset to delete from |
direction |
Number | The direction to delete in (default is BACKWARD) |
- Deprecated:
- after v0.10.3
- Source:
Returns:
for positioning the cursor
- Type
- Position
deleteRange(range) → {Position}
Delete a range from the post
Usage:
let { range } = editor;
editor.run((postEditor) => {
let nextPosition = postEditor.deleteRange(range);
postEditor.setRange(nextPosition);
});
Parameters:
Name | Type | Description |
---|---|---|
range |
Range | Cursor Range object with head and tail Positions |
- Source:
Returns:
The position where the cursor would go after deletion
- Type
- Position
insertMarkers(position, markers) → {Position}
Insert an array of markers at the given position. If the position is in a non-markerable section (like a card section), this method throws an error.
Parameters:
Name | Type | Description |
---|---|---|
position |
Position | |
markers |
Array.<Marker> |
- Source:
Returns:
The position that represents the end of the inserted markers.
- Type
- Position
insertSection(section)
Insert the given section after the current active section, or, if no section is active, at the end of the document.
Parameters:
Name | Type | Description |
---|---|---|
section |
Section |
- Source:
insertSectionAtEnd(section)
Insert the given section at the end of the document.
Parameters:
Name | Type | Description |
---|---|---|
section |
Section |
- Source:
insertSectionBefore(collection, section, beforeSection)
Insert a given section before another one, updating the post abstract and the rendered UI.
Usage:
let markerRange = editor.range;
let sectionWithCursor = markerRange.headMarker.section;
let section = editor.builder.createCardSection('my-image');
let collection = sectionWithCursor.parent.sections;
editor.run((postEditor) => {
postEditor.insertSectionBefore(collection, section, sectionWithCursor);
});
Parameters:
Name | Type | Description |
---|---|---|
collection |
LinkedList | The list of sections to insert into |
section |
Object | The new section |
beforeSection |
Object | Optional The section "before" is relative to, if falsy the new section will be appended to the collection |
- Source:
insertText(position, text) → {Position}
Insert the text at the given position Inherits the markups already at that position, if any.
Parameters:
Name | Type | Description |
---|---|---|
position |
Position | |
text |
String |
- Source:
Returns:
position at the end of the inserted text.
- Type
- Position
insertTextWithMarkup(position, text, markups) → {Position}
Inserts text with the given markups, ignoring the existing markups at the position, if any.
Parameters:
Name | Type | Description |
---|---|---|
position |
Position | |
text |
String | |
markups |
Array.<Markup> |
- Source:
Returns:
position at the end of the inserted text
- Type
- Position
moveSectionDown(section)
Parameters:
Name | Type | Description |
---|---|---|
section |
Section | A section that is already in DOM |
- Source:
moveSectionUp(section)
Parameters:
Name | Type | Description |
---|---|---|
section |
Section | A section that is already in DOM |
- Source:
removeSection(section)
Remove a given section from the post abstract and the rendered UI.
Usage:
let { range } = editor;
let sectionWithCursor = range.head.section;
editor.run((postEditor) => {
postEditor.removeSection(sectionWithCursor);
});
Parameters:
Name | Type | Description |
---|---|---|
section |
Object | The section to remove |
- Source:
replaceSection(section, newSection)
Parameters:
Name | Type | Description |
---|---|---|
section |
Section | |
newSection |
Section |
- Source:
Returns:
null
schedule(callback, onceopt)
A method for adding work the deferred queue
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
callback |
function | to run during completion |
||
once |
Boolean |
<optional> |
false | Whether to only schedule the callback once. |
- Source:
scheduleDidUpdate()
Schedule a notification that the post has been changed.
The notification will result in the editor firing its postDidChange
hook after the postEditor completes its work (at the end of Editor#run).
- Source:
scheduleOnce(callback)
A method for adding work the deferred queue. The callback will only
be added to the queue once, even if scheduleOnce
is called multiple times.
The function cannot be an anonymous function.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | to run during completion |
- Source:
scheduleRerender()
Add a rerender job to the queue
- Source:
setRange(range)
Schedules to select the given range on the editor after the postEditor has completed its work. This also updates the postEditor's active range (so that multiple calls to range-changing methods on the postEditor will update the correct range).
Usage: let range = editor.range; editor.run(postEditor => { let nextPosition = postEditor.deleteRange(range);
// Will position the editor's cursor at `nextPosition` after
// the postEditor finishes work and the editor rerenders.
postEditor.setRange(nextPosition);
});
Parameters:
Name | Type | Description |
---|---|---|
range |
Range | Position |
- Source:
splitSection(position) → {Array}
Split the section at the position.
Usage:
let position = editor.cursor.offsets.head;
editor.run((postEditor) => {
postEditor.splitSection(position);
});
// Will result in the creation of two new sections
// replacing the old one at the cursor position
The return value will be the two new sections. One or both of these sections can be blank (contain only a blank marker), for example if the headMarkerOffset is 0.
Parameters:
Name | Type | Description |
---|---|---|
position |
Position |
- Source:
Returns:
new sections, one for the first half and one for the second (either one can be null)
- Type
- Array
toggleMarkup(markupOrString, range)
Toggle the given markup in the given range (or at the position given). If the range/position has the markup, the markup will be removed. If nothing in the range/position has the markup, the markup will be added to everything in the range/position.
Usage:
// Remove any 'strong' markup if it exists in the selection, otherwise
// make it all 'strong'
editor.run(postEditor => postEditor.toggleMarkup('strong'));
// add/remove a link to 'bustle.com' to the selection
editor.run(postEditor => {
const linkMarkup = postEditor.builder.createMarkup('a', {href: 'http://bustle.com'});
postEditor.toggleMarkup(linkMarkup);
});
Parameters:
Name | Type | Description |
---|---|---|
markupOrString |
Markup | String | Either a markup object created using the builder (useful when adding a markup with attributes, like an 'a' markup), or, if a string, the tag name of the markup (e.g. 'strong', 'em') to toggle. |
range |
Range | Position | in which to toggle. Defaults to current editor range. |
- Source:
toggleSection(sectionTagName, range)
Toggles the tagName of the active section or sections in the given range/position. If every section has the tag name, they will all be reset to default sections. Otherwise, every section will be changed to the requested type
Parameters:
Name | Type | Description |
---|---|---|
sectionTagName |
String | A valid markup section or list section tag name (e.g. 'blockquote', 'h2', 'ul') |
range |
Range | Position | The range over which to toggle. Defaults to the current editor range. |
- Source: